Systemd: Difference between revisions

From DWIKI
Line 33: Line 33:
===List enabled services===
===List enabled services===
  systemctl list-unit-files --state=enabled
  systemctl list-unit-files --state=enabled
===Edit systemd service file===
systemctl edit --full my.service


== Timers ==
== Timers ==

Revision as of 14:19, 3 July 2023

 


Documentation

Locations

/etc/systemd
/usr/lib/systemd/
/lib/systemd

 


HOWTO

Services

List enabled services

systemctl list-unit-files --state=enabled


Edit systemd service file

systemctl edit --full my.service

Timers

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

 

 

 

Systemd and DNS

resolvectl status

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

systemd-resolve --flush-caches

All status

systemctl status -a

syslog spam

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

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