Skip to content

Instantly share code, notes, and snippets.

@dberardo-com
Forked from puhitaku/supervisor
Last active February 14, 2025 11:51
Show Gist options
  • Save dberardo-com/ffc0bd54bee472a987063b1453196b09 to your computer and use it in GitHub Desktop.
Save dberardo-com/ffc0bd54bee472a987063b1453196b09 to your computer and use it in GitHub Desktop.
Supervisor init script for OpenWrt (procd).
#!/bin/sh /etc/rc.common
START=99
STOP=10
SERVICE_DAEMONIZE=1
SERVICE_WRITE_PID=1
PIDFILE=/var/run/supervisord.pid
LOCKFILE=/var/run/supervisord_up.lock
LOCKFILE_DOWN=/var/run/supervisord_down.lock
SUPERVISORCTL_BIN=$(which supervisorctl)
PIDFILE=/tmp/supervisord.pid
CONFIG=/etc/supervisord.conf
start() {
if pgrep -f "supervisord" > /dev/null; then
echo "Supervisor is already running. Exiting."
rm -f "$LOCKFILE"
exit 1
fi
if [ -f "$LOCKFILE" ]; then
echo "Start command has already been issued. Exiting."
exit 1
fi
if [ -f "$LOCKFILE_DOWN" ]; then
echo "Supervisor is being stopped. Exiting."
exit 1
fi
# Create lock file
touch "$LOCKFILE"
# Start Supervisor
/usr/bin/supervisord $PROG -c $CONFIG -j $PIDFILE
# Ensure Supervisor started properly before keeping the lock
if ! pgrep -f "supervisord" > /dev/null; then
echo "Supervisor failed to start."
rm -f "$LOCKFILE"
exit 1
fi
rm -f "$LOCKFILE" || echo Lockfile removed
}
stop() {
if ! pgrep -f "supervisord" > /dev/null; then
echo "Supervisor is already down"
rm -f "$LOCKFILE_DOWN"
else
if [ -f "$LOCKFILE_DOWN" ]; then
echo "Stop command has already been issued. Exiting."
exit 1
fi
touch $LOCKFILE_DOWN
if [ -f "$LOCKFILE" ]; then
echo "Stop command while start was still in progress."
killall supervisord > /dev/null
rm -f "$LOCKFILE"
rm -f "$LOCKFILE_DOWN"
exit 0
fi
echo "Stopping Supervisor..."
$SUPERVISORCTL_BIN -c $CONFIG stop all
rm -f "$LOCKFILE"
rm -f "$LOCKFILE_DOWN"
echo "Done stopping"
killall supervisord > /dev/null
fi
}
restart() {
stop
sleep 2
start
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment