In this exercise, you use the systemctl command to stop, start, restart, reload, enable, and disable the systemd services.
Outcomes
Use the systemctl command to control the systemd services.
As the student user on the workstation machine, use the lab command to prepare your system for this exercise.
This command prepares your environment and ensures that all required resources are available.
[student@workstation ~]$ lab start services-control
Instructions
Log in to the servera machine as the student user and switch to the root user.
[student@workstation ~]$ssh student@servera...output omitted... [student@servera ~]$sudo -i[sudo] password for student:student[root@servera ~]#
Restart and reload the sshd service, and observe the results.
Display the status of the sshd service.
Note the process ID of the sshd daemon.
Press q to exit the command.
[root@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 Thu 2022-05-19 04:04:45 EDT; 16min ago Docs: man:sshd(8) man:sshd_config(5)Main PID: 784 (sshd)Tasks: 1 (limit: 10799) Memory: 6.6M ...output omitted...
Restart the sshd service and view the status.
In this example, the process ID of the daemon changes from 784 to 1193.
Press q to exit the command.
[root@servera ~]#systemctl restart sshd[root@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 Thu 2022-05-19 04:21:40 EDT; 5s ago Docs: man:sshd(8) man:sshd_config(5)Main PID: 1193 (sshd)Tasks: 1 (limit: 10799) Memory: 1.7M ...output omitted...
Reload the sshd service and view the status.
The process ID of the daemon does not change.
Press q to exit the command.
[root@servera ~]#systemctl reload sshd[root@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 Thu 2022-05-19 04:21:40 EDT; 52s ago Docs: man:sshd(8) man:sshd_config(5) Process: 1201 ExecReload=/bin/kill -HUP $MAINPID (code=exited, status=0/SUCCESS)Main PID: 1193 (sshd)Tasks: 1 (limit: 10799) Memory: 1.7M ...output omitted...
Verify that the chronyd service is running.
Press q to exit the command.
[root@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 2022-05-19 04:04:44 EDT; 19min ago ...output omitted...
Stop the chronyd service and view the status.
Press q to exit the command.
[root@servera ~]#systemctl stop chronyd[root@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 2022-05-19 04:24:59 EDT; 4s ago ...output omitted... May 19 04:24:59 servera.lab.example.com systemd[1]:Stopping NTP client/server...May 19 04:24:59 servera.lab.example.com systemd[1]:chronyd.service: Deactivated successfully.May 19 04:24:59 servera.lab.example.com systemd[1]:Stopped NTP client/server.
Determine whether the chronyd service is enabled to start at system boot.
[root@servera ~]# systemctl is-enabled chronyd
enabledReboot the servera machine, and then view the status of the chronyd service.
[root@servera ~]# systemctl reboot
Connection to servera closed by remote host.
Connection to servera closed.
[student@workstation ~]$Log in as the student user on the servera machine, and switch to the root user.
View the status of the chronyd service.
Press q to exit the command.
[student@workstation ~]$ssh student@servera...output omitted... [student@servera ~]$sudo -i[sudo] password for student:student[root@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 2022-05-19 04:27:12 EDT; 40s ago ...output omitted...
Disable the chronyd service so that it does not start at boot, and then view the status of the service.
Press q to exit the command.
[root@servera ~]#systemctl disable chronydRemoved /etc/systemd/system/multi-user.target.wants/chronyd.service. [root@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 2022-05-19 04:27:12 EDT; 2min 48s ago ...output omitted...
Reboot servera, and then view the status of the chronyd service.
[root@servera ~]# systemctl reboot
Connection to servera closed by remote host.
Connection to servera closed.
[student@workstation ~]$Log in as the student user on servera, and view the status of the chronyd service.
Press q to exit the command.
[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)
Return to the workstation system as the student user.
[student@servera ~]$ exit
logout
Connection to servera closed.
[student@workstation ~]$This concludes the section.