How to Run Python Script in PM2 Server

 To run your Flask app with PM2, follow these steps:

  1. Navigate to your project directory: Open your terminal and navigate to the directory containing your Flask app.


    cd path/to/flask_app
  2. 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.py file.


    pm2 start app.py --interpreter python3 --name flask_app

    Replace python3 with your specific Python version if needed.

  3. 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:


    pm2 startup

    Follow the instructions that PM2 provides after running this command.

  4. Save the PM2 process list: Save the current process list so that PM2 can restore it on reboot:


    pm2 save
  5. Check the status of your app: You can check the status of your Flask app using:


    pm2 list
  6. View logs: To see the logs for your Flask app, you can use:


    pm2 logs flask_app

Now your Flask app should be running under PM2, and it will automatically restart if it crashes or if the server reboots!

Comments

Popular posts from this blog

Handling Performance Bottlenecks in Spring Applications

Retry in SprinBoot Application