How to Run Python Script in PM2 Server
To run your Flask app with PM2, follow these steps:
Navigate to your project directory: Open your terminal and navigate to the directory containing your Flask app.
Start your Flask app with PM2: Use the following command to start your app with PM2. You need to specify the Python interpreter and the path to your
app.pyfile.Replace
python3with your specific Python version if needed.Configure PM2 to run on startup (optional but recommended): To ensure PM2 restarts your app after a server reboot, you can set it up to run on startup with:
Follow the instructions that PM2 provides after running this command.
Save the PM2 process list: Save the current process list so that PM2 can restore it on reboot:
Check the status of your app: You can check the status of your Flask app using:
View logs: To see the logs for your Flask app, you can use:
Now your Flask app should be running under PM2, and it will automatically restart if it crashes or if the server reboots!
Comments
Post a Comment