Gentoo Archives: gentoo-user

From: Rich Freeman <rich0@g.o>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] sysV/openrc init script vs. systemd .service file
Date: Mon, 11 Aug 2014 21:03:06
Message-Id: CAGfcS_ksGkCv4bg7PX7kJb6_GgHPGN0ecCS+RmSVk30DxgqvxQ@mail.gmail.com
In Reply to: [gentoo-user] sysV/openrc init script vs. systemd .service file by Grant Edwards
1 On Mon, Aug 11, 2014 at 4:05 PM, Grant Edwards
2 <grant.b.edwards@×××××.com> wrote:
3 >
4 > Any advice on whether it would be easier to use a common init script
5 > with sysV/OpenRC/systemd or to write a separate .service file?
6
7 I'd almost certainly generate a proper unit, and not try to use a
8 compatibility mode, especially if you're generating these using
9 software. If anything it would make more sense to make a sysvinit
10 script which is a wrapper for a systemd unit than the other way
11 around.
12
13 Sysvinit scripts are just that - touring-complete scripts.
14
15 Systemd units are declarative.
16
17 Here is the Gentoo mysqld unit, which is pretty simple:
18
19 [Unit]
20 Description=MySQL database server
21 After=syslog.target
22 After=network.target
23
24 [Service]
25 Type=simple
26 User=mysql
27 Group=mysql
28
29 # Note: we set --basedir to prevent probes that might trigger SELinux alarms,
30 # https://bugzilla.redhat.com/show_bug.cgi?id=547485
31 ExecStart=/usr/bin/mysqld_safe --basedir=/usr
32 ExecStartPost=/usr/libexec/mysqld-wait-ready $MAINPID
33
34 # Give a reasonable amount of time for the server to start up/shut down
35 TimeoutSec=300
36
37 # We rely on systemd, not mysqld_safe, to restart mysqld if it dies
38 Restart=always
39
40 # Place temp files in a secure directory, not /tmp
41 PrivateTmp=true
42
43 [Install]
44 WantedBy=multi-user.target
45
46 Most daemons will be fairly similar to this, though a daemon which
47 forks will be slightly different (type=forking, and will have a
48 PIDfile setting). This one is a bit fancy in that it has a post-exec
49 script/program that just checks for the main service to be ready (so
50 that reverse dependencies aren't started prematurely).
51
52 It is important that whatever is in execstart doesn't die if this is a
53 daemon. If this is just going to modprobe something and terminate
54 that is fine, but there is a slightly different way to express those
55 so that it isn't considered a failure.
56
57 Rich

Replies

Subject Author
[gentoo-user] Re: sysV/openrc init script vs. systemd .service file Grant Edwards <grant.b.edwards@×××××.com>