* [gentoo-user] sysV/openrc init script vs. systemd .service file
@ 2014-08-11 20:05 Grant Edwards
2014-08-11 21:03 ` Rich Freeman
0 siblings, 1 reply; 4+ messages in thread
From: Grant Edwards @ 2014-08-11 20:05 UTC (permalink / raw
To: gentoo-user
I maintain some out-of-tree Linux device drivers that have been around
for yonks and ship with system V init scripts. There's an install
script (or Makefile recipe) that attempts attempts to figure out where
to put an init script and set up symlinks as appropriate.
It's not perfect, but so far it has worked good enough. It doesn't
work great with openrc [e.g. doesn't enable the init script
automatically], but people seem to be able to figure it out.
Now I've got a customer that runs systemd and reports that the init
script "doesn't work" for some undefined value of "doesn't work".
I've pretty much always been a system V init guy and have only
grumblingly adapted to openrc. [Insert crotchety old Unix guy
ramblings here... blah blah version 7... PDP-11 blah DECwriter blah
silent 700 blah blah ASR-33... kids these days... ad naseam.]
Needless to say: I find systemd distasteful, but I've got customers
who use it. So...
I keep reading that systemd is "compatible with system V init
scripts", but documentation on how that works seems to be somewhat
lacking and/or wrong. e.g. The upstream docs refer to using
/sbin/system to run old-style init scripts found in /etc/init.d, but
neither /sbin/system nor the /etc/init.d directory seem to exsit on
the systemd machine that I'm testing with. I'm currently testing with
Arch Linux, but I'm also going to set up a Gentoo/systemd system.
I've also seen recommendations that one would be better off just doing
it the right way and writing a systemd .service file.
Any advice on whether it would be easier to use a common init script
with sysV/OpenRC/systemd or to write a separate .service file?
--
Grant Edwards grant.b.edwards Yow! Where's the Coke
at machine? Tell me a joke!!
gmail.com
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [gentoo-user] sysV/openrc init script vs. systemd .service file
2014-08-11 20:05 [gentoo-user] sysV/openrc init script vs. systemd .service file Grant Edwards
@ 2014-08-11 21:03 ` Rich Freeman
2014-08-11 21:55 ` [gentoo-user] " Grant Edwards
0 siblings, 1 reply; 4+ messages in thread
From: Rich Freeman @ 2014-08-11 21:03 UTC (permalink / raw
To: gentoo-user
On Mon, Aug 11, 2014 at 4:05 PM, Grant Edwards
<grant.b.edwards@gmail.com> wrote:
>
> Any advice on whether it would be easier to use a common init script
> with sysV/OpenRC/systemd or to write a separate .service file?
I'd almost certainly generate a proper unit, and not try to use a
compatibility mode, especially if you're generating these using
software. If anything it would make more sense to make a sysvinit
script which is a wrapper for a systemd unit than the other way
around.
Sysvinit scripts are just that - touring-complete scripts.
Systemd units are declarative.
Here is the Gentoo mysqld unit, which is pretty simple:
[Unit]
Description=MySQL database server
After=syslog.target
After=network.target
[Service]
Type=simple
User=mysql
Group=mysql
# Note: we set --basedir to prevent probes that might trigger SELinux alarms,
# https://bugzilla.redhat.com/show_bug.cgi?id=547485
ExecStart=/usr/bin/mysqld_safe --basedir=/usr
ExecStartPost=/usr/libexec/mysqld-wait-ready $MAINPID
# Give a reasonable amount of time for the server to start up/shut down
TimeoutSec=300
# We rely on systemd, not mysqld_safe, to restart mysqld if it dies
Restart=always
# Place temp files in a secure directory, not /tmp
PrivateTmp=true
[Install]
WantedBy=multi-user.target
Most daemons will be fairly similar to this, though a daemon which
forks will be slightly different (type=forking, and will have a
PIDfile setting). This one is a bit fancy in that it has a post-exec
script/program that just checks for the main service to be ready (so
that reverse dependencies aren't started prematurely).
It is important that whatever is in execstart doesn't die if this is a
daemon. If this is just going to modprobe something and terminate
that is fine, but there is a slightly different way to express those
so that it isn't considered a failure.
Rich
^ permalink raw reply [flat|nested] 4+ messages in thread
* [gentoo-user] Re: sysV/openrc init script vs. systemd .service file
2014-08-11 21:03 ` Rich Freeman
@ 2014-08-11 21:55 ` Grant Edwards
2014-08-12 0:43 ` Rich Freeman
0 siblings, 1 reply; 4+ messages in thread
From: Grant Edwards @ 2014-08-11 21:55 UTC (permalink / raw
To: gentoo-user
On 2014-08-11, Rich Freeman <rich0@gentoo.org> wrote:
> On Mon, Aug 11, 2014 at 4:05 PM, Grant Edwards
><grant.b.edwards@gmail.com> wrote:
>>
>> Any advice on whether it would be easier to use a common init script
>> with sysV/OpenRC/systemd or to write a separate .service file?
>
> I'd almost certainly generate a proper unit, and not try to use a
> compatibility mode, especially if you're generating these using
> software.
It wouldn't be generated by software. Both the sysv init script and
.service file would be maintained by hand.
> If anything it would make more sense to make a sysvinit script which
> is a wrapper for a systemd unit than the other way around.
Thanks, I'll consider that, but I'm reluctant to do so for fear of
breaking compatibility with various ancient systems in use out there.
[I can't even find hardware old enough to run some of the Linux
kernels and distro's some customers are still using.]
[...]
> Most daemons will be fairly similar to this, though a daemon which
> forks will be slightly different (type=forking, and will have a
> PIDfile setting).
The daemon is currently of the traditional forking variety with a PID
file, so it should lend itself to Type=forking PIDFile=/var/run/whatever.pid.
But, there are a number of housekeeping tasks that are performed
before starting the daemon and after terminating the daemon (checking
configuration files, verifying presence of kernel module .ko/.o files,
loading a kernel module and logging some pertinent info from that
module, unloading the kernel module, etc.). It looks like I should
write ExecStartPre and ExecStopPost scripts for systemd to invoke.
One thing I'm still wondering about is the canonical location to
install things like ExecStartPre and ExecStopPost scripts.
I could modify the daemon to provide a "no-fork" option and then exec
it at the end of a startup script, but I don't really see much benefit
to that.
> This one is a bit fancy in that it has a post-exec script/program
> that just checks for the main service to be ready (so that reverse
> dependencies aren't started prematurely).
>
> It is important that whatever is in execstart doesn't die if this is
> a daemon. If this is just going to modprobe something and terminate
> that is fine, but there is a slightly different way to express those
> so that it isn't considered a failure.
Thanks much for the advice.
--
Grant Edwards grant.b.edwards Yow! I am covered with
at pure vegetable oil and I am
gmail.com writing a best seller!
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [gentoo-user] Re: sysV/openrc init script vs. systemd .service file
2014-08-11 21:55 ` [gentoo-user] " Grant Edwards
@ 2014-08-12 0:43 ` Rich Freeman
0 siblings, 0 replies; 4+ messages in thread
From: Rich Freeman @ 2014-08-12 0:43 UTC (permalink / raw
To: gentoo-user
On Mon, Aug 11, 2014 at 5:55 PM, Grant Edwards
<grant.b.edwards@gmail.com> wrote:
>
> Thanks much for the advice.
>
Np. One other thing is that anybody using journald would probably
appreciate logging to stdout.
Forking with a PIDfile is actually a preferred mode of operation,
since then you know it is ready to accept connections.
Making sure the parent doesn't die is especially important if you do
things like timer units (basically a systemd version of cron). I
tended to fork off processes from scripts from cron and you can't do
that with systemd unless the parent waits for all the children to
finish. The better way to do it is just write multiple scripts and
let them start in parallel. When a parent dies, the unit is
considered done, and all its children are meticulously killed off.
Rich
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-08-12 0:43 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-08-11 20:05 [gentoo-user] sysV/openrc init script vs. systemd .service file Grant Edwards
2014-08-11 21:03 ` Rich Freeman
2014-08-11 21:55 ` [gentoo-user] " Grant Edwards
2014-08-12 0:43 ` Rich Freeman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox