1

I am looking for help deploying my flash app. I've already written the app and it works well. I'm currently using the following command in the directory of my flask code:

sudo uwsgi --socket 0.0.0.0:70 --protocol=http -w AppName:app --buffer-size=32768

This is on my Amazon Lightsail instance. I have the instance linked to a static public IP, and if I navigate to the website, it works great. However, to get the command to continuously run in the background even after logging out of the Lightsail, I first start a screen command, execute the above line of code, and then detach the screen using ctrl-a-d.

The problem is, if the app crashes (which is understandable since it is very large and under development), or if the command is left running for too long, the process is killed, and it is no longer being served.

I am looking for a better method of deploying a flask app on Amazon Lightsail so that it will redeploy the app in the event of a crash without any interaction from myself.

4

2 回答 2

1

Generally you would write your own unit file for systemd to keep your application running, auto restart when it crashes and start when you boot your instances.

There are many tutorials out there showing how to write such a unit file. Some examples:

于 2020-07-16T03:39:27.593 回答
1

You can use pm2

Starting an application with PM2 is straightforward. It will auto discover the interpreter to run your application depending on the script extension. This can be configurable via the Ecosystem config file, as I will show you later on this article.

All you need to install pm2 and then

pm2 start appy.py

Great, this application will now run forever, meaning that if the process exit or throw an exception it will get automatically restarted. If you exit the console and connect again you will still be able to check the application state.

To list application managed by PM2 run:

pm2 ls

You can also check logs

pm2 logs

Keeping Processes Alive at Server Reboot

If you want to keep your application online across unexpected (or expected) server restart, you will want to setup init script to tell your system to boot PM2 and your applications.

It’s really simple with PM2, just run this command (without sudo):

pm2 startup

Pm2 Manage-Python-Processes

于 2020-07-16T03:50:12.350 回答