User Tools

Site Tools


linux:systemd

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

linux:systemd [2019/01/21 11:16] (current)
seanburns created
Line 1: Line 1:
 +<​markdown>​
 +# systemd Notes
 +## Date: Mon Oct  1 12:55:38 EDT 2018
  
 +Some notes on *systemd*:
 +
 +* systemd is an init system that aims to provide better boot time
 +  (through parallelization) and a better way to manage services and
 +  processes.
 +* all services on a Linux system are assigned a control group (cgroup). This
 +  will be important for when we install web services (servers) on our
 +  systems.
 +* on killing services: the problem with previous init is that sometimes child
 +  processes do not die when you close parent processes. E.g., something like
 +  this may not kill all http processes:
 +
 +```bash
 +killall httpd
 +```
 +
 +* but because of cgroups, ``kill`` is thorough and all child processes die and
 +  are not be reassigned a new PID.
 +* to do this, systemd places all process in control groups: *cgroups*. These
 +  groups are named after their processes. Services include the likes of httpd
 +  for web services, sshd for ssh services, mysqld for mysql services, and so
 +  forth. When a process, like httpd, spawns a new process, that new sub-process
 +  remains in the control group.
 +
 +``` bash
 +systemctl kill httpd.service
 +```
 +
 +Traditionally,​ we might use the ``ps`` command to view processes:
 +
 +```bash
 +ps xaf 
 +# show systemd info
 +ps xawf -eo pid,​user,​cgroups,​args
 +```
 +
 +Instead of the above command, we can use the following. This shows the cgroup
 +hierarchy in a tree format:
 +
 +```bash
 +systemd-cgls
 +```
 +
 +``journalctl`` replaces ``/​var/​log/​messages`` from the SysV init world. To view
 +journal entries, simply type:
 +
 +``` bash
 +journalctl
 +```
 +
 +If you ``tab tab`` after typing ``journalctl``,​ command line completion will
 +provide additional options (see man page: ``man 7 systemd.journal-fields`` and
 +see ``man man`` for numbering options). For example:
 +
 +```bash
 +journalctl _UID=1000
 +```
 +
 +The above shows journal entries related to userid of 1000, which is my user id.
 +We can see all user IDs by concatenating (``cat``) the passwd file. Here I look
 +at journal entries for ``chronyd``,​ with a userid of 992. This is a service
 +that manages the system'​s time:
 +
 +```bash
 +cat /etc/passwd
 +journalctl _UID=992
 +```
 +
 +## Various useful commands: see:
 +
 +```bash
 +man systemctl
 +```
 +
 +<pre bash>
 +# list units in memory ​
 +systemctl list-units
 +
 +# list sockets in memory
 +systemctl list-sockets
 +
 +# get status, start, stop, reload, restart a unit, e.g., sshd
 +systemctl status sshd.service
 +systemctl start sshd.service
 +systemctl stop sshd.service
 +systemctl reload sshd.service
 +systemctl restart sshd.service
 +systemctl reload-or-restart sshd.service
 +
 +# enable, disable sshd 
 +systemctl enable sshd.service
 +systemctl disable sshd.service
 +
 +# ask systemctl if enabled
 +systemctl is-enabled sshd.service
 +
 +# System: reboot, poweroff, or suspend
 +systemctl reboot
 +systemctl poweroff
 +systemctl suspend
 +
 +# to show changes to the system
 +systemd-delta ​
 +
 +# to list control groups and processes
 +systemd-cgls
 +
 +# to list real-time control group process, resource usage, and memory usage
 +systemd-cgtop
 +
 +# instead of grepping for failed processes/​services:​
 +systemctl --state failed
 +
 +# to list services
 +systemctl list-unit-files -t service
 +
 +# to change resource usage for the sshd service, where 1024 is the default:
 +systemctl set-property --runtime sshd CPUShares=1200
 +
 +# to examine boot time:
 +systemd-analyze
 +
 +# list logs
 +journalctl ​
 +
 +# list logs from a specified boot
 +journalctl -b
 +
 +# like tail -- follow in real-time
 +journalctl -f
 +
 +# show logs for specific systemd unit
 +journalctl -u sshd.service
 +</​pre>​
 +</​markdown>​
linux/systemd.txt ยท Last modified: 2019/01/21 11:16 by seanburns