Upstart script and start-stop-daemon
I had an issue where making an upstart script would call the script multiple times, causing my IRCd to spawn around 8 times or so. In order to rectify this, I used start-stop-daemon:
description "IRC Daemon Upstart Script"
start on startup
start on runlevel [2345]
stop on runlevel [016]
respawn
nice -5
exec start-stop-daemon --start --chuid ircuser --chdir /home/ircuser/inspircd/run --exec /home/ircuser/inspircd/run/bin/inspircd -- --config=/home/ircuser/inspircd/run/conf/inspircd.conf
This works exactly like I want it to, EXCEPT that:
stop ircd
says that it stops it, but inspircd is still running afterwards.
Is there a better way than using start-stop-daemon that will stop the script from opening 8 instances, or is there some way I can make it compatible with the start-stop-daemon?
I can't be entirely sure but inspircd might be forking out the way when it's run so Upstart doesn't know where its PID really is. If that's the case, it can be fixed because Upstart has two stanzas for handling forking processes:
-
expect fork
catches processes that fork once (imo, most likely the case here). -
expect daemon
catches things that fork out twice... Which this may be doing.
So try this:
description "IRC Daemon Upstart Script"
start on startup
start on runlevel [2345]
stop on runlevel [016]
respawn
expect fork
nice -5
exec su bash -c "cd /home/ircuser/inspircd/run; /home/ircuser/inspircd/run/bin/inspircd -- --config=./conf/inspircd.conf" ircuser
And if that doesn't work, check my su
-statement to make sure it works from the command line and then change expect fork
to expect daemon
and give it another whirl.
Edit the bash
wrapper might be doing it more harm than good. This might be a better exec:
exec sudo -u ircuser /home/ircuser/inspircd/run/bin/inspircd -- --config=/home/ircuser/inspircd/run/conf/inspircd.conf