systemd
What is an init system?
Running Programs Automatically on Your Tiny Computer: systemd: Writing and Enabling a Service
Raspberry Pi Boot Process
Clarification about the boot process (systemd / init)
How To Use Systemctl to Manage Systemd Services and Units
How To Configure a Linux Service to Start Automatically After a Crash or Reboot – Part 2: Reference
How does systemd use /etc/init.d scripts?
Before: SysVinit (System V init, or just init) Now: systemd
- In systemd, there is no concept of runlevels. - These are replaced by targets. - Targets can and do depend on each other. basic.target => multi-user.target => graphical.target - Under SysVinit, scripts run strictly in order runlevel => systemd target 0: halt 1: single-user 2: multi-user 3: multi-user with networking => multi-user.target 4: undefined (user defined) 5: multi-user with display manager (graphical login) => graphical.target 6: reboot basic.target network.target multi-user.target graphical.target init.scope system.slice -.mount -.slice
$ sudo apt-get update $ sudo apt-get dist-upgrade $ sudo apt-get install graphviz $ sudo apt-get install tree
$ systemd-analyze critical-chain
The time after the unit is active or started is printed after the "@" character.
The time the unit takes to start is printed after the "+" character.
graphical.target @33.104s
└─multi-user.target @33.103s
└─getty.target @33.103s
└─getty@tty1.service @33.102s
└─systemd-user-sessions.service @33.030s +16ms
└─network.target @33.023s
└─dhcpcd.service @2.326s +30.692s
└─basic.target @2.161s
└─sockets.target @2.161s
└─triggerhappy.socket @2.160s
└─sysinit.target @2.155s
└─systemd-timesyncd.service @1.930s +224ms
└─systemd-tmpfiles-setup.service @1.864s +55ms
└─local-fs.target @1.854s
└─boot.mount @1.836s +16ms
└─systemd-fsck@dev-disk-by\x2dpartuuid-fc38305d\x2d01.service @1.492s +336ms
└─dev-disk-by\x2dpartuuid-fc38305d\x2d01.device @1.489s
$ systemd-analyze dot | dot -Tsvg > systemd.svg
Color legend: black = Requires
dark blue = Requisite
dark grey = Wants
red = Conflicts
green = After
$ pstree
systemd-+-agetty
|-avahi-daemon---avahi-daemon
|-bluetoothd
|-cron
|-dbus-daemon
|-dhcpcd
|-hciattach
|-login---bash
|-rsyslogd-+-{in:imklog}
| |-{in:imuxsock}
| `-{rs:main Q:Reg}
|-sshd---sshd---sshd---bash---pstree
|-systemd---(sd-pam)
|-systemd-journal
|-systemd-logind
|-systemd-timesyn---{sd-resolve}
|-systemd-udevd
|-thd
`-wpa_supplicant
Global: /etc/systemd/system /lib/systemd/system/ User: /etc/systemd/user, /run/systemd/user /lib/systemd/user /usr/lib/systemd/user
$ systemctl status $ systemctl or $ systemctl list-units $ systemctl list-unit-files
Service units Target units unit slice scope service services (.service) mount points (.mount) devices (.device) sockets (.socket) (.automount) (.swap) (.target) (.path) (.timer) (.slice) (.scope)
$ sudo systemctl start myscript.service $ sudo systemctl stop myscript.service $ sudo systemctl enable myscript.service
autologin@.service bluetooth.target.wants dbus-org.bluez.service -> /lib/systemd/system/bluetooth.service dbus-org.freedesktop.Avahi.service -> /lib/systemd/system/avahi-daemon.service dhcpcd.service.d dhcpcd5.service -> /lib/systemd/system/dhcpcd.service getty.target.wants getty@tty1.service.d halt.target.wants multi-user.target.wants network-online.target.wants poweroff.target.wants rc-local.service.d reboot.target.wants remote-fs.target.wants sockets.target.wants sshd.service -> /lib/systemd/system/ssh.service sysinit.target.wants syslog.service -> /lib/systemd/system/rsyslog.service timers.target.wants