Supervisor... it keeps your app running!

supervisor is a nice thing. It keeps your app running.

sudo apt-get install supervisor

Config goes in...

/etc/supervisor/conf.d/ directory

You might for example add a file helloworld.conf in the required place with content such as

$ cat helloworld.conf
[program:helloworld]
command=/usr/bin/dotnet /home/leon/publish/MvcMovie.dll
#var/aspnetcore/HelloMVC/HelloMVC.dll
#directory=/var/aspnetcore/HelloMVC/
directory=/home/leon/publish/
autostart=true
autorestart=true
stderr_logfile=/var/log/helloworld.err.log
stdout_logfile=/var/log/helloworld.out.log
environment=ASPNETCORE_ENVIRONMENT=Production
user=www-data
stopsignal=INT

Here's how to view the last 20 lines of the supervisor log, using tail

$ sudo tail -n 20 -f /var/log/supervisor/supervisord.log

...in which you might see it struggle to keep your app running...

Or the last 20 lines of your app's error output...

$ sudo tail -n 20 -f /var/log/helloworld.err.log

Or the last 20 lines of your app's standard (non error) output...

$ sudo tail -n 20 -f /var/log/helloworld.out.log

To restart supervisor after you've given it some new configuration:

    service supervisor stop
    service supervisor start

I noticed that supervisor did not successfully restart when I rebooted my linux box.

I restarted it with service supervisor start (which required me to type my password)

First though, I checked the status with service supervisor status, and saw:

user1@machine1:~$ service supervisor status
? supervisor.service - Supervisor process control system for UNIX
   Loaded: loaded (/lib/systemd/system/supervisor.service; disabled; vendor preset: enabled)
   Active: inactive (dead)
     Docs: http://supervisord.org

Starting it went like this...

user1@machine1:~$ service supervisor start
==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===
Authentication is required to start 'supervisor.service'.
Authenticating as: user1,,, (user1)
Password:
==== AUTHENTICATION COMPLETE ===

And now I get this result from status --

user1@machine1:~$ service supervisor status
? supervisor.service - Supervisor process control system for UNIX
   Loaded: loaded (/lib/systemd/system/supervisor.service; disabled; vendor preset: enabled)
   Active: active (running) since Thu 2017-04-06 07:19:51 EDT; 4min 19s ago
     Docs: http://supervisord.org
 Main PID: 2795 (supervisord)
    Tasks: 41
   Memory: 275.4M
      CPU: 24.093s
   CGroup: /system.slice/supervisor.service
           +-2795 /usr/bin/python /usr/bin/supervisord -n -c /etc/supervisor/supervisord.conf
           +-2800 /usr/bin/dotnet /opt/webapps/webapp1/app/app1.dll
           +-2801 /usr/bin/dotnet /opt/webapps/webapp2/app/app2.dll
           +-2802 /usr/bin/dotnet /opt/webapps/webapp3/app/app3.dll

TODO: https://lincolnloop.com/blog/automatically-running-supervisord-startup/

recommends:

@reboot    /my/path/to/supervisord -c /my/path/to/supervisord.conf 2>&1

i.e.

@reboot /usr/bin/supervisord -n -c /etc/supervisor/supervisord.conf 2>&1

But I need to add that to my cron jobs using crontab.

Sources

results matching ""

    No results matching ""