upstart init daemon

Published: Monday, 16 September 2013

On Ubuntu, upstart has replaced System-V init. Since Ubuntu 15, systemd replaced upstart.

Adding a new daemon or service

Create your script

There should be existing scripts in /etc/init/. Copy one of them and modify it to suit your needs.

Changing uid

Sometimes the daemon you want to run should be run as a different user. Use the start-stop-daemon command for this. In the case below the teamcity user will be running the daemon.

I’ve placed this in /etc/init/teamcity.conf

# Ubuntu upstart file at /etc/init/teamcity.conf

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

  exec start-stop-daemon --start --quiet --chuid teamcity --exec /home/teamcity/TeamCity/bin/ run
end script

Test your command

Test out the start-stop-daemon command manually.

# start-stop-daemon --start --chuid teamcity --exec /home/teamcity/TeamCity/bin/ run

If it is working fine then your script is ready. Kill the job and in the next step start it via the upstart command.

Start the job

Use the start command. The name of your job must match the name of your conf file in /etc/init.

# start teamcity
teamcity start/running, process 7407


Reboot and check that your service automatically starts.

Stopping the job

Use the stop command. If your job has forked upstart may have trouble stopping it.