Starting up with upstart

July 3, 2012 - Words by Matej Artač

July 3, 2012
Words by Matej Artač

You may not care much for the recent way that Debians handles services: upstart. It seems easy enough to create new services, so here’s a quick overview.

First, we create a link to upstart-job in /etc/init.d.

$ cd /etc/init.d
$ ln -s /lib/init/upstart-job my-service

Then we create a script to tell upstart what happens when we want to start or stop the job. The script should go into /etc/init and is named after the job, but with the suffix .conf:

$ cd /etc/init
$ cat my-service.conf
# contents of
my-service.conf

kill timeout 10 # wait 10s between SIGTERM and SIGKILL.
pre-start script
    mkdir -p /var/log/my-service/
end script

start on runlevel [2345]
stop on runlevel [06]

script
    cd /var/lib/my-service
    ./my-service.sh
end script

Now we can start the service using:

$ start my-service

and stop it using:

$ stop my-service

Social media

Keep up with what we do on our social media.