How To Run Flask Server In The Background
Solution 1:
Use:
$ sudo nohup python app1c.py > log.txt 2>&1 &
nohup
allows to run command/process or shell script that can continue running in the background after you log out from a shell.
> log.txt
: it forword the output to this file.
2>&1
: move all the stderr to stdout.
The final &
allows you to run a command/process in background on the current shell.
Solution 2:
Install Node package forever at here https://www.npmjs.com/package/forever Then use
forever start -c python your_script.py
to start your script in the background. Later you can use
forever stop your_script.py
to stop the script
Solution 3:
You have multiple options:
- Easy: deattach the process with
&
, for example:
$ sudo python app1c.py &
Medium: install tmux with
apt-get install tmux
launch tmux and start your app as before and detach with CTRL+B.Complexer: Read run your flask script with a wsgi server - uwsgi, gunicorn, nginx.
Solution 4:
Use:
$sudo python app1c.py >> log.txt 2>&1 &
">> log.txt" pushes all your stdout inside the log.txt file (You may check the application logs in it)
"2>&1" pushes all the stderr inside the log.txt file (This would push all the error logs inside log.txt)
"&" at the end makes it run in the background.
You would get the process id immediately after executing this command with which you can monitor or verify it.
$sudo ps -ef | grep <process-id>
Hope it helps..!!
Solution 5:
I've always found a detached screen process to be best for use cases such as these.
Run:
screen -m -d sudo python app1c.py
Post a Comment for "How To Run Flask Server In The Background"