RHCSA Rapid Track
In this exercise, you will use systemctl to stop, start, restart, reload, enable, and disable a systemd-managed service.
Outcomes
You should be able to use the systemctl command to control systemd-managed services.
Log in as the student user on workstation using student as the password.
From workstation, run the lab services-control start command.
The command runs a start script that determines whether the host, servera, is reachable on the network.
The script also ensures that the sshd and chronyd services are running on servera.
[student@workstation ~]$lab services-control start
Use the ssh command to log in to
serveraas thestudentuser. The systems are configured to use SSH keys for authentication, and therefore a password is not required.[student@workstation ~]$ssh student@servera...output omitted...[student@servera ~]$Execute the systemctl restart and systemctl reload commands on the
sshdservice. Observe the different results of executing these commands.Display the status of the
sshdservice. Note the process ID of thesshddaemon.[student@servera ~]$systemctl status sshd● sshd.service - OpenSSH server daemon Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled) Active: active (running) since Wed 2019-02-06 23:50:42 EST; 9min ago Docs: man:sshd(8) man:sshd_config(5)Main PID: 759 (sshd)Tasks: 1 (limit: 11407) Memory: 5.9M ...output omitted...Press q to exit the command.
Restart the
sshdservice and view the status. The process ID of the daemon must change.[student@servera ~]$sudo systemctl restart sshd[sudo] password for student:student[student@servera ~]$systemctl status sshd● sshd.service - OpenSSH server daemon Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled) Active: active (running) since Wed 2019-02-06 23:50:42 EST; 9min ago Docs: man:sshd(8) man:sshd_config(5)Main PID: 1132 (sshd)Tasks: 1 (limit: 11407) Memory: 5.9M ...output omitted...In the preceding output, notice that the process ID changed from 759 to 1132 (on your system, the numbers likely will be different). Press q to exit the command.
Reload the
sshdservice and view the status. The process ID of the daemon must not change and connections are not interrupted.[student@servera ~]$sudo systemctl reload sshd[student@servera ~]$systemctl status sshd● sshd.service - OpenSSH server daemon Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled) Active: active (running) since Wed 2019-02-06 23:50:42 EST; 9min ago Docs: man:sshd(8) man:sshd_config(5)Main PID: 1132 (sshd)Tasks: 1 (limit: 11407) Memory: 5.9M ...output omitted...Press q to exit the command.
Verify that the
chronydservice is running.[student@servera ~]$systemctl status chronyd● chronyd.service - NTP client/server Loaded: loaded (/usr/lib/systemd/system/chronyd.service; enabled; vendor preset: enabled)Active:active(running) since Wed 2019-02-06 23:50:38 EST; 1h 25min ago ...output omitted...Press q to exit the command.
Stop the
chronydservice and view the status.[student@servera ~]$sudo systemctl stop chronyd[student@servera ~]$systemctl status chronyd● chronyd.service - NTP client/server Loaded: loaded (/usr/lib/systemd/system/chronyd.service; enabled; vendor preset: enabled)Active:inactive(dead) since Thu 2019-02-07 01:20:34 EST; 44s ago ...output omitted... ... servera.lab.example.com chronyd[710]: System clock wrong by 1.349113 seconds, adjustment started ... servera.lab.example.com systemd[1]:Stopping NTP client/server...... servera.lab.example.com systemd[1]:Stopped NTP client/server.Press q to exit the command.
Determine if the
chronydservice is enabled to start at system boot.[student@server ~]$systemctl is-enabled chronydenabledReboot
servera, then view the status of thechronydservice.[student@servera ~]$sudo systemctl rebootConnection to servera closed by remote host. Connection to servera closed.[student@workstation ~]$Log in as the
studentuser onserveraand view the status of thechronydservice.[student@workstation ~]$ssh student@servera...output omitted...[student@servera ~]$systemctl status chronyd● chronyd.service - NTP client/server Loaded: loaded (/usr/lib/systemd/system/chronyd.service; enabled; vendor preset: enabled)Active:active(running) since Thu 2019-02-07 01:48:26 EST; 5min ago ...output omitted...Press q to exit the command.
Disable the
chronydservice so that it does not start at system boot, then view the status of the service.[student@servera ~]$sudo systemctl disable chronyd[sudo] password for student:studentRemoved /etc/systemd/system/multi-user.target.wants/chronyd.service.[student@servera ~]$systemctl status chronyd● chronyd.service - NTP client/server Loaded: loaded (/usr/lib/systemd/system/chronyd.service;disabled; vendor preset: enabled) Active: active (running) since Thu 2019-02-07 01:48:26 EST; 5min ago ...output omitted...Press q to exit the command.
Reboot
servera, then view the status of thechronydservice.[student@servera ~]$sudo systemctl rebootConnection to servera closed by remote host. Connection to servera closed.[student@workstation ~]$Log in as the
studentuser onserveraand view the status of thechronydservice.[student@workstation ~]$ssh student@servera...output omitted...[student@servera ~]$systemctl status chronyd● chronyd.service - NTP client/server Loaded: loaded (/usr/lib/systemd/system/chronyd.service;disabled; vendor preset: enabled)Active:inactive(dead) Docs: man:chronyd(8) man:chrony.conf(5)Exit from
servera.[student@servera ~]$exitlogout Connection to servera closed.[student@workstation]$
This concludes the guided exercise.