Systemd: Difference between revisions
From DWIKI
mNo edit summary |
m (→FAQ) |
||
(36 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
| |||
= Documentation = | = Documentation = | ||
Line 5: | Line 8: | ||
*[http://www.freedesktop.org/wiki/Software/systemd/ http://www.freedesktop.org/wiki/Software/systemd/] | *[http://www.freedesktop.org/wiki/Software/systemd/ http://www.freedesktop.org/wiki/Software/systemd/] | ||
*[https://wiki.ubuntu.com/systemd https://wiki.ubuntu.com/systemd] | *[https://wiki.ubuntu.com/systemd https://wiki.ubuntu.com/systemd] | ||
*[https://wiki.archlinux.org/index.php/Systemd Creating systemd service] | |||
*[https://wiki.ubuntu.com/SystemdForUpstartUsers https://wiki.ubuntu.com/SystemdForUpstartUsers] | *[https://wiki.ubuntu.com/SystemdForUpstartUsers https://wiki.ubuntu.com/SystemdForUpstartUsers] | ||
*[https://www.digitalocean.com/community/tutorials/how-to-use-systemctl-to-manage-systemd-services-and-units How To Use Systemctl to Manage Systemd Services and Units] | *[https://www.digitalocean.com/community/tutorials/how-to-use-systemctl-to-manage-systemd-services-and-units How To Use Systemctl to Manage Systemd Services and Units] | ||
Line 11: | Line 15: | ||
*[https://www.freedesktop.org/wiki/Software/systemd/PredictableNetworkInterfaceNames/ Predictable Network Interface Names] | *[https://www.freedesktop.org/wiki/Software/systemd/PredictableNetworkInterfaceNames/ Predictable Network Interface Names] | ||
*[[https://blog.darknedgy.net/technology/2020/05/02/0/index.html#tech-critique https://blog.darknedgy.net/technology/2020/05/02/0/index.html#tech-critique] | *[[https://blog.darknedgy.net/technology/2020/05/02/0/index.html#tech-critique https://blog.darknedgy.net/technology/2020/05/02/0/index.html#tech-critique] | ||
*[https://mohsensy.github.io/sysadmin/2018/08/19/systemd-service-tutorial.html Systemd service tutorial] | |||
*[https://www.freedesktop.org/wiki/Software/systemd/dbus/ https://www.freedesktop.org/wiki/Software/systemd/dbus/ Systemd and dbus] | |||
*[https://www.thegeekdiary.com/how-to-boot-into-rescue-mode-or-emergency-mode-through-systemd-in-centos-rhel-7-and-8/ Single user/emergency] | |||
= Locations = | |||
/etc/systemd | /etc/systemd | ||
/usr/lib/systemd/ | /usr/lib/systemd/ | ||
/lib/systemd | /lib/systemd | ||
=FAQ= | | ||
= 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://opensource.com/article/20/7/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 | |||
=== 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 | |||
== remove nameservers from /run/systemd/resolve/resolv.conf == | |||
Edit /etc/systemd/resolved.conf | |||
Take out the DNS line and | |||
systemctl restart systemd-resolved | |||
== gateway4 has been deprecated == | |||
Using routes: | |||
routes: | |||
- to: default | |||
via: 192.168.1.1 | |||
== Systemd and DNS, list nameservers used == | |||
resolvectl status | |||
===Change nameserversers resolvectl uses=== | |||
====On Ubuntu==== | |||
Edit the netplan file | |||
netplan generate | |||
netplan apply | |||
====Without editing netplan==== | |||
So does NOT update your netplan config! | |||
resolvectl dns eth0 8.8.8.8 8.8.4.4 | |||
=== Failed to get global data: Unit dbus-org.freedesktop.resolve1.service not found. === | |||
Means systemd-resolved is not running | |||
Restart: | |||
systemctl restart systemd-resolved | |||
=== Flush caches === | |||
# thing from the past | |||
systemd-resolve --flush-caches | |||
now use | |||
resolvectl flush-caches | |||
== All status == | |||
systemctl status -a | systemctl status -a | ||
==syslog spam== | == syslog spam == | ||
https://psyq123.wordpress.com/2015/06/29/if-you-get-a-lot-of-logspam-from-systemd-in-your-varlogsyslog-this-might-help/ | |||
[https://psyq123.wordpress.com/2015/06/29/if-you-get-a-lot-of-logspam-from-systemd-in-your-varlogsyslog-this-might-help/ https://psyq123.wordpress.com/2015/06/29/if-you-get-a-lot-of-logspam-from-systemd-in-your-varlogsyslog-this-might-help/] | |||
== list available services == | |||
systemctl list-unit-files | systemctl list-unit-files | ||
or | or | ||
systemctl list-units | systemctl list-units | ||
| |||
== normal interface names == | |||
net.ifnames=0 | net.ifnames=0 | ||
==Show failed services== | == Show failed services == | ||
systemctl --failed | systemctl --failed | ||
| |||
== systemd: Started Session == | |||
Change loglevel to notice in /etc/systemd/system.conf | Change loglevel to notice in /etc/systemd/system.conf | ||
systemctl daemon-reexec | systemctl daemon-reexec | ||
==Status== | |||
=== Active: inactive (dead) === | |||
parameter ActiveState would return inactive | |||
SubState returns dead |
Revision as of 13:01, 6 March 2025
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
remove nameservers from /run/systemd/resolve/resolv.conf
Edit /etc/systemd/resolved.conf Take out the DNS line and
systemctl restart systemd-resolved
gateway4 has been deprecated
Using routes:
routes: - to: default via: 192.168.1.1
Systemd and DNS, list nameservers used
resolvectl status
Change nameserversers resolvectl uses
On Ubuntu
Edit the netplan file
netplan generate netplan apply
Without editing netplan
So does NOT update your netplan config!
resolvectl dns eth0 8.8.8.8 8.8.4.4
Failed to get global data: Unit dbus-org.freedesktop.resolve1.service not found.
Means systemd-resolved is not running
Restart:
systemctl restart systemd-resolved
Flush caches
- thing from the past
systemd-resolve --flush-caches
now use
resolvectl 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