Upstart recipe for non-forking daemons

Do you need to start your non-forking daemon on Ubuntu Server 15.04? You can use this recipe.

I know that probably systemd will be the default init system even in Ubuntu Server 15.04 but, in the mean time, we have Ubuntu Server 14.04.2 and on that OS the init system is Upstart.

It turns out that Upstart has an introduction here. It is well written and understandable.

If your daemon daemon:

you can write a job description like the following one. It has to be placed in /etc/init/[yourname.conf].

description "Your description here"

start on runlevel [2345]
stop on runlevel [!2345]

env [any environment variables you may need]
setuid [the users that the daemon will run as]
respawn

exec [the name of your daemon here]

Than you can use the following commands:

$ service start <jobname> # starts the job
$ service stop <jobname> # stops the job
$ service status <jobname> # gets the service status

The output of your daemon will be in /var/log/upstart/[jobname]. Isn’t that sweet?