Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

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
share|improve this answer
    
Thank you! It works more neatly, and yes expect fork fixed the issue. However, I still can't call 'stop ircd' and have the script stop. However, I'll manage without it (ps aux, kill), but if you can amend your answer to include a way to do that, I will be a very happy Ubuntu user ;) –  Liam Dawson Dec 21 '11 at 23:28
    
Hmm - when you run sudo start ircd it should output a PID. If you stick that on the end of ps (eg : ps u -p <PID>) does that show a process that makes sense? If it doesn't it's still losing track of the PID so you might want to try expect daemon –  Oli Dec 21 '11 at 23:47
    
Actually, it doesn't output a PID, just some console output. Oh well, ps aux, kill <pid> works fine, I was more concerned about making the script START on boot, which it does. Thanks! –  Liam Dawson Dec 21 '11 at 23:53

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.