Systemd: Difference between revisions
From DWIKI
m (→Create timer) |
m (→Flush caches) |
||
(10 intermediate revisions by the same user not shown) | |||
Line 29: | Line 29: | ||
= HOWTO = | = HOWTO = | ||
==systemctl verbose== | |||
SYSTEMD_LOG_LEVEL=debug systemctl start yourservice | |||
==Services== | |||
===List enabled services=== | |||
See https://www.baeldung.com/linux/systemctl-list-enabled-services | |||
systemctl list-unit-files --state=enabled | |||
===Edit systemd service file=== | |||
systemctl edit --full my.service | |||
== Timers == | == Timers == | ||
Line 34: | Line 45: | ||
*[https://opensource.com/article/20/7/systemd-timers https://opensource.com/article/20/7/systemd-timers] | *[https://opensource.com/article/20/7/systemd-timers https://opensource.com/article/20/7/systemd-timers] | ||
*[https://wiki.archlinux.org/title/Systemd/Timers https://wiki.archlinux.org/title/Systemd/Timers] | *[https://wiki.archlinux.org/title/Systemd/Timers https://wiki.archlinux.org/title/Systemd/Timers] | ||
*https://linuxhint.com/cron_systemd_timer/ also about random time | |||
man systemd.timer | man systemd.timer | ||
Line 62: | Line 73: | ||
And to get an email when service gets restarted: https://dev.to/setevoy/linux-systemd-unit-files-edit-restart-on-failure-and-email-notifications-5h3k | And to get an email when service gets restarted: https://dev.to/setevoy/linux-systemd-unit-files-edit-restart-on-failure-and-email-notifications-5h3k | ||
== | ==Logs== | ||
===View systemd logs=== | |||
journalctl -u postfix | |||
== | |||
= FAQ = | |||
== Analyze boot processes == | == Analyze boot processes == | ||
Line 83: | Line 84: | ||
systemd-analyze blame | systemd-analyze blame | ||
== gateway4 has been deprecated == | |||
Using routes: | |||
routes: | |||
- to: default | |||
via: 192.168.1.1 | |||
== Systemd and DNS == | |||
resolvectl status | |||
===Change nameserversers resolvectl uses=== | |||
====On Ubuntu==== | |||
Edit the netplan file | |||
netplan generate | |||
netplan apply | |||
=== Failed to get global data: Unit dbus-org.freedesktop.resolve1.service not found. === | === Failed to get global data: Unit dbus-org.freedesktop.resolve1.service not found. === | ||
Line 112: | Line 120: | ||
=== Flush caches === | === Flush caches === | ||
# thing from the past? | |||
systemd-resolve --flush-caches | systemd-resolve --flush-caches | ||
Latest revision as of 16:30, 21 November 2024
Documentation
- Useful systemd commands
- http://www.freedesktop.org/wiki/Software/systemd/
- https://wiki.ubuntu.com/systemd
- Creating systemd service
- https://wiki.ubuntu.com/SystemdForUpstartUsers
- How To Use Systemctl to Manage Systemd Services and Units
- How to switch from NetworkManager to systemd-networkd on Linux
- https://fedoraproject.org/wiki/SysVinit_to_Systemd_Cheatsheet
- Predictable Network Interface Names
- [https://blog.darknedgy.net/technology/2020/05/02/0/index.html#tech-critique
- Systemd service tutorial
- https://www.freedesktop.org/wiki/Software/systemd/dbus/ Systemd and dbus
- Single user/emergency
Locations
/etc/systemd /usr/lib/systemd/ /lib/systemd
HOWTO
systemctl verbose
SYSTEMD_LOG_LEVEL=debug systemctl start yourservice
Services
List enabled services
See https://www.baeldung.com/linux/systemctl-list-enabled-services
systemctl list-unit-files --state=enabled
Edit systemd service file
systemctl edit --full my.service
Timers
- https://opensource.com/article/20/7/systemd-timers
- https://wiki.archlinux.org/title/Systemd/Timers
- https://linuxhint.com/cron_systemd_timer/ also about random time
man systemd.timer
List active timers
systemctl list-timers
List all timers
systemctl list-timers --all
Enable timer
systemctl enable fstrim.timer
Auto restart crashed services
systemctl edit elasticsearch.service
add:
[Service] Restart=always
then
systemctl daemon-reload systemctl restart elasticsearch.service
And to get an email when service gets restarted: https://dev.to/setevoy/linux-systemd-unit-files-edit-restart-on-failure-and-email-notifications-5h3k
Logs
View systemd logs
journalctl -u postfix
FAQ
Analyze boot processes
systemd-analyze blame
gateway4 has been deprecated
Using routes:
routes: - to: default via: 192.168.1.1
Systemd and DNS
resolvectl status
Change nameserversers resolvectl uses
On Ubuntu
Edit the netplan file
netplan generate netplan apply
Failed to get global data: Unit dbus-org.freedesktop.resolve1.service not found.
Means systemd-resolved is not running
Restart:
systemctl restart systemd-resolved
Add nameserver
Sacrifice a chicken
Flush caches
- thing from the past?
systemd-resolve --flush-caches
All status
systemctl status -a
syslog spam
list available services
systemctl list-unit-files
or
systemctl list-units
normal interface names
net.ifnames=0
Show failed services
systemctl --failed
systemd: Started Session
Change loglevel to notice in /etc/systemd/system.conf
systemctl daemon-reexec
Status
Active: inactive (dead)
parameter ActiveState would return inactive
SubState returns dead