Intro to systemd - Frequently used commands - Managing services with systemctl - Diagnostics using journalctl About these commands: - Most commands have a default option, which typically shows the current status. - For all commands, add the --help parameter to get a quick summary. - Use the man page to get more of the details. - Don't let the plethora of options startle you! - Perhaps the easiest way to learn how to do something is to search the web for the word systemd along with the desired outcome. hostnamectl - read or set the hostname - shows various info about the hardware - this replaces various distro specific methods of setting the hostname localectl - manages the system locale and keyboard layout - this replaces various distro specific methods to configure these timedatectl - sets timezone - shows various options about keeping - timedatectl status vs. timedatectl show - this replaces various distro specific methods of setting the time resolvectl - manages name resolution options - think of nslookup, host and dig on steroids - can be very useful in diagnostics - this replaces various distro specific methods of setting name resolution and various commands like hslookup, host, dig, nscd reboot and poweroff - best method to reboot or shutdown a system - this replaces various commands such as shutdown, halt, init and telinit loginctl - configures the login manager - this replaces functionality in w, who, passwd, id, pgrep, pkill, kill and killall - can be used with pam_systemd, if available udevadm - sends commands to the device manager - useful for diagnostics udevadm - sends commands to the device manager - useful for diagnostics systemctl - controls the system and manages services - contains "units" which have "templates" that define various items, such as services - systemctl with no options shows units in use - systemctl --all shows all units defined - in this intro, we will only look at service units how to find the proper name of a service - is the service named ssh, sshd, OpenSSH or what? - systemctl | grep -i ssh display information about a service - systemctl status ssh - includes info including: file containing unit definition whether currently enabled whether preset (default setting) is enabled PID, memory usage, CPU, etc. color coded logs of recent events manage a service - systemctl status ssh - systemctl start ssh - systemctl restart ssh - systemctl stop ssh select to run automatically at boot - systemctl sstatus ssh - systemctl enable ssh - systemctl disable ssh create an alias for a service name - "bind" alias for the "named" service: - systemctl status named | grep loaded note location of unit definition - systemctl edit named add two lines, then exit and save [Install] Alias=bind.service - systemctl enable named force reading of updated config - systemctl status bind verify that all is well fake example of a custom watchdog service:` cat > /etc/systemd/system/mydog.service <<\EoT [Unit] Description=My Dog Service, not UID 0 After=network.target [Service] Type=simple User=nobody WorkingDirectory=/var/lib/mydog ExecStart=/var/lib/mydog --whatever Restart=on-abort [Install] WantedBy=multi-user.target EoT systemctl daemon-reload; systemctl enable --now mydog check for failed services - systemctl --type=service --state=failed journalctl - easy access to the logs - serveral easy to remeber options can be combined in any combintion journalctl (1/2) - journalctl -u ssh shows only log entries from a single unit (or service) - journalctl -f follows in long listings until interrupted with ctrl-C - journalctl -S 0:05 displays only entries since the last 5 minutes - journalctl -S yesterday 2023-02-09 14:30 -U today 12:00 displays entries since 2:30pm on Feb 9 until today at noon - journalctl -f -l -u ssh very nice when troubleshooting sshd connections! journalctl (2/2) - journalctl --list-boots shows list of recent boots - journalctl -f -l -b1 shows previous boot logs (or -b2 for second last) - journalctl -k shows kernel log entries, aka --dmesg - journalctl --help find grep, reverse, quiet and pager options, and more