skip to Main Content

I have a web app that I deployed to a machine that has ubuntu 20 installed
to be able to run the app I should open ssh to the ubuntu machine and then run this command

cd mywebapp
python3 app.py

it works successfully, but once I close the ssh console or reboot the machine or anything happens, it stopped and I have to repeat these commands

I tried to add it as a corn job to be run after machine reboot but it does not work

I post a question in the following link : run python app after server restart does not work using crontab

nothing work with me, and I have to make sure that this web app will always be running because it should be working to send push notification to mobile devices

can anyone please advice, I have been searching and trying for so many time

2

Answers


  1. I’m not expert in it, but two solutions come in my mind:

    1- Using systemd:

    systemd can be responsible to keep services up.

    You can write a custom unit for your app, and config it as a way to be up always.

    This tutorial may be useful: writing unit

    2- Using Docker:

    When you have containerized app, you config it as to come up, on failure or anything like that.

    Read about it here

    Login or Signup to reply.
  2. What if you have the calling piece of Python script within a bash script and run that as a daemon:

    Your bash script could like below (test.sh):

    #!/bin/sh
    cd desired/directory
    python3 app.py
    

    and you can run the bashscript like this by using nohup:

    nohup ./test.sh 0<&- &>/dev/null &
    

    You could refer this, if you want to store the outputs of nohup.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search