Upstart
Since I’m struggling with upstart, the ubuntu init
replacement, I’m writing down some notes.
When you run start
, status
and stop
commands on a daemon you’re actually running initctl {command}
. You can see the available commands by running initctl help
.
Most Ubuntu installations maintain the older /etc/init.d
scripts for compatibility. You run those scripts with the traditional /etc/init.d/service_name {start|stop}
. If you take a look at the /usr/sbin/service
script you might notice that it contains the logic to check whether the script if configured in /etc/init
or /etc/init.d
and behaves according to that.
Some definitions
Upstart makes a difference between tasks and services. A task is a short-running process, while a service is a process that should keep running.
A job is defined in a /etc/init/<jobname>.conf
configuration file.
Upstart also defines events
and hooks
, but for the time being we don’t care about them.
Configuration syntax
There are a few directives:
Easy ones
# this is a comment
author "Author name"
description "Description of the job"
console
console <log|none|output|owner>
Attaches stdin
, stdout
, and stderr
as requested:
log
: only used by system logs. Uses/var/log/upstart/*
asstdout
none
:/dev/null
for everythingoutput
: uses the console device (what does it mean?)owner
: similar tooutput
chdir / chroot
chdir /var/mydirectory
chroot /var/mydirectory
Runs the process with the specified working directory or in a chrooted jail rather than /
.
exec
exec COMMAND [ARGS] ...
Single-line command to run
expect
expect <fork|daemon|stop>
This is the most dreaded configuration line. This tells upstart how the process will behave fork-wise.
If the process doesn’t fork then don’t use this directive. If it forks once then use fork
; if twice then daemon
.
respawn
respawn
If enabled, the process will be restarted when its goal was changed to stop
.
respawn limit COUNT INTERVAL
With this directive the job will be stopped if it is respawned more than COUNT
times in INTERVAL
seconds.
setgid / setuid
Sets the process user and group. Works with Upstart v1.4, mind you!
start
start on runlevel [2345]
Many syntaxes are allowed here. You can also hook the start to an external event:
start on started mysql
stop
Similar to start
.
Reminders
Runlevels
You should know this, but..
- 0: system halt
- 1: single user mode
- 2: multi-user + networking (default)
- 3-5: same as 2 but not used
- 6: system reboot
Links
- http://upstart.ubuntu.com/cookbook/