LinuxCBT Systemd Edition Notes
LinuxCBT Systemd Edition Notes
Features:
1. System && Service Manager - freedesktop.org/wiki/Software/systemd
a. System
a1. system initialization
a2. power state of machine: up, down, suspended, hybrid, etc.
b. Service Manager
b1. User-space management of daemons (services)
b2. Management of other system units: devices, daemons, sockets, d-bus, etc.
NOTE: 'systemd' is an all-encompassing system manager for Linux which stands in
stark contrast to typicaly, conventional Unix | Linux philosophy of simplicity of
various services, executables, functions, etc.
3. New INIT system - Most major distros now use: 'systemd': i.e. Debian, RedHat
and SuSE, and eventually: Ubuntu
10. Service management via: 'systemctl': status | start | stop | restart | enable |
disable
11. LOG of start | stop of daemons - includes: PID and Timestamp - audit trail of
service history
12. Runlevel control - 'targets' REPLACE Runlevels (0(poweroff|shutdown), 1(rescue|
emergency), 2|3(multi-user), 5(graphical), 6(reboot)
13. State control: emergency, rescue, poweroff, restart, hibernation, suspension
14. 'systemd' units - encapsulation of services, sockets, system state snapshots,
targets, etc.
15. Device-based activation - i.e. hot-plugged device activates corresponding
service(s)
16. Complete LOGs from startup -> shutdown: interim LOGs are buffered to 'kmsg' LOG
then flushed to: /dev/log
17. Parallelization of service invocation at startup significantly expedites system
startup
NOTE: The system may come up much quicker, but services may take longer to be
'ready'
18. Management of 'Control Groups' (Kernel features: Hierarchy of labeled
processes): '/sys/fs/cgroups'
NOTE: This makes it possible to properly manage parent-child(ren) processes
19. Mount || Automount management
20. Service do NOT inherit environment: $PATH && HOME from current $USER - more
secure
21. Remote invocation/management of remote systems using 'systemctl' via: '-H HOST'
- relies on passwordless-AUTH(SSH)
NOTE: This, again, is NOT possible with current: SysV environment
22. 'systemd' provides userspace MUCH quicker because of various tricks
23. On-demand (event-drivent) invocation of services: i.e. TTYs (agetty)
# Boot Process #
BIOS -> GRUB -> Kernel/INITRD -> 'init'(PID=1) -> User Space
BIOS -> GRUB -> Kernel/INITRD -> 'systemd'(PID=1) -> User Space (quicker)
Tasks:
1. Evaluate various startup with 'systemd' times, etc.
NOTE: 'tty1' is always spawned regardless of targets: 'multi-user' || 'graphical'
NOTE: In contrast to typical 'sysvinit' startups, 'systemd' does NOT auto-spawn ALL
TTYs
NOTE: TTYs are spaned on-demand - event-driven(CTRL-ALT-F(NUM))
Tasks:
1. 'systemd' -> PID=1' - spawns ALL other user-space processes
2. 'dpkg -l | grep systemd' || 'yum search systemd && rpm -ql systemd'
a. '/etc/systemd' - top-level config container
3. Time control: 'timedatectl'
a. 'timedatectl' - displays current time | date | etc. information
b. 'timedatectl list-timezones' - returns list of possible timezones
c. 'timedatectl set-timezone TZ' - use one from the 'list-timezones' dump
d. 'timedatectl set-time YYYY-MM-DD HH:MM:SS' - sets the time and NTP should
handle the rest
# Targets ~ RunLevels #
Fetures:
1. Run-Level control ~ (0..6) - replaces these SysV INIT runlevels
Various Targets:
RunLevel Target
0 (poweroff|shutdown).target
1 (emergency|rescue).target
2-4 (multi-user.target) - sans graphics
5 (graphical.target)
6 (reboot.target)
Tasks:
1. Show the currently loaded targets:
a. 'systemctl -t target'
b. 'systemctl show -p "Requires" graphical.target'
2. Show the DEFAULT target
a. 'systemctl get-default'
3. Navigate Targets: i.e. 'init N(0..6)'
a. 'systemctl isolate TARGET'
NOTE: TTY6 may become your goto TTY when alternating between targets
# 'systemctl' #
Features:
1. Primary management tool for: 'systemd'
2. Replaces various power management commands:
a. 'halt'
b. 'reboot'
c. 'poweroff'
d. 'hibernate'
e. etc.
Tasks:
1. Reboot | Poweroff
a. 'systemctl [--no-wall] reboot [-i]' || 'reboot'(symlinked to: systemctl)'
b. 'systemctl "" poweroff '
c. 'systemctl "" suspend' - dumps state to RAM (faster recovery than 'hibername')
(does not persist across power outages on HOST)
NOTE: 'suspend' requires the HOST system to be on in order to preserve the contents
of the suspended state
NOTE: Resumption occurs quickly and often will NOT break active SSH sessions
d. 'systemctl "" hibernate' - dumps the state to disk (persists across power
outages)
3. Manage Service
a. 'systemctl status (apache2|httpd)'
b. 'systemctl (start|stop|reload|restart) (apache2|httpd)'
c. 'systemctl kill (apache2|httpd)'
# Remote Control #
Features:
1. Execute systemd-related commands on remote targets
2. Provided utilities support the remote option: '-H TARGET'
3. Requires SSH Passwordless-AUTH setup to avoid prompts per invocation
NOTE: For basic, non-privileged tasks using 'systemctl', setup passwordless-AUTH as
non-privileged
i.e. 'linuxcbt' -> 'linuxcbt'(remote target)
Tasks:
1. 'systemctl -H 192.168.75.121' - auto-paginates output received from target
NOTE: Sometimes, output from remote calls is truncated
2. Setup passwordless-AUTH on target systems
a. 'ssh-keygen' - generate a keypair
b. 'ssy-copy-id TARGET'
c. Test passwordless-AUTH on targets using: 'ssh'
3. Re-run 'systemctl' on TARGETs
a. 'systemctl -H 192.168.75.121'
4. Enable 'root' 'systemctl' access on targets
NOTE: If target does NOT allow password-AUTH for 'root' then copy key manually.
Otherwise, use: 'ssh-copy-id'
Tasks:
1. Explore 'journalctl' - dumps ALL messages in the current buffer
NOTE: By default, LOGs are maintained in memory: /run/log/journal/machine-id and
are NOT saved (flushed) to disk automatically
NOTE: If you make: '/var/log/journal' - then LOGs will be flushed as needed (size |
interval)