linux
Systemd
→ Systemd-run
Run with the current user environment, with cgroup quota :
systemd-run --user --scope sh -c 'echo hello ; sleep 10 ; echo $(pwd)'
systemd-run --user -pCPUQuota=200% --scope sh -c 'echo hello ; sleep 10 ; echo $(pwd)'
→ calendar syntax
# verify syntax https://stackoverflow.com/a/75625764/3865083
systemd-analyze calendar 'Mon..Fri *-*-01' 'Mon *-*-02..03' --iterations 10
→ Journalctl
→ Filter
It centralizes all the systemd logs. You can filter by many criteria. It has a handy command completion:
journalctl _COMM=prometheus --since '2021-11-01 11:00' --until '2021-11-01 12:00'
→ Relative time filter
journalctl _COMM=prometheus --since -1h
→ Follow
This allows to see incoming logs:
journalctl _COMM=sshd -f
→ Kernel
journalctl -k
→ Boot
journalctl -b
→ Priority
0: Emergency. The system is unusable.
1: Alert. A condition has been flagged that should be corrected immediately.
2: Critical. This covers crashes, coredumps, and significant failures in primary applications.
3: Error. An error has been reported, but it is not considered severe.
4: Warning. Brings a condition to your attention that, if ignored, may become an error.
5: Notice. Used to report events that are unusual, but not errors.
6: Information. Regular operational messages. These do not require action.
7: Debug. Messages put into applications to make it easier for them to debug them.
→ Edit systemd files
The system files are located in /usr/lib/systemd/system
and are overwriten when the system get updated.
There is two options to make your own unit:
- create a systemd file in
/etc/systemd/system
: it will overwrite the system's one - run
systemctl edit <service-name>
: it will add content into/etc/systemd/system/<service>.service.d/override.conf
. Note that it does not need daemon-reload and can only append config rows.
→ Cleanup journal
journalctl --disk-usage
journalctl --vacuum-size=2G
→ Get logs from service
journalctl -u matrix-synapse.service -f -n 1000
→ Redirect docker to journal
logging:
driver: journald
options:
tag: my-docker-app
→ Users
Users units are in both :
/usr/lib/systemd/user/
~/.config/systemd/
users unit does not have access to system units
This page was last modified: