Download - Systemd mlug-20140614
![Page 1: Systemd mlug-20140614](https://reader034.vdocument.in/reader034/viewer/2022052600/5577b57bd8b42a1c068b46b1/html5/thumbnails/1.jpg)
Glenn HolmerGlenn Holmer
Milwaukee Linux Users GroupMilwaukee Linux Users GroupJune 14, 2014June 14, 2014
systemd: the new init system for Linuxsystemd: the new init system for Linux
![Page 2: Systemd mlug-20140614](https://reader034.vdocument.in/reader034/viewer/2022052600/5577b57bd8b42a1c068b46b1/html5/thumbnails/2.jpg)
History
![Page 3: Systemd mlug-20140614](https://reader034.vdocument.in/reader034/viewer/2022052600/5577b57bd8b42a1c068b46b1/html5/thumbnails/3.jpg)
init, the father of processes
✔ BIOS loads bootloader from hard drive✔ bootloader loads GRUB✔ GRUB loads kernel✔ kernel mounts filesystems and loads drivers✔ kernel starts first process (init)
![Page 4: Systemd mlug-20140614](https://reader034.vdocument.in/reader034/viewer/2022052600/5577b57bd8b42a1c068b46b1/html5/thumbnails/4.jpg)
sysvinit startup
✔ init looks for default runlevel and runs its scripts to start the appropriate services
✔ each runlevel has a directory /etc/rcN.d/ with start and stop symlinks to scripts in /etc/init.d
![Page 5: Systemd mlug-20140614](https://reader034.vdocument.in/reader034/viewer/2022052600/5577b57bd8b42a1c068b46b1/html5/thumbnails/5.jpg)
init systems
traditional: sysvinit (Linux)alternate: OpenRC (Gentoo), upstart (Ubuntu)other OS: BSD, SMF (Solaris), launchd (Mac)
![Page 6: Systemd mlug-20140614](https://reader034.vdocument.in/reader034/viewer/2022052600/5577b57bd8b42a1c068b46b1/html5/thumbnails/6.jpg)
![Page 7: Systemd mlug-20140614](https://reader034.vdocument.in/reader034/viewer/2022052600/5577b57bd8b42a1c068b46b1/html5/thumbnails/7.jpg)
What's wrong with sysvinit?
synchronouseverything started at boot timecan't control double-forked child processes
![Page 8: Systemd mlug-20140614](https://reader034.vdocument.in/reader034/viewer/2022052600/5577b57bd8b42a1c068b46b1/html5/thumbnails/8.jpg)
What's better about systemd?
asynchronousservices started only when needed (via socket)services run in cgroups
![Page 9: Systemd mlug-20140614](https://reader034.vdocument.in/reader034/viewer/2022052600/5577b57bd8b42a1c068b46b1/html5/thumbnails/9.jpg)
Why is systemd controversial?
“do one thing and do it well” (feature creep)depends on dbus/kdbusLinux-specific (because of cgroups)binary log file (the journal)
http://0pointer.de/blog/projects/the-biggest-myths.html
![Page 10: Systemd mlug-20140614](https://reader034.vdocument.in/reader034/viewer/2022052600/5577b57bd8b42a1c068b46b1/html5/thumbnails/10.jpg)
Why is systemd controversial?
“do one thing and do it well” (feature creep)depends on dbus/kdbusLinux-specific (because of cgroups)binary log file (the journal)
http://0pointer.de/blog/projects/the-biggest-myths.html
personality conflicts...
![Page 11: Systemd mlug-20140614](https://reader034.vdocument.in/reader034/viewer/2022052600/5577b57bd8b42a1c068b46b1/html5/thumbnails/11.jpg)
![Page 12: Systemd mlug-20140614](https://reader034.vdocument.in/reader034/viewer/2022052600/5577b57bd8b42a1c068b46b1/html5/thumbnails/12.jpg)
systemd adoption
Ubuntu: upstart 2006 (native init 2009)Fedora: upstart 2008, systemd 2011RHEL: RHEL 7 (just released) uses systemdSUSE: upstart option 2010, systemd 2011SLES: SLES 12 (Q3) will use systemdDebian: systemd 2014, Ubuntu will follow
![Page 13: Systemd mlug-20140614](https://reader034.vdocument.in/reader034/viewer/2022052600/5577b57bd8b42a1c068b46b1/html5/thumbnails/13.jpg)
Mechanics
![Page 14: Systemd mlug-20140614](https://reader034.vdocument.in/reader034/viewer/2022052600/5577b57bd8b42a1c068b46b1/html5/thumbnails/14.jpg)
Why is sysvinit synchronous?
services wait for their dependencies(which open a socket when ready)
![Page 15: Systemd mlug-20140614](https://reader034.vdocument.in/reader034/viewer/2022052600/5577b57bd8b42a1c068b46b1/html5/thumbnails/15.jpg)
Why not open the socket on startup?
services with dependencies can start at oncesocket buffer holds messages until ready
![Page 16: Systemd mlug-20140614](https://reader034.vdocument.in/reader034/viewer/2022052600/5577b57bd8b42a1c068b46b1/html5/thumbnails/16.jpg)
Why is sysvinit slow?
shell scripts! (shell loaded over and over)multiple invocations of grep, awk, sed...
![Page 17: Systemd mlug-20140614](https://reader034.vdocument.in/reader034/viewer/2022052600/5577b57bd8b42a1c068b46b1/html5/thumbnails/17.jpg)
Why not use configuration files?
in /usr/lib/systemd/systemlocals, overrides in /etc/systemd/system
![Page 18: Systemd mlug-20140614](https://reader034.vdocument.in/reader034/viewer/2022052600/5577b57bd8b42a1c068b46b1/html5/thumbnails/18.jpg)
[Unit]Description=PostgreSQL database serverAfter=network.target
[Service]Type=forkingUser=postgresGroup=postgresEnvironment=PGPORT=5432Environment=PGDATA=/var/lib/pgsql/dataOOMScoreAdjust=-1000ExecStartPre=/usr/bin/postgresql-check-db-dir ${PGDATA}ExecStart=/usr/bin/pg_ctl start -D ${PGDATA} -s -o "-p ${PGPORT}" -w -t 300ExecStop=/usr/bin/pg_ctl stop -D ${PGDATA} -s -m fastExecReload=/usr/bin/pg_ctl reload -D ${PGDATA} -sTimeoutSec=300
[Install]WantedBy=multi-user.target
![Page 19: Systemd mlug-20140614](https://reader034.vdocument.in/reader034/viewer/2022052600/5577b57bd8b42a1c068b46b1/html5/thumbnails/19.jpg)
some systemd unit types:
service: traditional daemon (ssh, http, kdm...)socket: listener socket for service activationtarget: like a runlevel, but not exclusive
![Page 20: Systemd mlug-20140614](https://reader034.vdocument.in/reader034/viewer/2022052600/5577b57bd8b42a1c068b46b1/html5/thumbnails/20.jpg)
no /etc/inittab:
/etc/systemd/system/default.target
is a symlink to e.g.
/lib/systemd/system/graphical.target
![Page 21: Systemd mlug-20140614](https://reader034.vdocument.in/reader034/viewer/2022052600/5577b57bd8b42a1c068b46b1/html5/thumbnails/21.jpg)
some distros use symlinks:
runlevel0.target -> poweroff.targetrunlevel1.target -> rescue.targetrunlevel2.target -> multi-user.targetrunlevel3.target -> multi-user.targetrunlevel4.target -> multi-user.targetrunlevel5.target -> graphical.targetrunlevel6.target -> reboot.target
![Page 22: Systemd mlug-20140614](https://reader034.vdocument.in/reader034/viewer/2022052600/5577b57bd8b42a1c068b46b1/html5/thumbnails/22.jpg)
more unit types:
slice: resource control via cgroups(can control CPU share, memory usage, IO bandwidth,device access)
snapshot: saves current runtime state,can return to it with isolate(lost on reboot)
![Page 23: Systemd mlug-20140614](https://reader034.vdocument.in/reader034/viewer/2022052600/5577b57bd8b42a1c068b46b1/html5/thumbnails/23.jpg)
more unit types:
device: when device is ready (udev)mount: (/etc/fstab still preferred)automount: (requires matching mount unit)swap: swap spacepath: unit activation on path changetimer: event based on boot time,
time since a unit's activation,calendar time
![Page 24: Systemd mlug-20140614](https://reader034.vdocument.in/reader034/viewer/2022052600/5577b57bd8b42a1c068b46b1/html5/thumbnails/24.jpg)
sysvinit compatibility
“virtual” service units created in-memorylook for LSB: or SYSV: in the output of systemd list-units
service,chkconfig,telinit... still work
for more information:freedesktop.org/wiki/Software/systemd/Incompatibilities/
![Page 25: Systemd mlug-20140614](https://reader034.vdocument.in/reader034/viewer/2022052600/5577b57bd8b42a1c068b46b1/html5/thumbnails/25.jpg)
Usage
![Page 26: Systemd mlug-20140614](https://reader034.vdocument.in/reader034/viewer/2022052600/5577b57bd8b42a1c068b46b1/html5/thumbnails/26.jpg)
GUI front-end for systemd:
systemadm
On Fedora 20 and OpenSUSE 13.1, installsystemd-ui package.
Good for exploring and learning systemd.
![Page 27: Systemd mlug-20140614](https://reader034.vdocument.in/reader034/viewer/2022052600/5577b57bd8b42a1c068b46b1/html5/thumbnails/27.jpg)
![Page 28: Systemd mlug-20140614](https://reader034.vdocument.in/reader034/viewer/2022052600/5577b57bd8b42a1c068b46b1/html5/thumbnails/28.jpg)
Most frequently-used commands:
systemctljournalctl
Completion prompting and color coding!
![Page 29: Systemd mlug-20140614](https://reader034.vdocument.in/reader034/viewer/2022052600/5577b57bd8b42a1c068b46b1/html5/thumbnails/29.jpg)
systemctl [list-units]systemctl list-unit-filessystemctl -t servicesystemctl –-state failedsystemctl enable <servicename>systemctl start <servicename>systemctl status <servicename>systemctl daemon-reloadsystemctl halt
![Page 30: Systemd mlug-20140614](https://reader034.vdocument.in/reader034/viewer/2022052600/5577b57bd8b42a1c068b46b1/html5/thumbnails/30.jpg)
journalctl -f (follow, like tail -f)journalctl -x (show extra)journalctl -n99 (last 99 entries)journalctl -b (since boot)journalctl -b -1 (since previous boot)journalctl --since (since date/time)journalctl -p err (by priority)journalctl -u (by unit)journalctl /usr/... (by executable)journalctl /dev/... (by device)
![Page 31: Systemd mlug-20140614](https://reader034.vdocument.in/reader034/viewer/2022052600/5577b57bd8b42a1c068b46b1/html5/thumbnails/31.jpg)
switch “runlevel”:systemctl isolate <target-name>
emergency boot: start kernel withsystemd.unit=<target-name>
![Page 32: Systemd mlug-20140614](https://reader034.vdocument.in/reader034/viewer/2022052600/5577b57bd8b42a1c068b46b1/html5/thumbnails/32.jpg)
systemd diagnostics:
systemd-cgls (“control group ls”)systemd-cgtop (“control group top”)
systemd-analyzesystemd-analyze blamesystemd-analyze plot > filename.svgsystemd-analyze dot | \ dot -Tsvg > systemd.svg
![Page 33: Systemd mlug-20140614](https://reader034.vdocument.in/reader034/viewer/2022052600/5577b57bd8b42a1c068b46b1/html5/thumbnails/33.jpg)
![Page 34: Systemd mlug-20140614](https://reader034.vdocument.in/reader034/viewer/2022052600/5577b57bd8b42a1c068b46b1/html5/thumbnails/34.jpg)
Example
![Page 35: Systemd mlug-20140614](https://reader034.vdocument.in/reader034/viewer/2022052600/5577b57bd8b42a1c068b46b1/html5/thumbnails/35.jpg)
![Page 36: Systemd mlug-20140614](https://reader034.vdocument.in/reader034/viewer/2022052600/5577b57bd8b42a1c068b46b1/html5/thumbnails/36.jpg)
![Page 37: Systemd mlug-20140614](https://reader034.vdocument.in/reader034/viewer/2022052600/5577b57bd8b42a1c068b46b1/html5/thumbnails/37.jpg)
![Page 38: Systemd mlug-20140614](https://reader034.vdocument.in/reader034/viewer/2022052600/5577b57bd8b42a1c068b46b1/html5/thumbnails/38.jpg)
![Page 39: Systemd mlug-20140614](https://reader034.vdocument.in/reader034/viewer/2022052600/5577b57bd8b42a1c068b46b1/html5/thumbnails/39.jpg)
![Page 40: Systemd mlug-20140614](https://reader034.vdocument.in/reader034/viewer/2022052600/5577b57bd8b42a1c068b46b1/html5/thumbnails/40.jpg)
![Page 41: Systemd mlug-20140614](https://reader034.vdocument.in/reader034/viewer/2022052600/5577b57bd8b42a1c068b46b1/html5/thumbnails/41.jpg)
![Page 42: Systemd mlug-20140614](https://reader034.vdocument.in/reader034/viewer/2022052600/5577b57bd8b42a1c068b46b1/html5/thumbnails/42.jpg)
resources:
overview:http://www.freedesktop.org/wiki/Software/systemd/
“Demystifying systemd” slides:http://bit.ly/1jm87CJ
“Getting Ready for Systemd” video:https://access.redhat.com/site/videos/403833