Skip to content

Instantly share code, notes, and snippets.

@pdaw
Last active March 2, 2025 20:11
Show Gist options
  • Save pdaw/7a1cf6727f6cd23e79195af84be97782 to your computer and use it in GitHub Desktop.
Save pdaw/7a1cf6727f6cd23e79195af84be97782 to your computer and use it in GitHub Desktop.
Supervisor running in systemd (it's manually configured because usage of virtualenv, not distribution package)
# activating supervisor service
systemctl enable supervisor.service
# checking if service is active
systemctl is-active supervisor.service
# checking service status
systemctl status supervisor.service
# managing service
systemctl start/stop/restart supervisor.service
# resources about systemd
# http://www.tecmint.com/manage-services-using-systemd-and-systemctl-in-linux/
# https://wiki.archlinux.org/index.php/Systemd
# https://www.digitalocean.com/community/tutorials/understanding-systemd-units-and-unit-files
# /etc/systemd/system/supervisor.service
[Unit]
Description=Supervisor
After=syslog.target network.target
[Service]
ExecStart=/path/to/virtualenv/bin/supervisord --configuration=/path/to/supervisord.conf --logfile=/path/to/log
ExecStop=/path/to/virtualenv/bin/supervisorctl shutdown
ExecReload=/path/to/virtualenv/bin/supervisorctl reload all
Type=forking
Restart=always
[Install]
WantedBy=multi-user.target
@abenevaut
Copy link

https://stackoverflow.com/a/67724450/2090870

PIDFile=

Takes a path referring to the PID file of the service. Usage of this option is recommended for services where Type= is set to forking. The path specified typically points to a file below /run/. If a relative path is specified it is hence prefixed with /run/. The service manager will read the PID of the main process of the service from this file after start-up of the service. The service manager will not write to the file configured here, although it will remove the file after the service has shut down if it still exists. The PID file does not need to be owned by a privileged user, but if it is owned by an unprivileged user additional safety restrictions are enforced: the file may not be a symlink to a file owned by a different user (neither directly nor indirectly), and the PID file must refer to a process already belonging to the service.

Note that PID files should be avoided in modern projects. Use Type=notify or Type=simple where possible, which does not require use of PID files to determine the main process of a service and avoids needless forking.

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