Run python flask on EC2 in the background

meraj picture meraj · Apr 12, 2014 · Viewed 8.5k times · Source

I have small app created on python flask and deployed on EC2 aws machine, when I do ssh to ec2 machine and starts flask, it works, but when I terminate the session the flask dies, I can run it using nohup. What is the best way to make it independent of ssh session and run it continuously.

Answer

Mike picture Mike · Apr 12, 2014

There are several options:

  1. nohup python app.py &
  2. use screen
  3. run supervisord(link) on system startup and control all through it (pythonic way :))

nohup means: do not terminate this process even when the stty is cut off.

& at the end means: run this command as a background task.