Systemd: Difference between revisions

From DWIKI
(17 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 46: Line 57:
  systemctl list-timers --all
  systemctl list-timers --all


=== Create timer ===
=== Enable timer ===


  systemctl enable fstrim.timer
  systemctl enable fstrim.timer
Line 61: Line 72:


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 =
= FAQ =


== Fix journal size ==
== Analyze boot processes ==


  journalctl --vacuum-time=10d
  systemd-analyze blame


or


  journalctl --vacuum-size=1G
== remove nameservers from /run/systemd/resolve/resolv.conf ==
Edit /etc/systemd/resolved.conf
Take out the DNS line and
  systemctl restart systemd-resolved


===Journal settings===
/etc/systemd/journald.conf
SystemMaxUse=1G
and then
systemctl restart systemd-journald.service


== gateway4 has been deprecated ==
Using routes:
routes:
- to: default
  via: 192.168.1.1


== Analyze boot processes ==
== Systemd and DNS, list nameservers used ==


  systemd-analyze blame
  resolvectl status


 


 
===Change nameserversers resolvectl uses===
====On Ubuntu====
Edit the netplan file
netplan generate
netplan apply


 


== Systemd and DNS ==
====Without editing netplan====
So does NOT update your netplan config!


  resolvectl status
  resolvectl dns eth0 8.8.8.8 8.8.4.4


=== 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 100: Line 121:


  systemctl restart systemd-resolved
  systemctl restart systemd-resolved
     
        
        


 
=== Add nameserver ===
Sacrifice a chicken
 


=== Flush caches ===
=== Flush caches ===
 
# thing from the past
  systemd-resolve --flush-caches
  systemd-resolve --flush-caches
now use
resolvectl flush-caches


== All status ==
== All status ==

Revision as of 13:01, 6 March 2025

 


Documentation

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

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

  1. thing from the past
systemd-resolve --flush-caches

now use

resolvectl 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