init
Upstart init daemon job configuration
- Provided by: upstart (Version: 1.13.2-0ubuntu21.1)
- Report a bug
Upstart init daemon job configuration
On startup, the Upstart init(8) daemon reads its job configuration from files in the /etc/init/ directory by default, and watches for future changes to these files using inotify(7).
If Upstart was invoked as a user process with --user option, it will run in User Session mode. See User Session Mode for further details.
To be considered by Upstart, files in this directory must have a recognized suffix and may also be present in sub-directories. There are two recognized suffixes:
A job can thus be defined by either:
Unless explicitly stated otherwise, any reference to a jobs configuration can refer both to a configuration file or an override file.
Each configuration file defines the template for a single service (long-running process or daemon) or task (short-lived process).
Note that a configuration file is not itself a job: it is a description of an environment a job could be run in. A job is the runtime embodiment of a configuration file.
The configuration file name as displayed by Upstart and associated tooling is taken from its relative path within the directory without the extension. For example a configuration file /etc/init/rc-sysinit.conf is named rc-sysinit, while a configuration file /etc/init/net/apache.conf is named net/apache. Since override files only modify the way a configuration file is interpreted, they are not named.
Configuration files are plain text and should not be executable.
Upstart is able to manage jobs within a chroot(2). To control jobs within the chroot environment, use the standard initctl(8) facility. Note that it is not necessary to install D-Bus within the chroot (in fact it is not recommended).
Note that this facility is distinct from the chroot stanza (see Process environment below).
Upstart can manage complete User Sessions. In this mode it runs with a process id greater than 1 and will read job configuration files from the following list of directories in the order shown:
Note that the first directory to contain a job is considered the owner of that job name: any subsequently searched directory that contains a job of the same name will be ignored. The same applies for override files: only the first override file found in the search order will be applied. Note that an override file can be in the same directory or earlier to that directory which contains the job file.
Jobs in these locations are expected to launch the user's session. Upstart will try to parent all spawned process with the aid of prctl(2). If successful this will ensure that even double-forking daemons will be reparented to the User Session process, and not to the init(8) daemon running with process id 1.
When running in User Session mode, Upstart will kill all job processes on session logout or shutdown.
All log output will be in $XDG_CACHE_HOME/upstart which defaults to $HOME/.cache/upstart
Each line begins with a configuration stanza and continues until either the end of the line or a line containing a closing stanza. Line breaks within a stanza are permitted within single or double quotes, or if preceded by a blackslash.
If a stanza is duplicated, the last occurence will be used. Unrecognized stanzas will generate parse errors, which will stop a job from running.
Stanzas and their arguments are delimited by whitespace, which consists of one or more space or tab characters which are otherwise ignored unless placed within single or double quotes.
Comments begin with a `#' and continue until the end of the line. Blank lines and lines consisting only of whitespace or comments are ignored.
The primary use of jobs is to define services or tasks to be run by the init(8) daemon. Each job may have one or more different processes run as part of its lifecycle, with the most common known as the main process.
The main process is defined using either the exec or script stanzas, only one of which is permitted. These specify the executable or shell script that will be run when the job is considered to be running. Once this process terminates, the job stops.
All processes are run with the full job environment available as environment variables in their process.
exec /usr/sbin/acpid -c $EVENTSDIR -s $SOCKET
The script stanza appears on its own on a line, the script is everything up until the first end script stanza appearing on its own on a line.
script
dd bs=1 if=/proc/kmsg of=$KMSGSINK
exec /sbin/klogd -P $KMSGSINK
end script
There are an additional four processes that may be run as part of the job's lifecycle. These are specified as the process name, followed by an exec or script stanza.
All of these processes, including the main process, are optional. Services without a main process will appear to be running until they are stopped: this is commonly used to define states such as runlevels. It is permissible to have no main process, but to have pre-start and post-stop processes for the state.
pre-start exec ifup -a post-stop exec ifdown -a
Jobs can be manually started and stopped at any time by a system administrator using the start(8) and stop(8) tools, however it is far more useful for jobs to be started and stopped automatically by the init(8) daemon when necessary.
This is done by specifying which events should cause your job to be started, and which cause your process to be stopped again.
The set of possible events is limitless, however there are a number of standard events defined by the init(8) daemon and telinit(8) tools that you will want to use.
When first started, the init(8) daemon will emit the startup(7) event. This will activate jobs that implement System V compatibility and the runlevel(7) event. As jobs are started and stopped, the init(8) daemon will emit the starting(7), started(7), stopping(7) and stopped(7) events on their behalf.
You may also match on the environment variables contained within the event by specifying the KEY and expected VALUE. If you know the order in which the variables are given to the event you may omit the KEY.
VALUE may contain wildcard matches and globs as permitted by fnmatch(3) and may expand the value of any variable defined with the env stanza.
Negation is permitted by using != between the KEY and VALUE.
If an event is emitted for which no jobs have registered interest (via either start on or stop on), the event is destroyed.
If a job specifies a single event in its start condition and that event is emitted and matches any specifies event environment variables, the overall condition becomes true, the job is started and -- assuming no other job has registered an interest in it -- the event is destroyed.
However, if an event is emitted which matches part of a jobs start condition, the job is said to be blocking the event (since the event is unable to change state until the job has started) and will both cause the event to persist and the job start condition to be marked as partially completed. Once all events in the start condition have been emitted, the overall job start condition becomes true and the job will be started. If no other jobs have registered interest in the events in the start condition, they will then be destroyed.
Note that no job processes are started until the overall expression evaluates to true.
Note that if a new job is created which specifies that it starts on one or more events that have already been destroyed, that job will not start automatically until those events are emitted again. Depending on the event, this may not happen until the next time the system is booted.
Although complex expressions are supported, it should be possible to specify the start condition for the majority of jobs with very simple expressions (between one and four events as a very approximate guide). A large number or complex combination of events is often an indication that the condition should be refactored.
Examples of start on conditions:
start on started gdm or started kdm start on stopped JOB=foo RESULT=failed PROCESS=pre-start start on device-added SUBSYSTEM=tty DEVPATH=ttyS* start on net-device-added INTERFACE!=lo start on (A and B C=D and E F=G)
VALUE may additionally expand the value of any variable that came from the job's start environment (either the event or the command that started it).
Examples of stop on conditions:
stop on A stop on starting B and stopped JOB=C stop on stopping gdm or stopping kdm stop on device-removed DEVPATH=$DEVPATH
Each job is run with an environment constructed from the following categories:
All jobs contain the TERM and PATH variables.
These commands also allow unsetting of variables.
All jobs also contain the UPSTART_JOB and UPSTART_INSTANCE environment variables, containing the name of the job and instance. These are mostly used by the initctl(8) utility to default to acting on the job the commands are called from.
The special UPSTART_EVENTS environment variable contains the list of events that started the job, it will not be present if the job was started manually.
The pre-stop and post-stop scripts are run with the environment of the events or commands that stopped the job. The UPSTART_STOP_EVENTS environment variable contains the list of events that stopped the job, it will not be present if the job was stopped manually.
Note that each KEY is the name of a variable; it is not prefixed with a dollar ('$') sign.
The first two categories above comprise the job environment table which is applied to all jobs. Note that changing the job environment table will only affect newly-started jobs.
Jobs are services by default. This means that the act of starting the job is considered to be finished when the job is running, and that even exiting with a zero exit status means the service will be respawned.
The start(8) command, and any starting(7) or stopping(7) events will block only until a service is running or until a task has finished.
If the special argument unlimited is specified instead of a COUNT and INTERVAL value, no limit will be applied and the job will be respawned indefinitely. Specifying either COUNT or INTERVAL as zero implies unlimited.
This stanza only applies to automatic respawns and not the restart(8) command.
normal exit 0 1 TERM SIGHUP
By default, only one instance of any job is permitted to exist at one time. Attempting to start a job when it's already starting or running results in an error. Note that a job is considered to be running if its pre-start process is running.
Multiple instances may be permitted by defining the names of those instances. If an instance with the same name is not already starting or running, a new instance will be started instead of returning an error.
These will often be variables that you need to pass to the process anyway, so are an excellent way to limit the instances.
instance $CONFFILE exec /sbin/httpd -c $CONFFILE
instance $TTY exec /sbin/getty -8 38300 $TTY
These jobs appear in the initctl(8) output with the instance name in parentheses, and have the INSTANCE environment variable set in their events.
Upstart provides several stanzas useful for documentation and external tools.
description "This does neat stuff"
author "Scott James Remnant <scott@netsplit.com>"
version "$Id$"
This stanza allows a job to document in its job configuration what events it emits itself, and may be useful for graphing possible transitions.
The initctl(8) check-config command attempts to use this stanza to resolve events.
EVENT can be either a literal string or a string including shell wildcard meta-characters (asterisk ('*'), question mark ('?'), and square brackets ('[' and ']')). Meta-characters are useful to allow initctl(8) check-config to resolve a class of events, such as those emitted by upstart-udev-bridge(8).
usage "tty DEV=ttyX - where X is console id"
Many common adjustments to the process environment, such as resource limits, may be configured directly in the job rather than having to handle them yourself.
Output is logged to file /var/log/upstart/<job-log-file> or $XDG_CACHE_HOME/upstart/<job-log-file> for system and user session jobs respectively.
If a job has specified instance, <job-log-file> will equate to <job>-<instance>.log where '<instance>' is replaced by the specific instance value and '<job>' is replaced with the job name (job configuration file name, without the extension). If instance is not specified, <job-log-file> will be <job>.log where '<job>' is replaced with the job name.
Jobs started from within a chroot will have their output logged to such a path within the chroot.
If log files already exist, they are appended to.
All slash ('/') characters in <job-log-file> are replaced with underscore ('_') characters. For example, any output from the 'wibble' instance of the 'foo/bar' job would be encoded in file 'foo_bar-wibble.log' in the log file directory. This gives the log file directory a flat structure.
If the directory for system jobs does not exist, job output for each job will be cached until the job finishes. Thus, the boot process must ensure that the directory is available as soon as possible since any job that finishes before a writeable disk is available will not be able to take advantage of this facility.
If it is not possible to write to any log file due to lack of disk space, the job will be considered to have specified a console value of none and all subsequent job output will be discarded.
If the logger detects that the file it is about to write to was deleted, it will re-open the file first.
Care should be taken if the log directory is a mount point since any job that starts before that mount is available and which produces output will then attempt to write logs to the mount point, not to the mounted directory. This may give the impression that log data has not been recorded. A strategy to handle this situation is to ensure the mount point directory is not writeable such that logs will only be written when the mount has succeeded (assuming the mount itself is writeable and has sufficient space).
Note that since log utilizes pseudo-ttys, your kernel must support these. If it does not, the console value will be modified automatically to none. Further, note that it may be necessary to increase the number of available pty devices; see pty(7) for details.
Under Linux, full Unix 98 pty support requires that the devpts filesystem be mounted.
If pty setup fails for any reason, an error message will be displayed and the job's console value will be reset to none.
ADJUSTMENT may be an integer value from -999 (very unlikely to be killed by the OOM killer) up to 1000 (very likely to be killed by the OOM killer). It may also be the special value never to have the job ignored by the OOM killer entirely.
Note that DIR must have all the necessary system libraries for the process to be run, often including /bin/sh
Limits are specified as both a SOFT value and a HARD value, both of which are integers. The special value unlimited may be specified for either.
The job process will run with the primary group of user USERNAME unless the setgid stanza is also specified in which case that group will be used instead.
For system jobs initgroups(3) will be called to set up supplementary group access.
Failure to determine and/or set user and group details will result in the overall job failing to start.
If this stanza is unspecified, all job processes will run with user ID 0 (root) in the case of system jobs, and as the user in the case of user jobs.
Note that system jobs using the setuid stanza are still system jobs, and can not be controlled by an unprivileged user, even if the setuid stanza specifies that user.
For system jobs initgroups(3) will be called to set up supplementary group access.
If this stanza is unspecified, the primary group of the user specified in the setuid block is used for all job processes. If both this and the setuid stanza are unspecified, all job processes will run with their group ID set to 0 (root) in the case of system jobs, and as the primary group of the user in the case of User Session jobs.
This stanza will be ignored if the version of Upstart is new enough to support cgroups but has been built without cgroup support.
This stanza will also be ignored if the init(8) daemon has had cgroup support disabled at boot time (see init (8)).
A job which specifies this stanza will not be started until both its start on condition is met and the address of the cgroup manager has been communicated to the init(8) daemon using the initctl(8) command notify-cgroup-manager-address.
If only the cgroup controller (such as memory, cpuset, blkio) is specified, a job-specific cgroup will be created and the job processes placed in it. The form of this cgroup is
upstart/$UPSTART_JOB
or if the job specifies the instance stanza the group will be the expanded value of:
upstart/$UPSTART_JOB-$UPSTART_INSTANCE
Any forward slashes in $UPSTART_JOB and $UPSTART_INSTANCE will be replaced with underscore ('_') characters.
This default cgroup for the job may be specified explicitly within a NAME using the special variable $UPSTART_CGROUP. This variable is not an environment variable and is only valid within the context of the cgroup stanza.
If NAME is not specified or does not contain $UPSTART_CGROUP, the job processes will not be placed in an upstart-specific
Note that this special variable cannot be specified with enclosing braces around the name.
No validation is performed on the specified values until the job is due to be started.
If the CONTROLLER is invalid, or the NAME cannot be created or the KEY or VALUE are invalid, the job will be failed.
The NAME argument may contain any valid variable and can also contain forward slashes to run the job processes in a sub-cgroup.
If any argument contains space characters, it must be quoted.
If a KEY is specified, a VALUE must also be specified (even it is simply an empty string).
The stanza maybe specified multiple times. The last occurence will be used except in the scenario where each occurence specifies a different KEY in which case all the keys and values will be applied.
It is not an error if NAME already exists.
Valid syntax:
Implicit NAME, no setting.
cgroup CONTROLLER
Explicit name, no setting.
cgroup CONTROLLER NAME
Implicit name with setting.
cgroup CONTROLLER KEY VALUE
Explicit name with setting.
cgroup CONTROLLER NAME KEY VALUE
cgroup cpu
cgroup cpu $UPSTART_CGROUP
cgroup cpu "$UPSTART_CGROUP"
cgroup cpu "a-well-known-cgroup"
cgroup memory $UPSTART_CGROUP limit_in_bytes 52428800 cgroup cpuset $UPSTART_CGROUP cpus 0-1 cgroup blkio slowio throttle.write_bps_device "8:16 1048576"
Override files allow a jobs environment to be changed without modifying the jobs configuration file. Rules governing override files:
Upstart provides several stanzas for loading and switching to different AppArmor profiles. If AppArmor isn't enabled in the currently running kernel, the stanzas will be silently ignored.
apparmor load /etc/apparmor.d/usr.sbin.cupsd
apparmor switch /usr/sbin/cupsd
kill signal INT
reload signal USR1
init(8) will send the process the SIGCONT signal to allow it to continue.
Without this stanza init(8) is unable to supervise daemon processes and will believe them to have stopped as soon as they daemonise on startup.
Without this stanza init(8) is unable to supervise forking processes and will believe them to have stopped as soon as they fork on startup.
The use of symbolic links in job configuration file directories is not supported since it can lead to unpredictable behaviour resulting from broken or inaccessible links (such as would be caused by a link crossing a filesystem boundary to a filesystem that has not yet been mounted).
The and and or operators allowed with start on and stop on do not work intuitively: operands to the right of either operator are only evaluated once and state information is then discarded. This can lead to jobs with complex start on or stop on conditions not behaving as expected when restarted. For example, if a job encodes the following condition:
start on A and (B or C)
When 'A' and 'B' become true, the condition is satisfied so the job will be run. However, if the job ends and subsequently 'A' and 'C' become true, the job will not be re-run even though the condtion is satisfied. Avoid using complex conditions with jobs which need to be restarted.
Manual page written by Scott James Remnant <scott@netsplit.com> and James Hunt <james.hunt@canonical.com>.
Report bugs at <https://launchpad.net/upstart/+bugs>
Copyright © 2009-2013 Canonical Ltd.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.
apparmor(7), cgmanager(8), init(8), initctl(8), prctl(2), pty(7), sh(1), upstart-events(7).