this is Ubuntu 10.10 Maverick.

I have the following shell script in init.d that I want to run as a "daemon" (background service with start/stop/restart really) at system startup. There is a symlink in rc3.d. I tried 4 and 5 too. (Ideally this would initialize before graphical login happens and before a user logs in.)

IMPORTANT: the script works 100% as expected and required when testing this with service MetaLeapDaemon start and service MetaLeapDaemon stop. (This shell script calls a Python program which makes sure the appropriate .pid files are both created at startup and deleted at exit.)

So generally it works fine but now my only issue is why it will not be run at any of the run-levels I tried. I know for sure it isn't run because the log file it normally creates does not get created.

As you can see (by the lack of any uid:gid args in the start-stop-daemon commands) this would currently run only under root, is this forbidden in a default setup?

Here's the script, pretty much your run-off-the-mill daemon script really:

#! /bin/sh


test -f $DAEMON || exit 0

set -e

case "$1" in
        start-stop-daemon --start --pidfile /var/run/$NAME.pid --exec $DAEMON
        start-stop-daemon --stop --pidfile /var/run/$NAME.pid
        start-stop-daemon --stop --pidfile /var/run/$NAME.pid
        sleep 1
        start-stop-daemon --start --pidfile /var/run/$NAME.pid --exec $DAEMON
        echo "Usage: $N {start|stop|restart}" >&2
        exit 1

exit 0
  • OK... now that I asked this question I get Related Recommended Questions from AskUbuntu... will check these out now.
    – pearjoint
    Apr 10, 2011 at 8:57
  • Will go with Upstart.
    – pearjoint
    Apr 10, 2011 at 10:00

2 Answers 2


I'm answering this for completeness, even though you already went with an Upstart job (and that is the way to go, I'm not suggesting here you go back)....

I think the key thing you missed first time around was the runlevel. I'm going to guess you are used to RPM distro's where it's typically runlevel 3 for multiuser and runlevel 5 for GUI?

In Debian and Ubuntu, there's really only single user (1) and multiuser (with GUI if installed). And multi user is runlevel 2. So your symlinks failed because you never got to RL 3.

Using the update-rc.d command makes managing the symlinks easier.

In any case, I'm writing this up for anyone else you might actually need it. Though I would suggest they convert the script to an Upstart too!


Use the following command to start your script at startup.

Add it to the startup applications.


By the way, someone told me to use NOPASSWORD, else it won't work:

You'd better run sudo visudo to edit the /etc/sudoers file and add a NOPASSWD for the command instead of writing the password in the script. – Lekensteyn

I hope this helped you,


  • 1
    Thanks but no longer needed... Upstart is way better for me and worked at first attempt!
    – pearjoint
    Apr 10, 2011 at 15:45
  • 1
    Also this is for redistribution for "semi-admin" end users... if I asked them to type their password in an init.d script to finalize setup... I could just as well tell them to script their own daemon ;)
    – pearjoint
    Apr 10, 2011 at 15:47
  • please post an answer by yourself, that other users can read what the answer is. thank you, Daniel :)
    – omnidan
    Apr 10, 2011 at 15:51
  • 1
    echo PASSWORD | sudo -u USERNAME COMMAND won't work. sudo reads the password from the terminal, not stdin.
    – geirha
    Apr 10, 2011 at 22:15
  • 1
    OK Daniel the answer is in Ubuntu it's not sufficient to put a shell script in init.d, it also needs to be registered via the insserv command. And I don't know if this would have worked because the "new" Upstart system is designed to take the place of the "old" init.d system. And indeed it's so much easier to handle and a valid .conf file in /etc/init/ (not .d) is sufficient.
    – pearjoint
    Apr 11, 2011 at 3:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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