Skip to content

Commit 969a4f7

Browse files
author
Paul Cobbaut
committed
several systemd updates
1 parent 68b3631 commit 969a4f7

File tree

1 file changed

+76
-54
lines changed

1 file changed

+76
-54
lines changed

modules/systemd/030_systemd_theory.xml

Lines changed: 76 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,15 @@ root@debian8:~#</screen>
2121
<?hard-pagebreak?>
2222
<section><title>systemd targets</title>
2323
<para>The first command to learn is <command>systemctl list-units --type=target</command> (or the shorter version <command>systemctl -t target</command>). It will show you the different targets on the system.</para>
24-
<screen>[root@rhel7 ~]# systemctl list-units --type=target
24+
<screen>[root@rhel71 ~]# <command>systemctl -t target</command>
2525
UNIT LOAD ACTIVE SUB DESCRIPTION
2626
basic.target loaded active active Basic System
2727
cryptsetup.target loaded active active Encrypted Volumes
2828
getty.target loaded active active Login Prompts
29-
graphical.target loaded active active Graphical Interface
3029
local-fs-pre.target loaded active active Local File Systems (Pre)
3130
local-fs.target loaded active active Local File Systems
3231
multi-user.target loaded active active Multi-User System
3332
network.target loaded active active Network
34-
nfs.target loaded active active Network File System Server
3533
paths.target loaded active active Paths
3634
remote-fs.target loaded active active Remote File Systems
3735
slices.target loaded active active Slices
@@ -44,19 +42,20 @@ LOAD = Reflects whether the unit definition was properly loaded.
4442
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
4543
SUB = The low-level unit activation state, values depend on unit type.
4644

47-
16 loaded units listed. Pass --all to see loaded but inactive units, too.
45+
14 loaded units listed. Pass --all to see loaded but inactive units, too.
4846
To show all installed unit files use 'systemctl list-unit-files'.
49-
[root@rhel7 ~]#</screen>
47+
[root@rhel71 ~]#</screen>
5048
<para>Targets are the replacement of runlevels and define specific points to reach when booting the system. For example the <command>graphical.target</command> is reached when you get a graphical interface, and the <command>nfs.target</command> requires a running nfs server.</para>
5149
<para>To switch to a target (for example <command>multi-user.target</command>), we now use <command>systemctl isolate</command> (instead of the equivalent <command>init 3</command> to change the runlevel).</para>
52-
<screen>[root@rhel7 ~]# ps fax | wc -l
50+
<para>This screenshot shows a <command>Red Hat Enterprise Linux 7</command> server switching from a graphical interface to command line (decreasing the number of running processes).</para>
51+
<screen>[root@rhel7 ~]# <command>ps fax | wc -l</command>
5352
169
54-
[root@rhel7 ~]# systemctl isolate multi-user.target
55-
[root@rhel7 ~]# ps fax | wc -l
53+
[root@rhel7 ~]# <command>systemctl isolate multi-user.target</command>
54+
[root@rhel7 ~]# <command>ps fax | wc -l</command>
5655
129
5756
[root@rhel7 ~]#</screen>
5857
<para>To change the default target, we again use this <command>systemctl</command> command (instead of editing the <command>/etc/inittab</command> file).</para>
59-
<screen>[root@rhel7 ~]# systemctl enable multi-user.target --force
58+
<screen>[root@rhel7 ~]# <command>systemctl enable multi-user.target --force</command>
6059
rm '/etc/systemd/system/default.target'
6160
ln -s '/usr/lib/systemd/system/multi-user.target' '/etc/systemd/system/default\
6261
.target'
@@ -65,80 +64,103 @@ ln -s '/usr/lib/systemd/system/multi-user.target' '/etc/systemd/system/default\
6564
</section>
6665
<?hard-pagebreak?>
6766
<section><title>systemd dependencies</title>
68-
<para>Dependencies are no longer defined by alfabetical order of running scripts, but by configuration in <command>/etc/systemd/system/</command>. For example here are the required services for the <command>multi-user.target</command> on Red Hat Enterprise 7.</para>
69-
<screen>[root@rhel7 ~]# ls /etc/systemd/system/multi-user.target.wants/
70-
abrt-ccpp.service hypervkvpd.service postfix.service
71-
abrtd.service hypervvssd.service remote-fs.target
72-
abrt-oops.service irqbalance.service rhsmcertd.service
73-
abrt-vmcore.service ksm.service rngd.service
74-
abrt-xorg.service ksmtuned.service rpcbind.service
75-
atd.service libstoragemgmt.service rsyslog.service
76-
auditd.service libvirtd.service smartd.service
77-
avahi-daemon.service mdmonitor.service sshd.service
78-
chronyd.service ModemManager.service sysstat.service
79-
crond.service NetworkManager.service tuned.service
80-
cups.path nfs.target vmtoolsd.service
81-
[root@rhel7 ~]#</screen>
82-
<para>Debian8 is not fully migrated yet.</para>
83-
<screen>root@debian8:~# ls /etc/systemd/system/multi-user.target.wants/
84-
anacron.service binfmt-support.service pppd-dns.service ssh.service
85-
atd.service fancontrol.service remote-fs.target
86-
avahi-daemon.service lm-sensors.service rsyslog.service</screen>
67+
<para>Dependencies are no longer defined by alfabetical order of running scripts, but by configuration in <command>/etc/systemd/system/</command>. For example here are the required services for the <command>multi-user.target</command> on Red Hat Enterprise 7.1.</para>
68+
<screen>[root@rhel71 ~]# <command>cat /etc/redhat-release</command>
69+
Red Hat Enterprise Linux Server release 7.1 (Maipo)
70+
[root@rhel71 ~]# <command>ls /etc/systemd/system/multi-user.target.wants/</command>
71+
abrt-ccpp.service auditd.service postfix.service sysstat.service
72+
abrtd.service chronyd.service remote-fs.target tuned.service
73+
abrt-oops.service crond.service rhsmcertd.service
74+
abrt-vmcore.service irqbalance.service rsyslog.service
75+
abrt-xorg.service NetworkManager.service sshd.service
76+
[root@rhel71 ~]#</screen>
77+
<para>Below a screenshot from Debian (stretch/sid is Debian 9). There is already a lot of <command>systemd</command> in Debian 8 and 9 (less than in RHEL7).</para>
78+
<screen>root@debian9:~# <command>cat /etc/debian_version</command>
79+
stretch/sid
80+
root@debian9:~# <command>ls /etc/systemd/system/multi-user.target.wants/</command>
81+
anacron.service binfmt-support.service lm-sensors.service rsyslog.service
82+
atd.service cron.service pppd-dns.service ssh.service
83+
avahi-daemon.service fancontrol.service remote-fs.target
84+
root@debian9:~#</screen>
8785
<para>Typical <command>rc scripts</command> are replaced with services. Issue the <command>systemctl list-units -t service --all</command> (or <command>systemctl -at service</command>) to get a list of all services on your system.</para>
88-
<screen>[root@rhel7 ~]# systemctl -at service | head -5 | column -t | cut -c1-78
86+
<screen>[root@rhel7 ~]# <command>systemctl -at service | head -5 | column -t | cut -c1-78</command>
8987
UNIT LOAD ACTIVE SUB DESCRIPTION
9088
abrt-ccpp.service loaded active exited Install ABRT coredump
9189
abrt-oops.service loaded active running ABRT kernel log
9290
abrt-vmcore.service loaded inactive dead Harvest vmcores for
9391
abrt-xorg.service loaded active running ABRT Xorg log
9492
[root@rhel7 ~]#</screen>
95-
<para>And here an example on how to see the status of the <command>sshd</command> service.</para>
96-
<screen>[root@rhel7 ~]# systemctl status sshd.service
93+
</section>
94+
<?hard-pagebreak?>
95+
<section><title>service status</title>
96+
<para>Below is a (truncated) screenshot showing how to see the status of the <command>sshd</command> service. (This RHEL server was attacked using brute force ssh on 2 August 2015.)</para>
97+
<screen>[root@rhel71 ~]# <command>systemctl status sshd.service</command>
98+
9799
sshd.service - OpenSSH server daemon
98-
Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled)
99-
Active: active (running) since Wed 2014-09-10 13:42:21 CEST; 55min ago
100-
Main PID: 1400 (sshd)
101-
CGroup: /system.slice/sshd.service
102-
--1400 /usr/sbin/sshd -D
100+
Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled)
101+
Active: active (running) since Wed 2015-07-29 12:00:10 CEST; 1 weeks 0 days ago
102+
Main PID: 1123 (sshd)
103+
CGroup: /system.slice/sshd.service
104+
└─1123 /usr/sbin/sshd -D
103105

104-
Sep 10 13:42:21 rhel7 systemd[1]: Started OpenSSH server daemon.
105-
Sep 10 13:42:21 rhel7 sshd[1400]: Server listening on 0.0.0.0 port 22.
106-
Sep 10 13:42:21 rhel7 sshd[1400]: Server listening on :: port 22.
107-
[root@rhel7 ~]#</screen>
106+
Aug 02 16:45:24 rhel71 sshd[12704]: Failed password for root from 43.229.53.79
107+
Aug 02 18:15:28 rhel71 sshd[12872]: pam_unix(sshd:auth): authentication failur
108+
Aug 02 18:15:28 rhel71 sshd[12872]: pam_succeed_if(sshd:auth): requirement "ui
109+
Aug 02 18:15:30 rhel71 sshd[12872]: Failed password for root from 43.229.53.79
110+
Aug 02 18:15:30 rhel71 sshd[12872]: pam_succeed_if(sshd:auth): requirement "ui
111+
Aug 02 18:15:32 rhel71 sshd[12872]: Failed password for root from 43.229.53.79
112+
Aug 02 18:15:32 rhel71 sshd[12872]: pam_succeed_if(sshd:auth): requirement "ui
113+
Aug 02 18:15:34 rhel71 sshd[12872]: Failed password for root from 43.229.53.79
114+
Aug 02 18:15:34 rhel71 sshd[12872]: Received disconnect from 43.229.53.79: 11:
115+
Aug 03 10:21:11 rhel71 sshd[14616]: pam_unix(sshd:auth): authentication failur
116+
Aug 03 10:21:11 rhel71 sshd[14616]: pam_succeed_if(sshd:auth): requirement "ui
117+
Aug 03 10:21:13 rhel71 sshd[14616]: Failed password for root from 119.188.7.14
118+
Aug 03 10:21:13 rhel71 sshd[14616]: Received disconnect from 119.188.7.143: 11
119+
Aug 03 14:20:03 rhel71 sshd[15083]: Accepted password for root from 192.168.1.
120+
Hint: Some lines were ellipsized, use -l to show in full.
121+
[root@rhel71 ~]#</screen>
122+
<para>This <command>systemd</command> feature does not work by default on <command>Debian 8/9</command> because <command>init</command> has pid 1. It only works when the system is booted with <command>systemd</command> as pid 1.</para>
123+
<screen>root@debian8:~# <command>systemctl status sshd</command>
124+
Failed to get D-Bus connection: Operation not permitted
125+
root@debian8:~# <command>systemctl status ssh</command>
126+
Failed to get D-Bus connection: Operation not permitted
127+
root@debian8:~# <command>service ssh status</command>
128+
sshd is running.
129+
root@debian8:~#</screen>
108130
</section>
109131
<?hard-pagebreak?>
110-
<section><title>systemd services</title>
132+
<section><title>systemd services configuration</title>
111133
<para>The <command>chkconfig</command> and <command>service</command> commands are considered 'legacy'. They are replaced with <command>systemctl</command>.</para>
112134
<para>This screenshot shows the new way to start and stop a service.</para>
113-
<screen>[root@rhel7 ~]# systemctl start crond.service
114-
[root@rhel7 ~]# systemctl show crond.service | grep State
135+
<screen>[root@rhel7 ~]# <command>systemctl start crond.service</command>
136+
[root@rhel7 ~]# <command>systemctl show crond.service | grep State</command>
115137
LoadState=loaded
116138
ActiveState=active
117139
SubState=running
118140
UnitFileState=enabled
119-
[root@rhel7 ~]# systemctl stop crond.service
120-
[root@rhel7 ~]# systemctl show crond.service | grep State
141+
[root@rhel7 ~]# <command>systemctl stop crond.service</command>
142+
[root@rhel7 ~]# <command>systemctl show crond.service | grep State</command>
121143
LoadState=loaded
122144
ActiveState=inactive
123145
SubState=dead
124146
UnitFileState=enabled
125147
[root@rhel7 ~]#</screen>
126148
<para>And here is the new way to stop and disable a service.</para>
127-
<screen>[root@rhel7 ~]# systemctl stop crond.service
128-
[root@rhel7 ~]# systemctl disable crond.service
149+
<screen>[root@rhel7 ~]# <command>systemctl stop crond.service</command>
150+
[root@rhel7 ~]# <command>systemctl disable crond.service</command>
129151
rm '/etc/systemd/system/multi-user.target.wants/crond.service'
130-
[root@rhel7 ~]# systemctl show crond.service | grep State
152+
[root@rhel7 ~]# <command>systemctl show crond.service | grep State</command>
131153
LoadState=loaded
132154
ActiveState=inactive
133155
SubState=dead
134156
UnitFileState=disabled
135157
[root@rhel7 ~]#</screen>
136158
<para>This screenshot shows how to enable and start the service again.</para>
137-
<screen>[root@rhel7 ~]# systemctl enable crond.service
159+
<screen>[root@rhel7 ~]# <command>systemctl enable crond.service</command>
138160
ln -s '/usr/lib/systemd/system/crond.service' '/etc/systemd/system/multi-user.\
139161
target.wants/crond.service'
140-
[root@rhel7 ~]# systemctl start crond.service
141-
[root@rhel7 ~]# systemctl show crond.service | grep State
162+
[root@rhel7 ~]# <command>systemctl start crond.service</command>
163+
[root@rhel7 ~]# <command>systemctl show crond.service | grep State</command>
142164
LoadState=loaded
143165
ActiveState=active
144166
SubState=running
@@ -148,13 +170,13 @@ UnitFileState=enabled
148170
<?hard-pagebreak?>
149171
<section><title>systemd signalling</title>
150172
<para>You can also use <command>systemd</command> to <command>kill</command> problematic services.</para>
151-
<screen>[root@rhel7 ~]# systemctl show crond.service | grep State
173+
<screen>[root@rhel7 ~]# <command>systemctl show crond.service | grep State</command>
152174
LoadState=loaded
153175
ActiveState=active
154176
SubState=running
155177
UnitFileState=enabled
156-
[root@rhel7 ~]# systemctl kill -s SIGKILL crond.service
157-
[root@rhel7 ~]# systemctl show crond.service | grep State
178+
[root@rhel7 ~]# <command>systemctl kill -s SIGKILL crond.service</command>
179+
[root@rhel7 ~]# <command>systemctl show crond.service | grep State</command>
158180
LoadState=loaded
159181
ActiveState=failed
160182
SubState=failed

0 commit comments

Comments
 (0)