Difference between revisions of "Systemd"
From Christoph's Personal Wiki
(New page: '''systemd''' is a suite of system management daemons, libraries, and utilities designed as a central management and configuration platform for the Linux computer operating system. ==Exam...) |
|||
Line 3: | Line 3: | ||
==Example usage== | ==Example usage== | ||
+ | * Check if you are running "init" or "systemd": | ||
+ | $ cat /proc/1/comm | ||
+ | systemd | ||
+ | |||
+ | * Restart network: | ||
+ | $ systemctl restart network.target | ||
+ | |||
+ | * stop and mask the firewalld service (see: [[CentOS#Iptables_vs._firewalld|iptables vs. firewalld]]): | ||
+ | |||
+ | $ systemctl stop firewalld | ||
+ | $ systemctl mask firewalld | ||
+ | |||
+ | * Miscellaneous: | ||
$ systemctl list-units | $ systemctl list-units | ||
$ systemctl list-units -t service | $ systemctl list-units -t service | ||
Line 21: | Line 34: | ||
ACTIVE = The high-level unit activation state, i.e. generalization of SUB. | ACTIVE = The high-level unit activation state, i.e. generalization of SUB. | ||
SUB = The low-level unit activation state, values depend on unit type. | SUB = The low-level unit activation state, values depend on unit type. | ||
+ | |||
+ | ==systemd-analyze== | ||
+ | |||
+ | * Analyze system boot-up performance | ||
+ | $ systemd-analyze | ||
+ | Startup finished in 5.223s (kernel) + 7.781s (userspace) = 13.004s | ||
+ | |||
+ | * Plot all dependencies of any unit whose name starts with "avahi-daemon": | ||
+ | $ systemd-analyze dot 'avahi-daemon.*' | dot -Tsvg > avahi.svg | ||
+ | $ eog avahi.svg | ||
+ | |||
+ | * Plot the dependencies between all known target units: | ||
+ | |||
+ | $ systemd-analyze dot --to-pattern='*.target' --from-pattern='*.target' | dot -Tsvg > targets.svg | ||
+ | $ eog targets.svg | ||
==journalctl== | ==journalctl== | ||
Line 26: | Line 54: | ||
$ journalctl | $ journalctl | ||
+ | $ journalctl | grep -Ei 'error|fail' | ||
$ journalctl -b # show only logs from this boot | $ journalctl -b # show only logs from this boot | ||
$ journalctl -b -1 # show only logs from previous boot | $ journalctl -b -1 # show only logs from previous boot | ||
$ journalctl -u ssh # show only logs for a given unit | $ journalctl -u ssh # show only logs for a given unit | ||
− | |||
$ journalctl -f # follow (somewhat analogous to `tail -f /var/log/messages`) | $ journalctl -f # follow (somewhat analogous to `tail -f /var/log/messages`) | ||
+ | $ journalctl -f -u ssh.service # show only logs for ssh unit and follow | ||
+ | |||
+ | ==timedatectl== | ||
+ | ''Note: Most of these commands will need to be run as either root or sudo and is only valid for systems using systemd.'' | ||
+ | |||
+ | * List all available timezones on your computer/server: | ||
+ | $ timedatectl list-timezones | ||
+ | |||
+ | * Set your computer's/server's timezone: | ||
+ | $ timedatectl set-timezone region/timezone | ||
+ | |||
+ | * For instance, to set your timezone to United States Pacific Time (PST; -8GMT): | ||
+ | $ timedatectl set-timezone America/Vancouver | ||
+ | |||
+ | Your system will be updated to use the selected timezone. You can verify with: | ||
+ | $ timedatectl | ||
+ | <pre> | ||
+ | Local time: Fri, 2012-11-02 09:26:46 CET | ||
+ | Universal time: Fri, 2012-11-02 08:26:46 UTC | ||
+ | RTC time: Fri, 2012-11-02 08:26:45 | ||
+ | Timezone: Europe/Warsaw | ||
+ | UTC offset: +0100 | ||
+ | NTP enabled: no | ||
+ | NTP synchronized: no | ||
+ | RTC in local TZ: no | ||
+ | DST active: no | ||
+ | Last DST change: CEST → CET, DST became inactive | ||
+ | Sun, 2012-10-28 02:59:59 CEST | ||
+ | Sun, 2012-10-28 02:00:00 CET | ||
+ | Next DST change: CET → CEST, DST will become active | ||
+ | the clock will jump one hour forward | ||
+ | Sun, 2013-03-31 01:59:59 CET | ||
+ | Sun, 2013-03-31 03:00:00 CEST | ||
+ | </pre> | ||
+ | |||
+ | * Enable an NTP daemon (chronyd): | ||
+ | |||
+ | $ timedatectl set-ntp true | ||
+ | ==== AUTHENTICATING FOR org.freedesktop.timedate1.set-ntp === | ||
+ | Authentication is required to control whether network time synchronization shall be enabled. | ||
+ | Authenticating as: user | ||
+ | Password: ******** | ||
+ | ==== AUTHENTICATION COMPLETE === | ||
+ | |||
+ | $ systemctl status chronyd.service | ||
+ | chronyd.service - NTP client/server | ||
+ | Loaded: loaded (/lib/systemd/system/chronyd.service; enabled) | ||
+ | Active: active (running) since Fri, 2012-11-02 09:36:25 CET; 5s ago | ||
+ | ... | ||
==External links== | ==External links== |
Revision as of 02:03, 14 May 2015
systemd is a suite of system management daemons, libraries, and utilities designed as a central management and configuration platform for the Linux computer operating system.
Example usage
- Check if you are running "init" or "systemd":
$ cat /proc/1/comm systemd
- Restart network:
$ systemctl restart network.target
- stop and mask the firewalld service (see: iptables vs. firewalld):
$ systemctl stop firewalld $ systemctl mask firewalld
- Miscellaneous:
$ systemctl list-units $ systemctl list-units -t service $ systemctl list-units | grep .service $ systemctl list-units -t target $ systemctl list-unit-files $ systemctl list-unit-files -t target $ systemctl list-dependencies multi-user.target $ systemctl [status|stop|enable|disable|restart] ssh.service $ systemctl is-enabled ssh.service $ systemctl [reboot|poweroff|suspend]
$ systemctl --failed UNIT LOAD ACTIVE SUB DESCRIPTION ● pollinate.service loaded failed failed Seed the pseudo random number generator on first boot ● vboxadd.service loaded failed failed LSB: VirtualBox Linux Additions kernel modules LOAD = Reflects whether the unit definition was properly loaded. ACTIVE = The high-level unit activation state, i.e. generalization of SUB. SUB = The low-level unit activation state, values depend on unit type.
systemd-analyze
- Analyze system boot-up performance
$ systemd-analyze Startup finished in 5.223s (kernel) + 7.781s (userspace) = 13.004s
- Plot all dependencies of any unit whose name starts with "avahi-daemon":
$ systemd-analyze dot 'avahi-daemon.*' | dot -Tsvg > avahi.svg $ eog avahi.svg
- Plot the dependencies between all known target units:
$ systemd-analyze dot --to-pattern='*.target' --from-pattern='*.target' | dot -Tsvg > targets.svg $ eog targets.svg
journalctl
Note: combine with syslog-ng for backward compatibility.
$ journalctl $ journalctl | grep -Ei 'error|fail' $ journalctl -b # show only logs from this boot $ journalctl -b -1 # show only logs from previous boot $ journalctl -u ssh # show only logs for a given unit $ journalctl -f # follow (somewhat analogous to `tail -f /var/log/messages`) $ journalctl -f -u ssh.service # show only logs for ssh unit and follow
timedatectl
Note: Most of these commands will need to be run as either root or sudo and is only valid for systems using systemd.
- List all available timezones on your computer/server:
$ timedatectl list-timezones
- Set your computer's/server's timezone:
$ timedatectl set-timezone region/timezone
- For instance, to set your timezone to United States Pacific Time (PST; -8GMT):
$ timedatectl set-timezone America/Vancouver
Your system will be updated to use the selected timezone. You can verify with:
$ timedatectl
Local time: Fri, 2012-11-02 09:26:46 CET Universal time: Fri, 2012-11-02 08:26:46 UTC RTC time: Fri, 2012-11-02 08:26:45 Timezone: Europe/Warsaw UTC offset: +0100 NTP enabled: no NTP synchronized: no RTC in local TZ: no DST active: no Last DST change: CEST → CET, DST became inactive Sun, 2012-10-28 02:59:59 CEST Sun, 2012-10-28 02:00:00 CET Next DST change: CET → CEST, DST will become active the clock will jump one hour forward Sun, 2013-03-31 01:59:59 CET Sun, 2013-03-31 03:00:00 CEST
- Enable an NTP daemon (chronyd):
$ timedatectl set-ntp true ==== AUTHENTICATING FOR org.freedesktop.timedate1.set-ntp === Authentication is required to control whether network time synchronization shall be enabled. Authenticating as: user Password: ******** ==== AUTHENTICATION COMPLETE === $ systemctl status chronyd.service chronyd.service - NTP client/server Loaded: loaded (/lib/systemd/system/chronyd.service; enabled) Active: active (running) since Fri, 2012-11-02 09:36:25 CET; 5s ago ...