Debian Policy on Starting Services on Installation

debianservices

Debian packages usually start services right after installing them. This is a well-known phenomenon, given tens of webpages explaining how to disable this behavior. As far as I remember, this has been in place before systemd has been adopted.

My question is, is it an official policy? Has this rule been written down anywhere? I've tried looking for it in the Debian Policy, but couldn't find relevant notes.

Best Answer

This is addressed in the “Managing the links” section of Policy, which described how links to services should be handled:

The default behaviour is to enable autostarting your package’s daemon.

Here I’m reading “autostarting” in a wide sense; technically since this section of Policy only deals with “links”, i.e., configuring services to start at boot, it could be read as only requiring this, but that would lead to inconsistent system states (i.e. a service installed but not started until the next boot). The recommendations in this section and the next one:

It is easiest for packages not to call update-rc.d directly, but instead use debhelper programs that add the required update-rc.d calls automatically. See dh_installinit, dh_installsystemd, etc.

It is easiest for packages not to call invoke-rc.d directly, but instead use debhelper programs that add the required invoke-rc.d calls automatically. See dh_installinit, dh_installsystemd, etc.

result in services which, by default, are enabled and started immediately.

Other sections of Policy assume this, or at least result from a requirement to support this; thus in the section on configuration files:

The scripts are not required to configure every possible option for the package, but only those necessary to get the package running on a given system. Ideally the sysadmin should not have to do any configuration other than that done (semi-)automatically by the postinst script.

If necessary though, Policy allows the opposite behaviour:

If, however, the daemon should not be autostarted unless the local administrator has explicitly requested this, instead add to your postinst script:

update-rc.d package defaults-disabled

The defaults can also be configured locally; for example debootstrap-style chroots are often set up to skip running services.

This section of Policy needs to be updated for systemd, but the general principle still applies.

Related Question