How to run Flask Server in the background
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.
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
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.