2011 12 Seminarios Internos Systemd
2011 12 Seminarios Internos Systemd
2011 12 Seminarios Internos Systemd
PABLO N. HESS
Instructor
Red Hat São Paulo
December 2011
General info & History
Authors: Current default init for:
Lennart Poettering (Red Hat) Fedora
Pulseaudio, Avahi
openSUSE
Kay Sievers (openSUSE)
Mandriva
Udev
double fork()
Daemon process
Reliable dependencies
Parallel service
initialization
Socket-based
Re-parented initialization
daemon stopped
to init
Better-than-shellscript
speeds
Code deduplication/
sanitization
Low first user PIDs
double fork()
Daemon process
Reliable dependencies
Parallel service
initialization
Socket-based
Re-parented initialization
daemon stopped
to init
Better-than-shellscript
speeds
Code deduplication/
sanitization
Low first user PIDs
systemd
Rsyslog as an example Reliable supervisioning
Reliable dependencies
sysvinit script
Parallel service
106 lines initialization
75 lines of code Socket-based
initialization
systemd “unit file”
Better-than-shellscript
11 lines speeds
9 lines of code Code deduplication/
sanitization
Low first user PIDs
Path-based initialization
CUPS as an example Reliable supervisioning
Reliable dependencies
File created in Parallel service
Everything is a unit:
home.automount auto-mounted FS
rsyslog.service regular service
sshd.socket socket definition
cups.path path definition
[Automount]
Where=/home
[Install]
WantedBy=sysinit.target home.mount
[Unit]
Description=My home directory
[Mount]
triggers home.mount #What=UUID=fd6e2ed9-d430-45b3-9...
What=/dev/sdb9
Where=/home
Type=ext4
Options=noatime,discard,nobarrier
man systemd.mount
Unit files example: swap
dev-sda5.swap
[Unit]
Description=Swap on /dev/sda5
man systemd.swap
[Swap]
What=/dev/sda5
Priority=1
TimeoutSec=5
[Install]
WantedBy=swap.target
Unit files example: services
sshd.service
[Unit]
Description=OpenSSH server daemon.
After=syslog.target network.target auditd.service
or
[Service]
Type=simple
ExecStart=/usr/sbin/sshd -D
ExecReload=/bin/kill -HUP $MAINPID
[Install]
WantedBy=multi-user.target
man systemd.service
Unit files example: services
[email protected]
...
[Service]
Environment=TERM=linux
ExecStart=-/sbin/agetty %I 38400
Restart=always
RestartSec=0
or
UtmpIdentifier=%I
TTYPath=/dev/%I
...
man systemd.service
Unit files example: services
sshd.socket
[email protected] [Unit]
Conflicts=sshd.service
[Unit]
Description=SSH Per-Connection [Socket]
Server ListenStream=22
After=syslog.target ListenStream=2200
Accept=yes
[Service]
ExecStart=/usr/sbin/sshd -i [Install]
StandardInput=socket WantedBy=sockets.target
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/libexec/iptables.init start
ExecStop=/usr/libexec/iptables.init stop external scripts!
Environment=BOOTUP=serial
Environment=CONSOLETYPE=serial
StandardOutput=syslog
StandardError=syslog
[Install]
WantedBy=basic.target
Unit files example: services (forking)
dnsmasq.service
[Unit]
Description=DNS caching server.
After=syslog.target network.target
the choice for
[Service]
Type=forking legacy SysV
PIDFile=/var/run/dnsmasq.pid
EnvironmentFile=-/etc/sysconfig/network init scripts
ExecStart=/usr/sbin/dnsmasq -s $HOSTNAME
[Install]
WantedBy=multi-user.target
One dir for the packager
$ ls /lib/systemd/system
abrt-ccpp.service poweroff.service
abrtd.service poweroff.target
abrt-oops.service poweroff.target.wants
abrt-vmcore.service pppoe-server.service
accounts-daemon.service prefdm.service
alsa-restore.service printer.target
alsa-store.service proc-sys-fs-binfmt_misc.automount
[email protected] proc-sys-fs-binfmt_misc.mount
anaconda.target psacct.service
arp-ethers.service quotacheck.service
atd.service quotaon.service
auditd.service rc-local.service
[email protected] rdisc.service
avahi-daemon.service reboot.service
avahi-daemon.socket reboot.target
basic.target reboot.target.wants
basic.target.wants remote-fs.target
bluetooth.service remount-rootfs.service
bluetooth.target rescue.service
canberra-system-bootup.service rescue.target
canberra-system-shutdown-reboot.service restorecond.service
canberra-system-shutdown.service rpcbind.target
chronyd.service rsyslog.service
chrony-wait.service rtkit-daemon.service
One dir for the packager
...and one for the sysadmin
$ ls /lib/systemd/system
abrt-ccpp.service poweroff.service
$ ls /etc/systemd/system
abrtd.service poweroff.target
abrt-oops.service poweroff.target.wants
home.automount
abrt-vmcore.service home.mount
pppoe-server.service
basic.target.wants
accounts-daemon.service graphical.target.wants
prefdm.service
bluetooth.target.wants
alsa-restore.service multi-user.target.wants
printer.target
my-own-target.target.wants
alsa-store.service network.target.wants
proc-sys-fs-binfmt_misc.automount
dbus-org.freedesktop.NetworkManager.service
[email protected] printer.target.wants
proc-sys-fs-binfmt_misc.mount
default.target
anaconda.target sockets.target.wants
psacct.service
default.target.wants
arp-ethers.service sysinit.target.wants
quotacheck.service
getty.target.wants
atd.service quotaon.service
auditd.service rc-local.service
[email protected] rdisc.service
avahi-daemon.service reboot.service
avahi-daemon.socket reboot.target
basic.target reboot.target.wants
basic.target.wants remote-fs.target
bluetooth.service remount-rootfs.service
bluetooth.target rescue.service
canberra-system-bootup.service rescue.target
canberra-system-shutdown-reboot.service restorecond.service
canberra-system-shutdown.service rpcbind.target
chronyd.service rsyslog.service
chrony-wait.service rtkit-daemon.service
Troubleshooting
# systemd-analyze blame
9682ms sshd-keygen.service
4483ms abrtd.service
4382ms plymouth-start.service
4365ms systemd-readahead-replay.service
2268ms sendmail.service
2182ms udev-settle.service
...
16ms rpcbind.service
13ms dnsmasq.service
Benchmarking
# systemd-analyze plot
PABLO N. HESS
Instructor
Red Hat São Paulo
December 2011