The reason I'm doing this script is because I want to daemonize supervisord: right now I'm in a cloud host in which I don't have access to the /etc
or the sudo
command; this script is my best attempt to do everything from my /home
. I have this bash script with the start-stop-daemon
command but it allows me to run it multiple times, and I would like it to just run just once.
So far here is what I got:
#! /bin/bash
SUPERVISORD=/usr/local/bin/supervisord
PIDFILE=/home/user/supervisor/supervisord.pid
OPTS="-c /home/user/supervisor/supervisord.conf -j $PIDFILE"
test -x $SUPERVISORD || exit 0
. /lib/lsb/init-functions
export PATH="${PATH:+$PATH:}/usr/local/bin:/usr/sbin:/sbin"
case "$1" in
start)
log_begin_msg "Starting Supervisor daemon manager..."
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $SUPERVISORD -- $OPTS || log_end_msg 1
log_end_msg 0
;;
stop)
log_begin_msg "Stopping Supervisor daemon manager..."
start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE || log_end_msg 1
log_end_msg 0
;;
restart|reload|force-reload)
log_begin_msg "Restarting Supervisor daemon manager..."
start-stop-daemon --stop --quiet --oknodo --retry 30 --pidfile $PIDFILE
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $SUPERVISORD -- $OPTS || log_end_msg 1
log_end_msg 0
;;
*)
log_success_msg "Usage: {start|stop|reload|force-reload|restart}"
exit 1
;;
esac
exit 0
I assume when the pid file is created it overwrites the previous one, so doing multiple stops doesn't work either. How can I make this script just run once, and not run multiple processes if I do "script start" 5 times? It should complain saying that the process is already running.
sudo service start <daemon>
it will report it is already running if it is, and not restart it./etc
orsudo
are locked that's why I did it this way