What is the recommended way to restart an app (a django+nginx app, in this case).

~/apps/myapp/stop && ~/apps/myapp/start 

doesn't seem to work. Specifically, the commands execute successfully, but the site continues to serve the old code for a few minutes at least.

I think it was working last month, but is not working now.

More info: if I just do ~/apps/myapp/stop and then go to the website, the website is still up, instead of giving me an error.

What am I doing wrong?

Additional info: Currently, I'm forced to do:

pkill -f "/home/navin/apps/myapp/env/bin/uwsgi"

This works, but I would still like for ~/apps/myapp/stop to work as expected.

Usually your uwsgi.ini will contain something like this:

touch-reload = /home/username/apps/appname/myproject/wsgi.py

So to reload your code without restarting you can run: touch /home/username/apps/appname/myproject/wsgi.py

Regarding the stop problem, check that /home/username/apps/appname/tmp/uwsgi.pid contains the proccess ID of your app's uwsgi master process. You can check the pid of the master process by running:

pgrep -o -f  /home/username/apps/appname/env/bin/uwsgi

if it doesn't match then running the following command should fix it:

pgrep -o -f  /home/username/apps/appname/env/bin/uwsgi > /home/username/apps/appname/tmp/uwsgi.pid

At that point your stop command should work correctly.

    3 months later

    sean I followed your instructions but when I stop and start the process ID's are different again

    • sean replied to this.

      Jordan process IDs will always change when you stop and start the app, because you're stopping the old processes and starting new processes in their place.

      If your uwsgi.pid isn't correct after a normal start then please email support@opalstack.com with the details so that we can look into it.

      2 months later

      Facing the same issue.
      I have follwed the thread . so does it mean every time I stop and start . I need to run this "pgrep -o -f /home/username/apps/appname/env/bin/uwsgi > /home/username/apps/appname/tmp/uwsgi.pid" ?

      • sean replied to this.

        arindam Nope, you shouldn't need to do that unless the tmp/uwsgi.pid file is out of sync with the your live process.

        However, if you want to update your stop script so that it deals with this sync problem automatically, here's a version that does that:

        #!/bin/bash
        
        # change this to the name of your app
        APP=appname
        
        # usually no need to edit beyond this line
        APPDIR="$HOME/apps/$APP"
        PIDFILE="$APPDIR/tmp/uwsgi.pid"
        UWSGI="$APPDIR/env/bin/uwsgi"
        PID=$( pgrep -o -f $UWSGI ) || { echo "$UWSGI not running"; exit 99; }
        echo $PID > $PIDFILE
        $UWSGI --stop $PIDFILE
        sleep 3
        pgrep -o -f $UWSGI && {
          echo "uWSGI did not stop, killing it."
          kill -9 $PID
          pkill -9 -f $UWSGI
        }
        rm -f $PIDFILE
        echo "Stopped."
        3 months later

        sean Just wanted to say this saved me from spending more days than needed trying to fix a simple problem. Thank you!

        2 years later

        I'm reading this thread and wondering if one of the offered solutions applies to a situation I've encountered:

        When I stop and then start my Django app, I get a server error on any operation that hits the database. To remedy this, I edit settings.py, changing Debug from False to True, stop and start, then change True back to False and stop/start.

        That always fixes the issue for whatever reason, but as I don't ever really want to expose my app with Debug set to True, what should I do?

        • sean replied to this.

          adebarros You should check ~/logs/apps/name_of_app/uwsgi.log to see what the error message is (ie a Python traceback). Once you've done that you can review the related code to see what the problem might be.

          If you're not sure how to interpret the logs then please email Opalstack support with the details and we'll be happy to assist 🙂

          Mastodon