Demonstrates some examples with systemd
Creating a systemd service
example 22_systemd_service.
Some journalctl
examples here.
REF: github.com/chrisguest75/shell_examples/27_journalctl/README.md
TODO:
- Add a timer and a socket example.
# show unit types
systemctl list-units -t help
# show help for different units
man systemd.unit
man systemd.service
man systemd.timer
A unit configuration file whose name ends in ".target" encodes information about a target unit of systemd, which is used for grouping units and as well-known synchronization points during start-up.
# list targets
systemctl list-units --type target
# show unit file for timers.target
systemctl cat timers.target
A unit configuration file whose name ends in ".service" encodes information about a process controlled and supervised by systemd.
# Show properties of one or more units/jobs or the manager
systemctl show --no-pager
# list services
systemctl list-units -t service --no-pager
systemctl list-units -t service --state running
# status of service
systemctl status zfs-zed.service
# list the unit files
systemctl cat zfs-import-cache.service
A unit configuration file whose name ends in ".socket" encodes information about an IPC or network socket or a file system FIFO controlled and supervised by systemd, for socket-based activation.
systemctl list-units --type socket
systemctl cat uuidd.socket
A unit configuration file whose name ends in ".timer" encodes information about a timer controlled and supervised by systemd, for timer-based activation.
systemctl list-timers --no-pager --all
systemctl cat fstrim.timer
systemd-run
systemd-run --user --on-calendar '*:0/1' ./script.sh --arg1
# if a timer is failing to be removed "not-found"
systemctl reset-failed
# what has failed?
systemctl --failed
# look at logs for a service
journalctl -b -u docker.service
# top for systemd services
systemd-cgtop
systemd-analyze blame
#
systemd-analyze plot --help
systemd-analyze plot > ./graph1.svg
xdg-open ./graph1.svg
# reload systemd
systemctl daemon-reload
systemctl reboot -i
loginctl
cheatsheet systemd
cheatsheet systemctl
- Systemd Units Explained with Types and States here
- How To Use Systemctl to Manage Systemd Services and Units here
- Understanding and administering systemd here
- More Systemd Fun: The Blame Game And Stopping Services With Prejudice help
- Use systemd timers instead of cronjobs here