Skip to content

Instantly share code, notes, and snippets.

@abenevaut
Last active April 12, 2025 10:24
Show Gist options
  • Save abenevaut/d6d094fad2581d5f8c6daf5a46c28741 to your computer and use it in GitHub Desktop.
Save abenevaut/d6d094fad2581d5f8c6daf5a46c28741 to your computer and use it in GitHub Desktop.

Prerequisite

  • SSH should be activated and working
  • Python 3.9 should be installed from Package Center
  • supervisord

Install Supervisord

Connect to the NAS with SSH, then log as root:

sudo su

Test if python3 is accessible from root command line:

python3 -V

If python is not accessible from root, complete your ~/.bashrc.

export PATH="/var/packages/Python3.9/target/usr/bin:PATH"

Install or upgrade pip

python3.9 -m ensurepip --upgrade
// or force upgrade
python3.9 -m pip install --upgrade pip

Install supervisor from pip

python3.9 -m pip install supervisor
  • supervisord & supervisorctl are now accessible from command line in root

Configure supervisor

cd /var/packages/Python3.9/target/usr/etc
// create worker directory
mkdir supervisor.d
// create supervisord configuration
vi supervisord.conf

Copy/paste supervisord.conf gist file to supervisord.conf.

Run supervisord with systemd

cd /etc/systemd/system
vi supervisor.service

Copy/paste supervisor.service gist file to supervisor.service

To manage service, the cheat sheet

// Enable/disable service
systemctl enable supervisor.service
systemctl disable supervisor.service

// Start/reload/stop/status the service
systemctl start supervisor.service
systemctl reload supervisor.service
systemctl stop supervisor.service
systemctl status supervisor.service

If you make any change in supervisor.service after enabled it

systemctl daemon-reload

Add worker

Workers should be placed in /volume1/@appstore/Python3.9/usr/etc/supervisor.d/ with .ini extension.

Following, a worker to run Laravel artisan queue worker with php 8.0 (installed from Package Center)

  • Project is installed in /volume1/web/www
  • 3 queues are setup high,default,low from database configuration
  • Logs are drop to /volume1/web/www -> storage/logs/worker.log
[program:www-worker]
process_name=%(program_name)s_%(process_num)02d
command=/usr/local/bin/php80 /volume1/web/www/artisan queue:work database --sleep=3 --tries=3 --max-time=3600 --queue=high,default,low
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
user=root
numprocs=8
redirect_stderr=true
stdout_logfile=/volume1/web/www/storage/logs/worker.log
stopwaitsecs=3600
[Unit]
Description=Supervisor
After=multi-user.target
[Service]
Type=forking
Restart=always
User=root
ExecStart=/var/packages/Python3.9/target/usr/bin/supervisord -c /var/packages/Python3.9/target/usr/etc/supervisord.conf
ExecStop=/var/packages/Python3.9/target/usr/bin/supervisorctl -c /var/packages/Python3.9/target/usr/etc/supervisord.conf shutdown
ExecReload=/var/packages/Python3.9/target/usr/bin/supervisorctl -c /var/packages/Python3.9/target/usr/etc/supervisord.conf reload
PIDFile=/var/run/supervisord.pid
[Install]
WantedBy=multi-user.target
[unix_http_server]
file=/var/run/supervisord.sock
[supervisord]
user=root
logfile=/var/log/supervisord.log
logfile_maxbytes=50MB
logfile_backups=10
loglevel=info
pidfile=/var/run/supervisord.pid
nodaemon=false
silent=false
minfds=1024
minprocs=200
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[supervisorctl]
serverurl=unix:///var/run/supervisord.sock
[include]
files = /var/packages/Python3.9/target/usr/etc/supervisor.d/*.ini
@abenevaut
Copy link
Author

alias supervisor="/opt/homebrew/opt/supervisor/bin/supervisord -c /opt/homebrew/etc/supervisord.conf --nodaemon"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment