Ubuntu Adding Startup Daemon/Process

Translation of the original in Catalan. Read it in: CatalàCastellano

This is one of those articles I never know how to title in Catalan. So it has stayed in English. Basically it's about documenting a little the sweat it cost me to find out what on earth the equivalent of Gentoo's /etc/conf.d/local.start was in Ubuntu. In fact, in the end I didn't find it. What I had to do is create a file in /etc/init.d and launch it as a startup daemon in the runlevels I'm interested in. In fact, this solution is cleaner than the one I wanted to apply initially but in the end I wasted a good while finding out how to do it and that's why I decided to document it.

The specific problem I had was that I wanted to launch Abyss Webserver when the machine starts. Specifically the command to launch it is:

# su usuari /opt/abyssws/abyssws -d

Well, to create the file that made this call you have to base it on the /etc/init.d/skeleton file. Skeleton uses the same script as start-stop-daemon in Gentoo to make the call to the Abyss daemon. To know more details about how this complete script works I recommend you look at the man page of the command.

The previous command to launch Abyss based on start-stop-daemon would be like this:

start-stop-daemon --start --quiet --pidfile /var/run/abyssws.pid -u usuari --exec /opt/abyssws/abyssws -- -d

As for the whole script you can also use a daemon startup file generator that I found at Robert Pectol's Ubuntu Linux Projects Website - Startup Script Generator, the problem is that this generator is very basic and doesn't support passing parameters to start-stop-daemon. That is, we couldn't define which user should launch the daemon.

After creating the script that will launch the daemon you just have to add it to the runlevels you're interested in. For example, if we want it to be available in any runlevel we can do:

# update-rc.d script defaults

If what we want is to start it last (position 99) in the boot sequence in runlevels 2, 3, 4 and 5 the command would be like this:

# update-rc.d -f script start 99 2 3 4 5

If what you don't know is which runlevel you're working in, it's as simple as typing runlevel and it will inform you of the current runlevel. A small reference of which runlevels exist you can find here.

1 comment

Comments from the old blog, as they were written. Comments are closed.

  1. carles

    a veure si t'ajuda...

    /etc/init.d te tot el llistat de serveix a llençar però no s'executa a l'inici del sistema. per aixo tenen /etc/rcS.d que links (ln -s ...) a /etc/init.d si et fixes. el directori rcS.d s'executara sempre independentment del rcX.d. també hi ha un script running local boot scripts (/etc/rc.local).

    salut!