systemd

N
systemd
Lucas Nussbaum
lucas.nussbaum@univ-lorraine.fr
Licence professionnelle ASRALL
Administration de systèmes, réseaux et applications à base de logiciels libres
License: GNU General Public License version 3 or later
or Creative Commons BY-SA 3.0 Unported
(see README.md)
Lucas Nussbaum systemd 1 / 40
Outline
1 Introduction
2 Behind the scenes: cgroups
3 Managing services
4 Analyzing startup performance
5 Exploring the system status
6 Configuring services by writing unit files
7 Timer units
8 Socket activation
9 Logging with journald
10 Containers integration
11 Networking with systemd-networkd
12 Migration from sysvinit
13 Conclusions
Lucas Nussbaum systemd 2 / 40
Init system
First process started by the kernel (pid 1)
Responsible for bringing up the rest of userspace
Mounting filesystems
Starting services
. . .
Also the parent for orphan processes
Traditional init system on Linux: sysVinit
Inherited from Unix System V
With additional tools (insserv, startpar) to handle
dependencies and parallel initialization
Lucas Nussbaum systemd 3 / 40
systemd
Written (since 2010) by Lennart Poettering (Red Hat) and others
Now the default on most Linux distributions
Shifts the scope from starting all services (sysVinit) to
managing the system and all services
Key features:
Relies on cgroups for
Services supervision
Control of services execution environment
Declarative syntax for unit files more efficient/robust
Socket activation for parallel services startup
Nicer user interface (systemctl & friends)
Additional features: logging, timer units (cron-like), user sessions
handling, containers management
Lucas Nussbaum systemd 4 / 40
Behind the scenes: cgroups
Abbreviated from control groups
Linux kernel feature
Limit, account for and isolate processes and their resource usage
(CPU, memory, disk I/O, network, etc.)
Related to namespace isolation:
Isolate processes from the rest of the system
Chroots on steroids
PID, network, UTS, mount, user, etc.
LXC, Docker ≈ cgroups + namespaces (+ management tools)
Lucas Nussbaum systemd 5 / 40
cgroups and systemd
Each service runs in its own cgroup
Enables:
Tracking and killing all processes created by each service
Per-service accounting and resources allocation/limitation
Previously, with sysVinit:
No tracking of which service started which processes
PID files, or hacks in init scripts: pidof / killall / pgrep
Hard to completely terminate a service (left-over CGI
scripts when killing Apache)
No resources limitation (or using setrlimit (= ulimit), which
is per-process, not per-service)
Also isolate user sessions kill all user processes (not by default)
More information: Control Groups vs. Control Groups and
Which Service Owns Which Processes?
Lucas Nussbaum systemd 6 / 40
systemd-cgls: visualizing the cgroups hierarchy
Lucas Nussbaum systemd 7 / 40
systemd-cgtop: per-service resources usage
Requires enabling CPUAccounting, BlockIOAccounting,
MemoryAccounting
Lucas Nussbaum systemd 8 / 40
Managing services with systemctl
What is being manipulated is called a unit: services (.service),
mount points (.mount), devices (.device), sockets (.socket), etc.
Basic commands:
sysVinit systemd notes
service foo start systemctl start foo
service foo stop systemctl stop foo
service foo restart systemctl restart foo
service foo reload systemctl reload foo
service foo condrestart systemctl condrestart foo restart if already running
update-rc.d foo enable systemctl enable foo auto-start at next boot
update-rc.d foo disable systemctl disable foo disable auto-start
systemctl is-enabled foo
There’s auto-completion (apache2 and apache2.service work)
Several services can be specified:
systemctl restart apache2 postgresql
Lucas Nussbaum systemd 9 / 40
systemd and runlevels
With sysVinit, runlevels control which services are started
automatically
0 = halt; 1 = single-user / minimal mode; 6 = reboot
Debian: no difference by default between levels 2, 3, 4, 5
RHEL: 3 = multi-user text, 5 = multi-user graphical
systemd replaces runlevels with targets:
Configured using symlinks farms in
/etc/systemd/system/target.wants/
systemctl enable/disable manipule those symlinks
systemctl mask disables the service and prevents it from
being started manually
The default target can be configured with
systemctl get-default/set-default
More information: The Three Levels of "Off"
Lucas Nussbaum systemd 10 / 40
Default targets (bootup(7))
local -fs-pre.target
|
v
(various mounts and (various swap (various cryptsetup
fsck services ...) devices ...) devices ...) (various low -level (various low -level
| | | services: udevd , API VFS mounts:
v v v tmpfiles , random mqueue , configfs ,
local -fs.target swap.target cryptsetup.target seed , sysctl , ...) debugfs , ...)
| | | | |
__________________|_________________ | ___________________|____________________/
|/
v
sysinit.target
|
____________________________________ /| ________________________________________
/ | | | 
| | | | |
v v | v v
(various (various | (various rescue.service
timers ...) paths ...) | sockets ...) |
| | | | v
v v | v rescue.target
timers.target paths.target | sockets.target
| | | |
__________________|_________________ | ___________________/
|/
v
basic.target
|
____________________________________ /| emergency.service
/ | | |
| | | v
v v v emergency.target
display - (various system (various system
manager.service services services)
| required for |
| graphical UIs) v
| | multi-user.target
| | |
_________________ | _________________/
|/
v
graphical.target
Lucas Nussbaum systemd 11 / 40
Analyzing startup performance
Fast boot matters in some use-cases:
Virtualization, Cloud:
Almost no BIOS / hardware checks only software
startup
Requirement for infrastructure elasticity
Embedded world
systemd-analyze time: summary
Startup finished in 4.883s (kernel) + 5.229s (userspace) = 10.112s
systemd-analyze blame: worst offenders
2.417s systemd -udev -settle.service
2.386s postgresql@9 .4-main.service
1.507s apache2.service
240ms NetworkManager.service
236ms ModemManager.service
194ms accounts -daemon.service
Lucas Nussbaum systemd 12 / 40
systemd-analyze plot
Similar to bootchartd, but does not require rebooting with a
custom init= kernel command-line
Lucas Nussbaum systemd 13 / 40
systemd-analyze critical-chain
Shows services in the critical path
Lucas Nussbaum systemd 14 / 40
Exploring the system status
Listing units with systemctl list-units (or just systemctl):
active units: systemctl
List only services: systemctl -t service
List units in failed state: systemctl --failed
Whole system overview: systemctl status
GUI available: systemadm
Lucas Nussbaum systemd 15 / 40
systemctl status service
Includes:
Service name and description, state, PID
Free-form status line from systemd-notify(1) or sd_notify(3)
Processes tree inside the cgroup
Last lines from journald (syslog messages and stdout/stderr)
Lucas Nussbaum systemd 16 / 40
Configuring services by writing unit files
With sysVinit: shell scripts in /etc/init.d/
Long and difficult to write
Redundant code between services
Slow (numerous fork() calls)
With systemd: declarative syntax (.desktop-like)
Move intelligence from scripts to systemd
Covers most of the needs, but shell scripts can still be used
Can use includes and overrides (systemd-delta)
View config file for a unit: systemctl cat atd.service
Or just find the file under /lib/systemd/system/ (distribution’s
defaults) or /etc/systemd/system (local overrides)
Lucas Nussbaum systemd 17 / 40
Simple example: atd
[Unit]
Description=Deferred execution scheduler
# Pointer to documentation shown in systemctl status
Documentation=man:atd(8)
[Service]
# Command to start the service
ExecStart =/usr/sbin/atd -f
IgnoreSIGPIPE=false # Default is true
[Install]
# Where "systemctl enable" creates the symlink
WantedBy=multi -user.target
Lucas Nussbaum systemd 18 / 40
Common options
Documented in systemd.unit(5) ([Unit]), systemd.service(5)
([Service]), systemd.exec(5) (execution environment)
Show all options for a given service:
systemctl show atd
Sourcing a configuration file:
EnvironmentFile=-/etc/default/ssh
ExecStart=/usr/sbin/sshd -D $SSHD_OPTS
Using the $MAINPID magic variable:
ExecReload=/bin/kill -HUP $MAINPID
Auto-restart a service when crashed: (≈ runit / monit)
Restart=on-failure
Conditional start:
ConditionPathExists=!/etc/ssh/sshd_not_to_be_run
Conditions on architecture, virtualization, kernel cmdline, AC power, etc.
Lucas Nussbaum systemd 19 / 40
Options for isolation and security
Use a network namespace to isolate the service from the network:
PrivateNetwork=yes
Use a filesystem namespaces:
To provide a service-specific /tmp directory:
PrivateTmp=yes
To make some directories inaccessible or read-only:
InaccessibleDirectories=/home
ReadOnlyDirectories=/var
Specify the list of capabilities(7) for a service:
CapabilityBoundingSet=CAP_CHOWN CAP_KILL
Or just remove one:
CapabilityBoundingSet=~CAP_SYS_PTRACE
Disallow forking:
LimitNPROC=1
Lucas Nussbaum systemd 20 / 40
Options for isolation and security (2)
Run as user/group: User=, Group=
Run service inside a chroot:
RootDirectory=/srv/chroot/foobar
ExecStartPre=/usr/local/bin/setup-foobar-chroot.sh
ExecStart=/usr/bin/foobard
RootDirectoryStartOnly=yes
Control CPU shares, memory limits, block I/O, swapiness:
CPUShares=1500
MemoryLimit=1G
BlockIOWeight=500
BlockIOReadBandwith=/var/log 5M
ControlGroupAttribute=memory.swappiness 70
More information: Converting sysV init scripts to systemd service
files, Securing your services, Changing roots, Managing
resources
Lucas Nussbaum systemd 21 / 40
Timer units
Similar to cron, but with all the power of systemd (dependencies,
execution environment configuration, etc)
Realtime (wallclock) timers: calendar event expressions
Expressed using a complex format (see systemd.time(7)),
matching timestamps like: Fri 2012-11-23 11:12:13
Examples of valid values: hourly (= *-*-* *:00:00), daily (=
*-*-* 00:00:00), *:2/3 (= *-*-* *:02/3:00)
Monotonic timers, relative to different starting points:
5 hours and 30 mins after system boot: OnBootSec=5h 30m
50s after systemd startup: OnstartupSec=50s
1 hour after the unit was last activated: OnUnitActiveSec=1h
(can be combined with OnBootSec or OnStartupSec to ensure
that a unit runs on a regular basis)
Lucas Nussbaum systemd 22 / 40
Timer units example
myscript.service:
[Unit]
Description=MyScript
[Service]
Type=simple
ExecStart =/usr/local/bin/myscript
myscript.timer:
[Unit]
Description=Runs myscript every hour
[Timer]
# Time to wait after booting before we run first time
OnBootSec =10min
# Time between running each consecutive time
OnUnitActiveSec =1h
Unit=myscript.service
[Install]
WantedBy=multi -user.target
Lucas Nussbaum systemd 23 / 40
Timer units example (2)
Start timer:
systemctl start myscript.timer
Enable timer to start at boot:
systemctl enable myscript.timer
List all timers:
systemctl list-timers
Lucas Nussbaum systemd 24 / 40
Socket activation
systemd listens for connection on behalf of service until the
service is ready, then passes pending connections
Benefits:
No need to express ordering of services during boot:
They can all be started in parallel faster boot
And they will wait for each other when needed (when
they will talk to each other), thanks to socket activation
Services that are seldomly used do not need to keep running,
and can be started on-demand
Not limited to network services: also D-Bus activation and path
activation
More information: Converting inetd Service, Socket Activation for
developers (+ follow-up)
Lucas Nussbaum systemd 25 / 40
Socket activation example: dovecot
dovecot.socket:
[Unit]
Description=Dovecot IMAP/POP3 
email server activation socket
[Socket]
# dovecot expects separate
# IPv4 and IPv6 sockets
BindIPv6Only=ipv6 -only
ListenStream =0.0.0.0:143
ListenStream =[::]:143
ListenStream =0.0.0.0:993
ListenStream =[::]:993
KeepAlive=true
[Install]
WantedBy=sockets.target
dovecot.service:
[Unit]
Description=Dovecot IMAP/POP3 
email server
After=local -fs.target network.target
[Service]
Type=simple
ExecStart =/usr/sbin/dovecot -F
NonBlocking=yes
[Install]
WantedBy=multi -user.target
Lucas Nussbaum systemd 26 / 40
Socket activation example: sshd
sshd.socket:
[Unit]
Description=SSH Socket for Per -Connection Servers
[Socket]
ListenStream =22
Accept=yes
[Install]
WantedBy=sockets.target
sshd@.service:
[Unit]
Description=SSH Per -Connection Server
[Service]
ExecStart=-/usr/sbin/sshd -i
StandardInput=socket
Lucas Nussbaum systemd 27 / 40
Socket activation example: sshd (2)
sshd@.service means that this is an instantiated service
There’s one instance of sshd@.service per connection:
# systemctl --full | grep ssh
sshd@172 .31.0.52:22 -172.31.0.4:47779. service loaded active running
sshd@172 .31.0.52:22 -172.31.0.54:52985. service loaded active running
sshd.socket loaded active listening
Instanciated services are also used by getty
See Serial console and Instanciated services
Lucas Nussbaum systemd 28 / 40
Logging with journald
Component of systemd
Captures syslog messages, kernel log messages, initrd and early
boot messages, messages written to stdout/stderr by all services
Forwards everything to syslog
Structured format (key/value fields), can contain arbitrary data
But viewable as syslog-like format with journalctl
Indexed, binary logs; rotation handled transparently
Can replace syslog (but can also work in parallel)
Not persistent across reboots by default – to make it persistent,
create the /var/log/journal directory, preferably with:
install -d -g systemd-journal /var/log/journal
setfacl -R -nm g:adm:rx,d:g:adm:rx /var/log/journal
Can log to a remote host (with systemd-journal-gateway, not in
Debian yet)
Lucas Nussbaum systemd 29 / 40
Example journal entry
_SERVICE=systemd -logind.service
MESSAGE=User harald logged in
MESSAGE_ID =422 bc3d271414bc8bc9570f222f24a9
_EXE=/lib/systemd/systemd -logind
_COMM=systemd -logind
_CMDLINE =/lib/systemd/systemd -logind
_PID =4711
_UID=0
_GID=0
_SYSTEMD_CGROUP =/ system/systemd -logind.service
_CGROUPS=cpu:/ system/systemd -logind.service
PRIORITY =6
_BOOT_ID =422 bc3d271414bc8bc95870f222f24a9
_MACHINE_ID=c686f3b205dd48e0b43ceb6eda479721
_HOSTNAME=waldi
LOGIN_USER =500
Lucas Nussbaum systemd 30 / 40
Using journalctl
View the full log: journalctl
Since last boot: journalctl -b
For a given time interval: journalctl --since=yesterday
or journalctl --until="2013-03-15 13:10:30"
View it in the verbose (native) format: journalctl -o verbose
Filter by systemd unit: journalctl -u ssh
Filter by field from the verbose format:
journalctl _SYSTEMD_UNIT=ssh.service
journalctl _PID=810
Line view (≈ tail -f): journalctl -f
Last entries (≈ tail): journalctl -n
Works with bash-completion
See also: Journald design document, Using the Journal
Lucas Nussbaum systemd 31 / 40
Containers integration
General philosophy: integrate management of services from
machines (VMs and containers) with those of the host
systemd-machined: tracks machines, provides an API to list,
create, register, kill, terminate machines, transfer images (tar,
raw, Docker)
machinectl: command-line utility to manipulate machines
other tools also have containers support:
systemctl -M mycontainer restart foo
systemctl list-machines: provides state of containers
journalctl -M mycontainer
journalctl -m: combined log of all containers
systemd has its own mini container manager: systemd-nspawn
Other virtualization solutions can also talk to machined
More information: Container integration
Lucas Nussbaum systemd 32 / 40
Networking with systemd-networkd
Replacement for /etc/network/interfaces, on servers and VMs
Not really for Network Manager on desktops and laptops
Supports setting IP configuration, configuring bridges, vlans,
bonding, tunnels, etc
Configuration files with a [Match] section to match on MAC
address, driver, udev path, type, hostname, etc
foo.link: link-level configuration – MAC address, interface
name, MTU, rate, Duplex mode, Wake on Lan
foo.netdev: creation of virtual network devices (bridges,
bonds, vlans, IPIP or GRE tunnels, VXLAN, tun, tap, veth)
foo.network: network devices configuration: IP (static or
DHCP, gateway, additional routes, DNS), addition to bridge
More information: systemd-networkd(8), systemd.link(5),
systemd.network(5), systemd.netdev(5)
Lucas Nussbaum systemd 33 / 40
Example 1: DHCP, additional route
For higher performance, systemd includes a DHCP client
# /etc/systemd/network/ethernet.network
[Match]
Name=eth0
[Network]
DHCP=yes
[Route]
Gateway =192.168.1.253
Destination =10.0.0.0/8
Lucas Nussbaum systemd 34 / 40
Example 2: static addressing and VLAN
# /etc/systemd/network/vlan1.netdev
# [Match] section is optional in netdev files
[NetDev]
Name=vlan1
Kind=vlan
[VLAN]
Id=1
# /etc/systemd/network/ethernet.network
[Match]
Name=eth0
[Network]
DHCP=yes
VLAN=vlan1 # will create vlan1 on this device
# /etc/systemd/network/vlan1.network
[Match]
Name=vlan1
[Network]
Address =192.168.1.1/24
Gateway =192.168.1.254
Lucas Nussbaum systemd 35 / 40
Example 3: bridge and tap
# /etc/systemd/network/bridge0.netdev
[NetDev]
Name=bridge0
Kind=bridge
# /etc/systemd/network/bridge0.network
[Match]
Name=bridge0
[Network]
Address =192.168.1.1/24
DHCPServer=yes # systemd has its own , very basic , DHCP server
# /etc/systemd/network/tap.netdev
[NetDev]
Name=tap0
Kind=tap
# /etc/systemd/network/tap.network
[Match]
Name=bridge0
[NetDev]
Bridge=bridge0
Lucas Nussbaum systemd 36 / 40
Migration from sysvinit
systemd hooks into LSB init scripts: service foo start|stop|...
and /etc/init.d/foo redirect to systemctl
systemd-sysv-generator creates wrapper units for LSB scripts:
Using LSB dependencies
Services are described as LSB: foo
List all generated services:
systemctl list-units | grep LSB:
Lucas Nussbaum systemd 37 / 40
Generated wrapper service file for apache2
$ systemctl cat apache2.service
# /run/systemd/generator.late/apache2.service
# Automatically generated by systemd -sysv -generator
[Unit]
Description=LSB: Apache2 web server
Before=runlevel2.target runlevel3.target runlevel4.target
runlevel5.target shutdown.target
After=local -fs.target remote -fs.target network -online.target
systemd -journald -dev -log.socket nss -lookup.target
Wants=network -online.target
Conflicts=shutdown.target
[Service]
Type=forking
KillMode=process
[...]
ExecStart=/etc/init.d/apache2 start
ExecStop=/etc/init.d/apache2 stop
ExecReload=/etc/init.d/apache2 reload
Lucas Nussbaum systemd 38 / 40
More stuff
New cross-distro configuration files: /etc/hostname,
/etc/locale.conf, /etc/sysctl.d/*.conf,
/etc/tmpfiles.d/*.conf
Tools to manage hostname, locale, time and date: hostnamectl,
localectl, timedatectl
Support for watchdogs
Handling of user sessions
Each within its own cgroup
Multi-seat support
loginctl to manage sessions, users, seats
Lucas Nussbaum systemd 39 / 40
Conclusions
systemd revisits the way we manage Linux systems
If we redesigned services management from scratch, would it
look like systemd?
For service developers: easier to support systemd than sysVinit
No need to fork, to drop privileges, to write a pid file
Just output logs to stdout (redirected to syslog, with priorities)
Some parts still have rough edges, or are still moving targets, but
are promising: journal, containers, networking
systemd might not be the final answer, but at least it’s an
interesting data point to look at
Lucas Nussbaum systemd 40 / 40
1 of 40

Recommended

Systemd: the modern Linux init system you will learn to love by
Systemd: the modern Linux init system you will learn to loveSystemd: the modern Linux init system you will learn to love
Systemd: the modern Linux init system you will learn to loveAlison Chaiken
3.1K views50 slides
SystemV vs systemd by
SystemV vs systemdSystemV vs systemd
SystemV vs systemdAll Things Open
15K views60 slides
Introduction to Linux Kernel by Quontra Solutions by
Introduction to Linux Kernel by Quontra SolutionsIntroduction to Linux Kernel by Quontra Solutions
Introduction to Linux Kernel by Quontra SolutionsQUONTRASOLUTIONS
1.5K views50 slides
Introduction to char device driver by
Introduction to char device driverIntroduction to char device driver
Introduction to char device driverVandana Salve
15.8K views29 slides
Embedded Linux on ARM by
Embedded Linux on ARMEmbedded Linux on ARM
Embedded Linux on ARMEmertxe Information Technologies Pvt Ltd
10.5K views235 slides

More Related Content

What's hot

Linux kernel architecture by
Linux kernel architectureLinux kernel architecture
Linux kernel architectureSHAJANA BASHEER
4.3K views32 slides
Linux file system by
Linux file systemLinux file system
Linux file systemMd. Tanvir Hossain
9.5K views23 slides
Git undo by
Git undoGit undo
Git undoAvilay Parekh
1K views37 slides
Linux Crash Dump Capture and Analysis by
Linux Crash Dump Capture and AnalysisLinux Crash Dump Capture and Analysis
Linux Crash Dump Capture and AnalysisPaul V. Novarese
14.6K views67 slides
Linux Internals - Kernel/Core by
Linux Internals - Kernel/CoreLinux Internals - Kernel/Core
Linux Internals - Kernel/CoreShay Cohen
1.4K views35 slides
Basic Linux Internals by
Basic Linux InternalsBasic Linux Internals
Basic Linux Internalsmukul bhardwaj
41.3K views333 slides

What's hot(20)

Linux Crash Dump Capture and Analysis by Paul V. Novarese
Linux Crash Dump Capture and AnalysisLinux Crash Dump Capture and Analysis
Linux Crash Dump Capture and Analysis
Paul V. Novarese14.6K views
Linux Internals - Kernel/Core by Shay Cohen
Linux Internals - Kernel/CoreLinux Internals - Kernel/Core
Linux Internals - Kernel/Core
Shay Cohen1.4K views
Linux Networking Explained by Thomas Graf
Linux Networking ExplainedLinux Networking Explained
Linux Networking Explained
Thomas Graf25.6K views
Understanding the Android System Server by Opersys inc.
Understanding the Android System ServerUnderstanding the Android System Server
Understanding the Android System Server
Opersys inc.53.5K views
Introduction to systemd by Yusaku OGAWA
Introduction to systemdIntroduction to systemd
Introduction to systemd
Yusaku OGAWA4.3K views
linux device driver by Rahul Batra
linux device driverlinux device driver
linux device driver
Rahul Batra11.4K views
Linux Kernel Booting Process (1) - For NLKB by shimosawa
Linux Kernel Booting Process (1) - For NLKBLinux Kernel Booting Process (1) - For NLKB
Linux Kernel Booting Process (1) - For NLKB
shimosawa12.5K views
Yocto - Embedded Linux Distribution Maker by Sherif Mousa
Yocto - Embedded Linux Distribution MakerYocto - Embedded Linux Distribution Maker
Yocto - Embedded Linux Distribution Maker
Sherif Mousa4.3K views
Kernel Recipes 2017 - Understanding the Linux kernel via ftrace - Steven Rostedt by Anne Nicolas
Kernel Recipes 2017 - Understanding the Linux kernel via ftrace - Steven RostedtKernel Recipes 2017 - Understanding the Linux kernel via ftrace - Steven Rostedt
Kernel Recipes 2017 - Understanding the Linux kernel via ftrace - Steven Rostedt
Anne Nicolas5.6K views

Similar to systemd

Systemd mlug-20140614 by
Systemd mlug-20140614Systemd mlug-20140614
Systemd mlug-20140614Susant Sahani
1.3K views42 slides
Sistemas operacionais 8 by
Sistemas operacionais 8Sistemas operacionais 8
Sistemas operacionais 8Nauber Gois
167 views88 slides
Linux lecture6 by
Linux lecture6Linux lecture6
Linux lecture6Haider Adnan
848 views15 slides
Summit demystifying systemd1 by
Summit demystifying systemd1Summit demystifying systemd1
Summit demystifying systemd1Susant Sahani
748 views68 slides
Linux Du Jour by
Linux Du JourLinux Du Jour
Linux Du Jourmwedgwood
680 views49 slides
Linux Booting Process by
Linux Booting ProcessLinux Booting Process
Linux Booting ProcessRishabh5121993
410 views48 slides

Similar to systemd(20)

Systemd mlug-20140614 by Susant Sahani
Systemd mlug-20140614Systemd mlug-20140614
Systemd mlug-20140614
Susant Sahani1.3K views
Sistemas operacionais 8 by Nauber Gois
Sistemas operacionais 8Sistemas operacionais 8
Sistemas operacionais 8
Nauber Gois167 views
Summit demystifying systemd1 by Susant Sahani
Summit demystifying systemd1Summit demystifying systemd1
Summit demystifying systemd1
Susant Sahani748 views
Linux Du Jour by mwedgwood
Linux Du JourLinux Du Jour
Linux Du Jour
mwedgwood680 views
LISA15: systemd, the Next-Generation Linux System Manager by Alison Chaiken
LISA15: systemd, the Next-Generation Linux System Manager LISA15: systemd, the Next-Generation Linux System Manager
LISA15: systemd, the Next-Generation Linux System Manager
Alison Chaiken1.1K views
Your first dive into systemd! by Etsuji Nakai
Your first dive into systemd!Your first dive into systemd!
Your first dive into systemd!
Etsuji Nakai13.3K views
X64 Workshop Linux Information Gathering by Aero Plane
X64 Workshop Linux Information GatheringX64 Workshop Linux Information Gathering
X64 Workshop Linux Information Gathering
Aero Plane1.8K views
3. configuring a compute node for nfv by videos
3. configuring a compute node for nfv3. configuring a compute node for nfv
3. configuring a compute node for nfv
videos2.5K views
Kernel Recipes 2015 - Kernel dump analysis by Anne Nicolas
Kernel Recipes 2015 - Kernel dump analysisKernel Recipes 2015 - Kernel dump analysis
Kernel Recipes 2015 - Kernel dump analysis
Anne Nicolas2.5K views
CentOS Linux Server Hardening by MyOwn Telco
CentOS Linux Server HardeningCentOS Linux Server Hardening
CentOS Linux Server Hardening
MyOwn Telco43.1K views
Containers with systemd-nspawn by Gábor Nyers
Containers with systemd-nspawnContainers with systemd-nspawn
Containers with systemd-nspawn
Gábor Nyers5.5K views
Systemd 간략하게 정리하기 by Seungha Son
Systemd 간략하게 정리하기Systemd 간략하게 정리하기
Systemd 간략하게 정리하기
Seungha Son56 views
MINCS - containers in the shell script (Eng. ver.) by Masami Hiramatsu
MINCS - containers in the shell script (Eng. ver.)MINCS - containers in the shell script (Eng. ver.)
MINCS - containers in the shell script (Eng. ver.)
Masami Hiramatsu2.1K views

Recently uploaded

.conf Go 2023 - How KPN drives Customer Satisfaction on IPTV by
.conf Go 2023 - How KPN drives Customer Satisfaction on IPTV.conf Go 2023 - How KPN drives Customer Satisfaction on IPTV
.conf Go 2023 - How KPN drives Customer Satisfaction on IPTVSplunk
88 views20 slides
Emerging & Future Technology - How to Prepare for the Next 10 Years of Radica... by
Emerging & Future Technology - How to Prepare for the Next 10 Years of Radica...Emerging & Future Technology - How to Prepare for the Next 10 Years of Radica...
Emerging & Future Technology - How to Prepare for the Next 10 Years of Radica...NUS-ISS
16 views28 slides
Business Analyst Series 2023 - Week 3 Session 5 by
Business Analyst Series 2023 -  Week 3 Session 5Business Analyst Series 2023 -  Week 3 Session 5
Business Analyst Series 2023 - Week 3 Session 5DianaGray10
209 views20 slides
The Importance of Cybersecurity for Digital Transformation by
The Importance of Cybersecurity for Digital TransformationThe Importance of Cybersecurity for Digital Transformation
The Importance of Cybersecurity for Digital TransformationNUS-ISS
27 views26 slides
Data-centric AI and the convergence of data and model engineering: opportunit... by
Data-centric AI and the convergence of data and model engineering:opportunit...Data-centric AI and the convergence of data and model engineering:opportunit...
Data-centric AI and the convergence of data and model engineering: opportunit...Paolo Missier
34 views40 slides
How to reduce cold starts for Java Serverless applications in AWS at JCON Wor... by
How to reduce cold starts for Java Serverless applications in AWS at JCON Wor...How to reduce cold starts for Java Serverless applications in AWS at JCON Wor...
How to reduce cold starts for Java Serverless applications in AWS at JCON Wor...Vadym Kazulkin
75 views64 slides

Recently uploaded(20)

.conf Go 2023 - How KPN drives Customer Satisfaction on IPTV by Splunk
.conf Go 2023 - How KPN drives Customer Satisfaction on IPTV.conf Go 2023 - How KPN drives Customer Satisfaction on IPTV
.conf Go 2023 - How KPN drives Customer Satisfaction on IPTV
Splunk88 views
Emerging & Future Technology - How to Prepare for the Next 10 Years of Radica... by NUS-ISS
Emerging & Future Technology - How to Prepare for the Next 10 Years of Radica...Emerging & Future Technology - How to Prepare for the Next 10 Years of Radica...
Emerging & Future Technology - How to Prepare for the Next 10 Years of Radica...
NUS-ISS16 views
Business Analyst Series 2023 - Week 3 Session 5 by DianaGray10
Business Analyst Series 2023 -  Week 3 Session 5Business Analyst Series 2023 -  Week 3 Session 5
Business Analyst Series 2023 - Week 3 Session 5
DianaGray10209 views
The Importance of Cybersecurity for Digital Transformation by NUS-ISS
The Importance of Cybersecurity for Digital TransformationThe Importance of Cybersecurity for Digital Transformation
The Importance of Cybersecurity for Digital Transformation
NUS-ISS27 views
Data-centric AI and the convergence of data and model engineering: opportunit... by Paolo Missier
Data-centric AI and the convergence of data and model engineering:opportunit...Data-centric AI and the convergence of data and model engineering:opportunit...
Data-centric AI and the convergence of data and model engineering: opportunit...
Paolo Missier34 views
How to reduce cold starts for Java Serverless applications in AWS at JCON Wor... by Vadym Kazulkin
How to reduce cold starts for Java Serverless applications in AWS at JCON Wor...How to reduce cold starts for Java Serverless applications in AWS at JCON Wor...
How to reduce cold starts for Java Serverless applications in AWS at JCON Wor...
Vadym Kazulkin75 views
SAP Automation Using Bar Code and FIORI.pdf by Virendra Rai, PMP
SAP Automation Using Bar Code and FIORI.pdfSAP Automation Using Bar Code and FIORI.pdf
SAP Automation Using Bar Code and FIORI.pdf
How the World's Leading Independent Automotive Distributor is Reinventing Its... by NUS-ISS
How the World's Leading Independent Automotive Distributor is Reinventing Its...How the World's Leading Independent Automotive Distributor is Reinventing Its...
How the World's Leading Independent Automotive Distributor is Reinventing Its...
NUS-ISS15 views
Empathic Computing: Delivering the Potential of the Metaverse by Mark Billinghurst
Empathic Computing: Delivering  the Potential of the MetaverseEmpathic Computing: Delivering  the Potential of the Metaverse
Empathic Computing: Delivering the Potential of the Metaverse
Mark Billinghurst470 views
Beyond the Hype: What Generative AI Means for the Future of Work - Damien Cum... by NUS-ISS
Beyond the Hype: What Generative AI Means for the Future of Work - Damien Cum...Beyond the Hype: What Generative AI Means for the Future of Work - Damien Cum...
Beyond the Hype: What Generative AI Means for the Future of Work - Damien Cum...
NUS-ISS34 views
DALI Basics Course 2023 by Ivory Egg
DALI Basics Course  2023DALI Basics Course  2023
DALI Basics Course 2023
Ivory Egg14 views
Future of Learning - Yap Aye Wee.pdf by NUS-ISS
Future of Learning - Yap Aye Wee.pdfFuture of Learning - Yap Aye Wee.pdf
Future of Learning - Yap Aye Wee.pdf
NUS-ISS41 views
Igniting Next Level Productivity with AI-Infused Data Integration Workflows by Safe Software
Igniting Next Level Productivity with AI-Infused Data Integration Workflows Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Safe Software225 views
Special_edition_innovator_2023.pdf by WillDavies22
Special_edition_innovator_2023.pdfSpecial_edition_innovator_2023.pdf
Special_edition_innovator_2023.pdf
WillDavies2216 views
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensors by sugiuralab
TouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective SensorsTouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective Sensors
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensors
sugiuralab15 views
Five Things You SHOULD Know About Postman by Postman
Five Things You SHOULD Know About PostmanFive Things You SHOULD Know About Postman
Five Things You SHOULD Know About Postman
Postman27 views
STPI OctaNE CoE Brochure.pdf by madhurjyapb
STPI OctaNE CoE Brochure.pdfSTPI OctaNE CoE Brochure.pdf
STPI OctaNE CoE Brochure.pdf
madhurjyapb12 views

systemd

  • 1. systemd Lucas Nussbaum lucas.nussbaum@univ-lorraine.fr Licence professionnelle ASRALL Administration de systèmes, réseaux et applications à base de logiciels libres License: GNU General Public License version 3 or later or Creative Commons BY-SA 3.0 Unported (see README.md) Lucas Nussbaum systemd 1 / 40
  • 2. Outline 1 Introduction 2 Behind the scenes: cgroups 3 Managing services 4 Analyzing startup performance 5 Exploring the system status 6 Configuring services by writing unit files 7 Timer units 8 Socket activation 9 Logging with journald 10 Containers integration 11 Networking with systemd-networkd 12 Migration from sysvinit 13 Conclusions Lucas Nussbaum systemd 2 / 40
  • 3. Init system First process started by the kernel (pid 1) Responsible for bringing up the rest of userspace Mounting filesystems Starting services . . . Also the parent for orphan processes Traditional init system on Linux: sysVinit Inherited from Unix System V With additional tools (insserv, startpar) to handle dependencies and parallel initialization Lucas Nussbaum systemd 3 / 40
  • 4. systemd Written (since 2010) by Lennart Poettering (Red Hat) and others Now the default on most Linux distributions Shifts the scope from starting all services (sysVinit) to managing the system and all services Key features: Relies on cgroups for Services supervision Control of services execution environment Declarative syntax for unit files more efficient/robust Socket activation for parallel services startup Nicer user interface (systemctl & friends) Additional features: logging, timer units (cron-like), user sessions handling, containers management Lucas Nussbaum systemd 4 / 40
  • 5. Behind the scenes: cgroups Abbreviated from control groups Linux kernel feature Limit, account for and isolate processes and their resource usage (CPU, memory, disk I/O, network, etc.) Related to namespace isolation: Isolate processes from the rest of the system Chroots on steroids PID, network, UTS, mount, user, etc. LXC, Docker ≈ cgroups + namespaces (+ management tools) Lucas Nussbaum systemd 5 / 40
  • 6. cgroups and systemd Each service runs in its own cgroup Enables: Tracking and killing all processes created by each service Per-service accounting and resources allocation/limitation Previously, with sysVinit: No tracking of which service started which processes PID files, or hacks in init scripts: pidof / killall / pgrep Hard to completely terminate a service (left-over CGI scripts when killing Apache) No resources limitation (or using setrlimit (= ulimit), which is per-process, not per-service) Also isolate user sessions kill all user processes (not by default) More information: Control Groups vs. Control Groups and Which Service Owns Which Processes? Lucas Nussbaum systemd 6 / 40
  • 7. systemd-cgls: visualizing the cgroups hierarchy Lucas Nussbaum systemd 7 / 40
  • 8. systemd-cgtop: per-service resources usage Requires enabling CPUAccounting, BlockIOAccounting, MemoryAccounting Lucas Nussbaum systemd 8 / 40
  • 9. Managing services with systemctl What is being manipulated is called a unit: services (.service), mount points (.mount), devices (.device), sockets (.socket), etc. Basic commands: sysVinit systemd notes service foo start systemctl start foo service foo stop systemctl stop foo service foo restart systemctl restart foo service foo reload systemctl reload foo service foo condrestart systemctl condrestart foo restart if already running update-rc.d foo enable systemctl enable foo auto-start at next boot update-rc.d foo disable systemctl disable foo disable auto-start systemctl is-enabled foo There’s auto-completion (apache2 and apache2.service work) Several services can be specified: systemctl restart apache2 postgresql Lucas Nussbaum systemd 9 / 40
  • 10. systemd and runlevels With sysVinit, runlevels control which services are started automatically 0 = halt; 1 = single-user / minimal mode; 6 = reboot Debian: no difference by default between levels 2, 3, 4, 5 RHEL: 3 = multi-user text, 5 = multi-user graphical systemd replaces runlevels with targets: Configured using symlinks farms in /etc/systemd/system/target.wants/ systemctl enable/disable manipule those symlinks systemctl mask disables the service and prevents it from being started manually The default target can be configured with systemctl get-default/set-default More information: The Three Levels of "Off" Lucas Nussbaum systemd 10 / 40
  • 11. Default targets (bootup(7)) local -fs-pre.target | v (various mounts and (various swap (various cryptsetup fsck services ...) devices ...) devices ...) (various low -level (various low -level | | | services: udevd , API VFS mounts: v v v tmpfiles , random mqueue , configfs , local -fs.target swap.target cryptsetup.target seed , sysctl , ...) debugfs , ...) | | | | | __________________|_________________ | ___________________|____________________/ |/ v sysinit.target | ____________________________________ /| ________________________________________ / | | | | | | | | v v | v v (various (various | (various rescue.service timers ...) paths ...) | sockets ...) | | | | | v v v | v rescue.target timers.target paths.target | sockets.target | | | | __________________|_________________ | ___________________/ |/ v basic.target | ____________________________________ /| emergency.service / | | | | | | v v v v emergency.target display - (various system (various system manager.service services services) | required for | | graphical UIs) v | | multi-user.target | | | _________________ | _________________/ |/ v graphical.target Lucas Nussbaum systemd 11 / 40
  • 12. Analyzing startup performance Fast boot matters in some use-cases: Virtualization, Cloud: Almost no BIOS / hardware checks only software startup Requirement for infrastructure elasticity Embedded world systemd-analyze time: summary Startup finished in 4.883s (kernel) + 5.229s (userspace) = 10.112s systemd-analyze blame: worst offenders 2.417s systemd -udev -settle.service 2.386s postgresql@9 .4-main.service 1.507s apache2.service 240ms NetworkManager.service 236ms ModemManager.service 194ms accounts -daemon.service Lucas Nussbaum systemd 12 / 40
  • 13. systemd-analyze plot Similar to bootchartd, but does not require rebooting with a custom init= kernel command-line Lucas Nussbaum systemd 13 / 40
  • 14. systemd-analyze critical-chain Shows services in the critical path Lucas Nussbaum systemd 14 / 40
  • 15. Exploring the system status Listing units with systemctl list-units (or just systemctl): active units: systemctl List only services: systemctl -t service List units in failed state: systemctl --failed Whole system overview: systemctl status GUI available: systemadm Lucas Nussbaum systemd 15 / 40
  • 16. systemctl status service Includes: Service name and description, state, PID Free-form status line from systemd-notify(1) or sd_notify(3) Processes tree inside the cgroup Last lines from journald (syslog messages and stdout/stderr) Lucas Nussbaum systemd 16 / 40
  • 17. Configuring services by writing unit files With sysVinit: shell scripts in /etc/init.d/ Long and difficult to write Redundant code between services Slow (numerous fork() calls) With systemd: declarative syntax (.desktop-like) Move intelligence from scripts to systemd Covers most of the needs, but shell scripts can still be used Can use includes and overrides (systemd-delta) View config file for a unit: systemctl cat atd.service Or just find the file under /lib/systemd/system/ (distribution’s defaults) or /etc/systemd/system (local overrides) Lucas Nussbaum systemd 17 / 40
  • 18. Simple example: atd [Unit] Description=Deferred execution scheduler # Pointer to documentation shown in systemctl status Documentation=man:atd(8) [Service] # Command to start the service ExecStart =/usr/sbin/atd -f IgnoreSIGPIPE=false # Default is true [Install] # Where "systemctl enable" creates the symlink WantedBy=multi -user.target Lucas Nussbaum systemd 18 / 40
  • 19. Common options Documented in systemd.unit(5) ([Unit]), systemd.service(5) ([Service]), systemd.exec(5) (execution environment) Show all options for a given service: systemctl show atd Sourcing a configuration file: EnvironmentFile=-/etc/default/ssh ExecStart=/usr/sbin/sshd -D $SSHD_OPTS Using the $MAINPID magic variable: ExecReload=/bin/kill -HUP $MAINPID Auto-restart a service when crashed: (≈ runit / monit) Restart=on-failure Conditional start: ConditionPathExists=!/etc/ssh/sshd_not_to_be_run Conditions on architecture, virtualization, kernel cmdline, AC power, etc. Lucas Nussbaum systemd 19 / 40
  • 20. Options for isolation and security Use a network namespace to isolate the service from the network: PrivateNetwork=yes Use a filesystem namespaces: To provide a service-specific /tmp directory: PrivateTmp=yes To make some directories inaccessible or read-only: InaccessibleDirectories=/home ReadOnlyDirectories=/var Specify the list of capabilities(7) for a service: CapabilityBoundingSet=CAP_CHOWN CAP_KILL Or just remove one: CapabilityBoundingSet=~CAP_SYS_PTRACE Disallow forking: LimitNPROC=1 Lucas Nussbaum systemd 20 / 40
  • 21. Options for isolation and security (2) Run as user/group: User=, Group= Run service inside a chroot: RootDirectory=/srv/chroot/foobar ExecStartPre=/usr/local/bin/setup-foobar-chroot.sh ExecStart=/usr/bin/foobard RootDirectoryStartOnly=yes Control CPU shares, memory limits, block I/O, swapiness: CPUShares=1500 MemoryLimit=1G BlockIOWeight=500 BlockIOReadBandwith=/var/log 5M ControlGroupAttribute=memory.swappiness 70 More information: Converting sysV init scripts to systemd service files, Securing your services, Changing roots, Managing resources Lucas Nussbaum systemd 21 / 40
  • 22. Timer units Similar to cron, but with all the power of systemd (dependencies, execution environment configuration, etc) Realtime (wallclock) timers: calendar event expressions Expressed using a complex format (see systemd.time(7)), matching timestamps like: Fri 2012-11-23 11:12:13 Examples of valid values: hourly (= *-*-* *:00:00), daily (= *-*-* 00:00:00), *:2/3 (= *-*-* *:02/3:00) Monotonic timers, relative to different starting points: 5 hours and 30 mins after system boot: OnBootSec=5h 30m 50s after systemd startup: OnstartupSec=50s 1 hour after the unit was last activated: OnUnitActiveSec=1h (can be combined with OnBootSec or OnStartupSec to ensure that a unit runs on a regular basis) Lucas Nussbaum systemd 22 / 40
  • 23. Timer units example myscript.service: [Unit] Description=MyScript [Service] Type=simple ExecStart =/usr/local/bin/myscript myscript.timer: [Unit] Description=Runs myscript every hour [Timer] # Time to wait after booting before we run first time OnBootSec =10min # Time between running each consecutive time OnUnitActiveSec =1h Unit=myscript.service [Install] WantedBy=multi -user.target Lucas Nussbaum systemd 23 / 40
  • 24. Timer units example (2) Start timer: systemctl start myscript.timer Enable timer to start at boot: systemctl enable myscript.timer List all timers: systemctl list-timers Lucas Nussbaum systemd 24 / 40
  • 25. Socket activation systemd listens for connection on behalf of service until the service is ready, then passes pending connections Benefits: No need to express ordering of services during boot: They can all be started in parallel faster boot And they will wait for each other when needed (when they will talk to each other), thanks to socket activation Services that are seldomly used do not need to keep running, and can be started on-demand Not limited to network services: also D-Bus activation and path activation More information: Converting inetd Service, Socket Activation for developers (+ follow-up) Lucas Nussbaum systemd 25 / 40
  • 26. Socket activation example: dovecot dovecot.socket: [Unit] Description=Dovecot IMAP/POP3 email server activation socket [Socket] # dovecot expects separate # IPv4 and IPv6 sockets BindIPv6Only=ipv6 -only ListenStream =0.0.0.0:143 ListenStream =[::]:143 ListenStream =0.0.0.0:993 ListenStream =[::]:993 KeepAlive=true [Install] WantedBy=sockets.target dovecot.service: [Unit] Description=Dovecot IMAP/POP3 email server After=local -fs.target network.target [Service] Type=simple ExecStart =/usr/sbin/dovecot -F NonBlocking=yes [Install] WantedBy=multi -user.target Lucas Nussbaum systemd 26 / 40
  • 27. Socket activation example: sshd sshd.socket: [Unit] Description=SSH Socket for Per -Connection Servers [Socket] ListenStream =22 Accept=yes [Install] WantedBy=sockets.target sshd@.service: [Unit] Description=SSH Per -Connection Server [Service] ExecStart=-/usr/sbin/sshd -i StandardInput=socket Lucas Nussbaum systemd 27 / 40
  • 28. Socket activation example: sshd (2) sshd@.service means that this is an instantiated service There’s one instance of sshd@.service per connection: # systemctl --full | grep ssh sshd@172 .31.0.52:22 -172.31.0.4:47779. service loaded active running sshd@172 .31.0.52:22 -172.31.0.54:52985. service loaded active running sshd.socket loaded active listening Instanciated services are also used by getty See Serial console and Instanciated services Lucas Nussbaum systemd 28 / 40
  • 29. Logging with journald Component of systemd Captures syslog messages, kernel log messages, initrd and early boot messages, messages written to stdout/stderr by all services Forwards everything to syslog Structured format (key/value fields), can contain arbitrary data But viewable as syslog-like format with journalctl Indexed, binary logs; rotation handled transparently Can replace syslog (but can also work in parallel) Not persistent across reboots by default – to make it persistent, create the /var/log/journal directory, preferably with: install -d -g systemd-journal /var/log/journal setfacl -R -nm g:adm:rx,d:g:adm:rx /var/log/journal Can log to a remote host (with systemd-journal-gateway, not in Debian yet) Lucas Nussbaum systemd 29 / 40
  • 30. Example journal entry _SERVICE=systemd -logind.service MESSAGE=User harald logged in MESSAGE_ID =422 bc3d271414bc8bc9570f222f24a9 _EXE=/lib/systemd/systemd -logind _COMM=systemd -logind _CMDLINE =/lib/systemd/systemd -logind _PID =4711 _UID=0 _GID=0 _SYSTEMD_CGROUP =/ system/systemd -logind.service _CGROUPS=cpu:/ system/systemd -logind.service PRIORITY =6 _BOOT_ID =422 bc3d271414bc8bc95870f222f24a9 _MACHINE_ID=c686f3b205dd48e0b43ceb6eda479721 _HOSTNAME=waldi LOGIN_USER =500 Lucas Nussbaum systemd 30 / 40
  • 31. Using journalctl View the full log: journalctl Since last boot: journalctl -b For a given time interval: journalctl --since=yesterday or journalctl --until="2013-03-15 13:10:30" View it in the verbose (native) format: journalctl -o verbose Filter by systemd unit: journalctl -u ssh Filter by field from the verbose format: journalctl _SYSTEMD_UNIT=ssh.service journalctl _PID=810 Line view (≈ tail -f): journalctl -f Last entries (≈ tail): journalctl -n Works with bash-completion See also: Journald design document, Using the Journal Lucas Nussbaum systemd 31 / 40
  • 32. Containers integration General philosophy: integrate management of services from machines (VMs and containers) with those of the host systemd-machined: tracks machines, provides an API to list, create, register, kill, terminate machines, transfer images (tar, raw, Docker) machinectl: command-line utility to manipulate machines other tools also have containers support: systemctl -M mycontainer restart foo systemctl list-machines: provides state of containers journalctl -M mycontainer journalctl -m: combined log of all containers systemd has its own mini container manager: systemd-nspawn Other virtualization solutions can also talk to machined More information: Container integration Lucas Nussbaum systemd 32 / 40
  • 33. Networking with systemd-networkd Replacement for /etc/network/interfaces, on servers and VMs Not really for Network Manager on desktops and laptops Supports setting IP configuration, configuring bridges, vlans, bonding, tunnels, etc Configuration files with a [Match] section to match on MAC address, driver, udev path, type, hostname, etc foo.link: link-level configuration – MAC address, interface name, MTU, rate, Duplex mode, Wake on Lan foo.netdev: creation of virtual network devices (bridges, bonds, vlans, IPIP or GRE tunnels, VXLAN, tun, tap, veth) foo.network: network devices configuration: IP (static or DHCP, gateway, additional routes, DNS), addition to bridge More information: systemd-networkd(8), systemd.link(5), systemd.network(5), systemd.netdev(5) Lucas Nussbaum systemd 33 / 40
  • 34. Example 1: DHCP, additional route For higher performance, systemd includes a DHCP client # /etc/systemd/network/ethernet.network [Match] Name=eth0 [Network] DHCP=yes [Route] Gateway =192.168.1.253 Destination =10.0.0.0/8 Lucas Nussbaum systemd 34 / 40
  • 35. Example 2: static addressing and VLAN # /etc/systemd/network/vlan1.netdev # [Match] section is optional in netdev files [NetDev] Name=vlan1 Kind=vlan [VLAN] Id=1 # /etc/systemd/network/ethernet.network [Match] Name=eth0 [Network] DHCP=yes VLAN=vlan1 # will create vlan1 on this device # /etc/systemd/network/vlan1.network [Match] Name=vlan1 [Network] Address =192.168.1.1/24 Gateway =192.168.1.254 Lucas Nussbaum systemd 35 / 40
  • 36. Example 3: bridge and tap # /etc/systemd/network/bridge0.netdev [NetDev] Name=bridge0 Kind=bridge # /etc/systemd/network/bridge0.network [Match] Name=bridge0 [Network] Address =192.168.1.1/24 DHCPServer=yes # systemd has its own , very basic , DHCP server # /etc/systemd/network/tap.netdev [NetDev] Name=tap0 Kind=tap # /etc/systemd/network/tap.network [Match] Name=bridge0 [NetDev] Bridge=bridge0 Lucas Nussbaum systemd 36 / 40
  • 37. Migration from sysvinit systemd hooks into LSB init scripts: service foo start|stop|... and /etc/init.d/foo redirect to systemctl systemd-sysv-generator creates wrapper units for LSB scripts: Using LSB dependencies Services are described as LSB: foo List all generated services: systemctl list-units | grep LSB: Lucas Nussbaum systemd 37 / 40
  • 38. Generated wrapper service file for apache2 $ systemctl cat apache2.service # /run/systemd/generator.late/apache2.service # Automatically generated by systemd -sysv -generator [Unit] Description=LSB: Apache2 web server Before=runlevel2.target runlevel3.target runlevel4.target runlevel5.target shutdown.target After=local -fs.target remote -fs.target network -online.target systemd -journald -dev -log.socket nss -lookup.target Wants=network -online.target Conflicts=shutdown.target [Service] Type=forking KillMode=process [...] ExecStart=/etc/init.d/apache2 start ExecStop=/etc/init.d/apache2 stop ExecReload=/etc/init.d/apache2 reload Lucas Nussbaum systemd 38 / 40
  • 39. More stuff New cross-distro configuration files: /etc/hostname, /etc/locale.conf, /etc/sysctl.d/*.conf, /etc/tmpfiles.d/*.conf Tools to manage hostname, locale, time and date: hostnamectl, localectl, timedatectl Support for watchdogs Handling of user sessions Each within its own cgroup Multi-seat support loginctl to manage sessions, users, seats Lucas Nussbaum systemd 39 / 40
  • 40. Conclusions systemd revisits the way we manage Linux systems If we redesigned services management from scratch, would it look like systemd? For service developers: easier to support systemd than sysVinit No need to fork, to drop privileges, to write a pid file Just output logs to stdout (redirected to syslog, with priorities) Some parts still have rough edges, or are still moving targets, but are promising: journal, containers, networking systemd might not be the final answer, but at least it’s an interesting data point to look at Lucas Nussbaum systemd 40 / 40