Here are the notes from the ma mouth YouTube video about systemd.
===== SystemD Commands ====== Created Wednesday 12 April 2017 **systemd** is a system and service manager for Linux operating systems. **systemctl** may be used to introspect and control the state of the systemd system and service manager. **systemd-analyze** may be used to determine system boot-up performance statistics and retrieve other state and tracing information from the system and service manager. === systemd-analyze === * Print help systemd-analyze -h Show time, blame, dump
* Prints the time that all processes have initialized/started but non necessary finished loaded Startup finished in 298ms (kernel) + 1.847s (initrd) + 16.103s (userspace) = 18.249s - Kernel load time - [not on all systems] Ram Disk load time - https://en.wikipedia.org/wiki/Initrd - Userspace load time (your programs) ** initrd (initial ramdisk) is a scheme for loading a temporary root file system into memory
* Q to exit * Prints a list of all running units, ordered by the time they took to initialize. This information may be used to optimize boot-up times. Note that the output might be misleading as the initialization of one service might be slow simply because it waits for the initialization of another service to complete.
* Q to exit * Outputs a (usually very long) human-readable serialization of the complete server state === systemctl === This is the main command for systemd. The syntax is: [sudo] systemctl OPTION service
sudo systemctl -h
* Print help View By Type > sudo systemctl -t service * service, socket, swap, device, etc View By State > sudo systemctl --state failed active, dead, failed Check journal status > sudo systemctl status systemd-journald -l Failed > sudo systemctl --failed Enable (load a boot up) > sudo systemctl enable firewalld Start > sudo systemctl start firewalld Restart > sudo systemctl restart firewalld Reload > sudo systemctl reload firewalld * Reload service's configuration file(s) Stop > sudo systemctl stop firewalld Disable (don't load at boot up) > sudo systemctl disable firewalld x Enabled/Disabled? > sudo systemctl is-enabled firewalld x Active? > sudo systemctl is-active firewalld Block Unit From Starting > sudo systemctl mask firewalld Unblock Unit From Starting > sudo systemctl unmask firewalld Power > sudo systemctl OPTION OPTIONS reboot poweroff suspend hibernate hybrid-sleep See units (configurations) > sudo systemctl list-units * Loads all active units > sudo systemctl list-units --all * Loads all units > sudo systemctl list-unit-files * A condensed list View Unit File > sudo systemctl cat sshd.service * Prints out the service configuration View Help On Unit > sudo systemctl help firewalld.service Reload [[SystemD]] and look for changed units > sudo systemctl daemon-reload View Dependencies > sudo systemctl list-dependencies sshd.service * Lists the units that must be started for service to run Remote Admin > systemctl -H IP/Hostname restart sshd * Issue commands on remote servers Show Low-Level Properities > sudo systemctl show sshd.service See conflicts > sudo systemctl show sshd.service -p Conflicts * However some conflicts don't seem to really matter See any changes (drop-ins) > sudo systemd-delta **Type=simple (default)** systemd considers the service to be started up immediately. The process must not fork. Do not use this type if other services need to be ordered on this service, unless it is socket activated. **Type=forking** systemd considers the service started up once the process forks and the parent has exited. For classic daemons use this type unless you know that it is not necessary. You should specify PIDFile= as well so systemd can keep track of the main process. Type=oneshot this is useful for scripts that do a single job and then exit. You may want to set RemainAfterExit=yes as well so that systemd still considers the service as active after the process has exited. Type=notify identical to Type=simple, but with the stipulation that the daemon will send a signal to systemd when it is ready. The reference implementation for this notification is provided by libsystemd-daemon.so. Type=dbus the service is considered ready when the specified BusName appears on DBus's system bus. Type=idle systemd will delay execution of the service binary until all jobs are dispatched. Other than that behavior is very similar to Type=simple. Basic File: [Unit] Description=Describe the daemon After=network.target [Service] ExecStart=/usr/sbin/[myapp] -D Type=forking PIDFile=/var/run/myapp.pid [Install] WantedBy=multi-user.target END **Fstrim** > sudo systemctl status fstrim SCRIPT FROM CENTOS: [Unit] Description=Discard unused blocks [Service] Type=oneshot ExecStart=/usr/sbin/fstrim -a END SCRIPT - Place in /etc/systemd/system **TimeSynCD** https://wiki.archlinux.org/index.php/Systemd-timesyncd Edit Files: Maintainer (don't use as they will be overwritten): /usr/lib/systemd/system Administrator (takes precedences over /usr): /etc/systemd/system Runtime, not presistent: /run/systemd/system * If one puts the file in /usr/lib/systemd/system it can be enable and disable, however could be overwritten * If one puts the file in /etc/systemd/system this is safer but enable and disable don't work Tools: * See the slices and cgroup names > sudo systemd-cgls * See the current usage > sudo systemd-cgtop === Journal === - indexed - formatted so errors in red - security - reliablility - intelligently rotated - allows filtering unlike traditional logs View the journal > sudo journalctl Watch live > sudo journalctl -f Call a specific service > sudo journalctl -u sshd.service Call based on time > sudo journalctl --since="2017-4-13 14:46:32" --until="2017-4-13 15:00:00" Call warnings > journalctl -p warning **Containers** systemd-nspawn - container for testing, debugging, testing and can be used like KVM https://www.freedesktop.org/software/systemd/man/systemd-nspawn.html