Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run python flask on EC2 in the background

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.

like image 750
meraj Avatar asked Apr 12 '14 10:04

meraj


People also ask

How do I run a Python Flask app in the background?

To install flask, simply type in pip install flask in your computer terminal/command line. Once you have made sure flask is installed, simply run the hello.py script. Once you run the script, the website should now be up and running on your local machine, and it can be viewed by visiting localhost:5000 in your browser.

Can I run Python on EC2 instance?

Installing Python on AWS EC2 : Follow the below steps to install Python on AWS EC2: Step 1: Create an AWS Elastic Cloud Compute Instance. Step 2: Start the EC2 instance that you have created in Step 1. Step 3: Connect to your EC2 Instance by clicking on Connect Button.


1 Answers

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.

like image 177
Mike Avatar answered Oct 05 '22 14:10

Mike