How does systemd use _etc_init.d scripts_ - Unix & Linux Stack Exchange

2023/7/27 15:02 How does systemd use /etc/init.d scripts? - Unix & Linux Stack Exchange
https://unix.stackexchange.com/questions/233468/how-does-systemd-use-etc-init-d-scripts 1/4
How does systemd use /etc/init.d scripts?
Asked 7 years, 9 months agoModified 3 years, 2 months agoViewed 224k times
173
I just switched to debian jessie, and most things run okay, including my graphical display
manager wdm.
The thing is, I just don't understand how this works. Obviously my script is
called, because when I put an early in there, wdm is not started. But when I alternatively
rename the directory (my default runlevel used to be 3), then wdm is still started.
/etc/init.d/wdm
exit
/etc/rc3.d
I could not find out how systemd finds this script and I do not understand what it does to all
the other init.d scripts.
When and how does systemd run init.d scrips?
In the long run, should I get rid of all init.d scripts?
systemd init-script init sysvinit
ShareImprove this questionFollow edited May 21, 2020 at 14:08
Ravexina
2,490 1 18 33
asked Oct 2, 2015 at 10:46
Martin Drautzburg
2,488 3 16 18
2 Answers
Sorted by:
Highest score (defa
229
chaos' answer is what some documentation says. But it's not what systemd actually does. (It's
not what van Smoorenburg did, either. most definitely
ignore LSB headers, which 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 environment variable in fact 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.)
rc The van Smoorenburg rc did
not insserv
HOME is
The native service format for systemd is the . systemd's service management
proper operates in terms of those, which it reads from one of nine directories where
(system-wide) files can
live. , , ,
and are four of those directories.
service unit
solely
.service
/etc/systemd/system /run/systemd/system /usr/local/lib/systemd/system
/usr/lib/systemd/system
The compatibility with van Smoorenburg scripts is achieved with a conversion program,
named . This program is listed in the
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.
rc
systemd-sysv-generator /usr/lib/systemd/systemgenerators/
This program is a , 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. generates the service units that
run the van Smoorenburg scripts from , if it doesn't find a native systemd service
unit by that name already existing in the other six locations.
generator
systemd-sysv-generator
rc /etc/init.d
2023/7/27 15:02 How does systemd use /etc/init.d scripts? - Unix & Linux Stack Exchange
https://unix.stackexchange.com/questions/233468/how-does-systemd-use-etc-init-d-scripts 2/4
systemd service management only knows about service units. These automatically
(re-)generated service units are written to invoke the van Smoorenburg scripts. They have,
amongst other things:
rc
[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 scripts must have an LSB header, and are
run in parallel without honouring the priorities imposed by the system. This is
incorrect on all points.
rc
/etc/rc?.d/
In fact, they don't need to have an LSB header, and if they do not
can recognize the more limited old RedHat comment headers ( , ,
and so forth). Moreover, in the absence of an LSB header it will fall back to the contents of
the 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.
systemd-sysvgenerator
description: pidfile:
/etc/rc?.d
The reason that didn't appear to matter is that you probably had that script
enabled via another directory. translates being listed in
any of , , and into a native relationship to
systemd's . Run levels are "obsolete" in the systemd world, and you can
forget about them.
/etc/rc3.d
/etc/rc?.d/ systemd-sysv-generator
/etc/rc2.d/ /etc/rc3.d/ /etc/rc4.d/ Wanted-By
multi-user.target
Further reading
systemd-sysv-generator. systemd manual pages. Freedesktop.org.
. . systemd manual pages.
Freedesktop.org.
"Environment variables in spawned processes" systemd.exec
https://unix.stackexchange.com/a/394191/5132
https://unix.stackexchange.com/a/204075/5132
https://unix.stackexchange.com/a/196014/5132
https://unix.stackexchange.com/a/332797/5132
ShareImprove this answerFollow edited Feb 25, 2019 at 10:06 answered Oct 2, 2015 at 20:31
JdeBP
66.6k 12 159
343
2
In Debian the system-generators directory doesn't live on /usr/lib, but
/lib packages.debian.org/sid/amd64/systemd/filelist – Braiam May 25, 2016 at 13:55
9 This is a straight up amazing answer. Well done sir. – peelman Jan 13, 2017 at 12:13
1 Thank you, thank you, thank you for this! Dealing with a mix of Debian 8 and RH/CentOS 7 systems has
made management of SysVInit vs Systemd service dependency management a bit of a headache but
2023/7/27 15:02 How does systemd use /etc/init.d scripts? - Unix & Linux Stack Exchange
https://unix.stackexchange.com/questions/233468/how-does-systemd-use-etc-init-d-scripts 3/4
this explanation of what systemd is doing has helped my understanding greatly. – Toby Mar 29, 2017 at
17:22
This generator does work. I'd also mention, for followers, that if you have an older version
of and an /etc/init.d script isn't set to "boot on start" it will still work as expected but won't
show up in the show-units lists:
systemd
unix.stackexchange.com/a/518894/8337 – rogerdpack May 14, 2019 at
15:15
This generator does work. I'd also mention, for followers, that if you have an older version of systemd
and an /etc/init.d script that isn't set to "boot on start" it will still start/stop as expected using systemctl
but won't show up in the show-units lists: also NB that
you basically "can't" control these service by running /etc/init.d/xx directly anymore or systemd
gets...confused as to what is running and what isn't :|
unix.stackexchange.com/questions/517872/…
– rogerdpack May 23, 2019 at 16:40
21
Systemd is with SysV init scripts. According to LSB 3.1, the init script
must have informational , defining when the script has to start/stop
and what is required for the script to start/stop. This is an example:
backward compatible
Comment Conventions
### BEGIN INIT INFO
# Provides: my-service
# Required-Start: $local_fs $network $remote_fs
# Required-Stop: $local_fs $network $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start and stop service my-service
# Description: my-service blah blah ...
### END INIT INFO
This is a commented section which is ignored by SysV. On the other hand, systemd reads that
dependency information and runs those scripts depending on that.
But there is one point, where systemd and SysV differ in terms of init scripts. SysV executes
the scripts in sequential order based on their number in the filename. Systemd doesn't. If
dependencies are met, systemd runs the scripts immediately, without honoring the
numbering of the script names. Some of them will most probably fail because of the ordering.
There are a lots of other incompatibilities that should be considered.
If there are init scripts and .service files for the same service, systemd will execute both, as
soon as the dependencies are met (in case of the init script, those defined in the LSB header).
ShareImprove this answerFollow edited Oct 2, 2015 at 20:34
muru
69.4k 13 192
290
answered Oct 2, 2015 at 11:31
chaos
47.4k 11 118
144
Okay, but I also have a whole bunch of .service files in /lib/systemd/system/. What does systemd
actually execute? Whatever is specified in the service files (in dependency order), the init.d scripts or
both? – Martin Drautzburg Oct 2, 2015 at 13:46
@MartinDrautzburg I added that to the answer – chaos Oct 2, 2015 at 13:58
1
As a sidenote, Debian has just announced to dump LSB
compatibility: article.gmane.org/gmane.linux.debian.devel.lsb/1103 – Jan Oct 2, 2015 at 14:22
2023/7/27 15:02 How does systemd use /etc/init.d scripts? - Unix & Linux Stack Exchange
https://unix.stackexchange.com/questions/233468/how-does-systemd-use-etc-init-d-scripts 4/4
2
systemd is anything BUT compatible with SysV scripts. Not only is that statement incorrect, but the
referenced link makes it clear that it is only "mostly compatible" and the amount of effort needed to
produce the same results is outrageously huge. – Julie in Austin Feb 12, 2019 at 19:08
2
I found out the hard way that if the file in /etc/init.d is a symlink, the systemd generator "systemd-sysvgenerator"
that scans for legacy init.d scripts will skip it. My gerrit file in init.d was a symlink to
/home/gerrit2/gerrit/bin/gerrit.sh, I fixed it with: cd /etc/init.d; sudo unlink gerrit; sudo cp
/home/gerrit2/gerrit/bin/gerrit.sh gerrit – Integrator Apr 13, 2020 at 5:58

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值