chaos' answer is what some documentation says. But it's not what systemd actually does. (It's not what van Smoorenburg rc
did, either. The van Smoorenburg rc
most definitely did not ignore LSB headers, which insserv
used to calculate static orderings, for starters.) The Freedesktop documentation, such as that "Incompatibilities" page, is in fact wrong, on these and other points. (The HOME
environment variable in fact is often set, for example. This went wholly undocumented anywhere for a long time. It's now documented in the manual, at least, but that Freedesktop WWW page still hasn't been corrected.)
The native service format for systemd is the service unit. systemd's service management proper operates solely in terms of those, which it reads from one of nine directories where (system-wide) .service
files can live. /etc/systemd/system
, /run/systemd/system
, /usr/local/lib/systemd/system
, and /usr/lib/systemd/system
are four of those directories.
The compatibility with van Smoorenburg rc
scripts is achieved with a conversion program, named systemd-sysv-generator
. This program is listed in the /usr/lib/systemd/system-generators/
directory and is thus run automatically by systemd early in the bootstrap process at every boot, and again every time that systemd is instructed to re-load its configuration later on.
This program is a generator, a type of ancillary utility whose job is to create service unit files on the fly, in a tmpfs where three more of those nine directories (which are intended to be used only by generators) are located. systemd-sysv-generator
generates the service units that run the van Smoorenburg rc
scripts from /etc/init.d
, if it doesn't find a native systemd service unit by that name already existing in the other six locations.
systemd service management only knows about service units. These automatically (re-)generated service units are written to invoke the van Smoorenburg rc
scripts. They have, amongst other things:
[Unit]
SourcePath=/etc/init.d/wibble
[Service]
ExecStart=/etc/init.d/wibble start
ExecStop=/etc/init.d/wibble stop
Received wisdom is that the van Smoorenburg rc
scripts must have an LSB header, and are run in parallel without honouring the priorities imposed by the /etc/rc?.d/
system. This is incorrect on all points.
In fact, they don't need to have an LSB header, and if they do not systemd-sysv-generator
can recognize the more limited old RedHat comment headers (description:
, pidfile:
, and so forth). Moreover, in the absence of an LSB header it will fall back to the contents of the /etc/rc?.d
symbolic link farms, reading the priorities encoded into the link names and constructing a before/after ordering from them, serializing the services. Not only are LSB headers not a requirement, and not only do they themselves encode before/after orderings that serialize things to an extent, the fallback behaviour in their complete absence is actually significantly non-parallelized operation.
The reason that /etc/rc3.d
didn't appear to matter is that you probably had that script enabled via another /etc/rc?.d/
directory. systemd-sysv-generator
translates being listed in any of /etc/rc2.d/
, /etc/rc3.d/
, and /etc/rc4.d/
into a native Wanted-By
relationship to systemd's multi-user.target
. Run levels are "obsolete" in the systemd world, and you can forget about them.
Further reading
Best Answer
Yes.
You're being bitten by a well-known flaw in System 5
rc
scripts. It's not really anything to do with systemd. You could have hit the flaw if you'd managed to start the scripts up in parallel some other way, such as withstartpar
for example.It's well known that grepping the output of
ps
is prone to races, both againstgrep
and against ongoing system state, and one can find decades of people reporting hitting these same faults over and over again with different shell scripts. It's daft and wrongheaded, and mentioned in the "BUGS" section of the BSD manual page forps
. The world should know better by now.The world does know better, and has for some time. We've had service managers that work properly, without all of these bodged-together mechanisms involving grepping the process list and files that may or may not contain the right number, since the early 1990s. You should definitely, if you are being hit by this and other race conditions, throw those rickety, failure-prone, idiosyncratic, and messy System 5
rc
scripts away and use proper service management. No ifs; no buts; no "quick workarounds" bodges upon the bodges that you are already using (the extragrep
s being themselves a bodge in the first place).There are many such service managers available. You don't have to use systemd. The various scripts that one would write for runit, nosh, or perp are as simple as the unit files that one would write for systemd.
In the nosh and systemd way of doing things, you don't have the two primary services checking for and running the secondary one. That's the job of the service management system. Rather you simply declare a dependency from the two primary services upon the secondary one, so that the service management system knows that when it is told to start
Agentdaemon.service
andSecuritydaemon.service
it has to startcommon.service
as well. In systemd service units this would be aRequires=
or aWants=
setting.Further reading
systemd.unit
. systemd manual pages. freedesktop.org.