Manage Linux server using systemd with easy steps given in this article.
At Bobcares we often handle similar requests from our customers as a part of our Server Management Services.
Today let’s see how our Support Engineers do this for our customers with ease.
How to Manage Linux server using systemd?
We will see how our Support Techs Manage Linux server using systemd with ease.
And we use the systemctl command to control services with systemd.
Linux servers can be managed easily via command-line with the help of various commands of systemd.
We will use the Apache Service, known as httpd on RedHat Based Linux distributions as an example.
Starting:
$ systemctl start httpd
Stopping:
$ systemctl stop httpd
Restart:
This command Fully stops and starts a service:
$ systemctl restart httpd
Reload:
Reloads a service’s configuration without causing the service to restart.
$ systemctl reload httpd
Enable on Boot:
This will set the specified service to start up every time a system is booted.
$ systemctl enable httpd
Disable on Boot:
This will set the specified service to not start up every time a system is booted up.
$ systemctl disable httpd
Check Status:
$ systemctl status httpd
Methods to check specific states
1. To check to see if a unit is currently active (running), we can use the following command:
$ systemctl is-active application.service
2. To see if the unit is enabled, we can use the following command:
$ systemctl is-enabled application.service
3. To check whether the unit is in a failed state, we can use the following command:
$ systemctl is-failed application.service
System State Overview
We can check the current state of the system with a number of systemctl commands that are given below.
1. List Current Units
To see a list of all of the active units we can use the following command:
$ systemctl list-units
We can get other information by adding additional flags as given below:
$ systemctl list-units --all
Use other flags to filter results with the following command:
$ systemctl list-units --all --state=inactive
Another common filter is the –type= filter. We can display units of the type we are interested in with the following command:
$ systemctl list-units --type=service
2. List All Unit Files
We can use the list-unit-files command to see every available unit file within the systemd paths, including those that systemd has not attempted to load.
$ systemctl list-unit-files
Manging Unit files with systemd
Now we can find out more specific information about units using some additional commands.
1. For Displaying a Unit File
To display the unit file that systemd has loaded into its system, we can use the cat command:
$ systemctl cat atd.service
2. For Displaying Dependencies
To see a unit’s dependency tree, we can use the list-dependencies command:
$ systemctl list-dependencies sshd.service
3. For Checking Unit Properties
To see the low-level properties of a unit, we can use the show command.
$ systemctl show sshd.service
If we want to display a single property, we can pass the -p flag with the property name.
$ systemctl show sshd.service -p Conflicts
We can replace Conflicts with any property we wish to check
Masking and Unmasking Units
Systemd can mark a unit as completely unstartable, automatically or manually, by linking it to /dev/null.
This is called masking the unit, and is possible with the following command:
$ systemctl mask nginx.service
This will prevent the Nginx service from being started, automatically or manually, for as long as it is masked.
We can check the list-unit-files, to see if the service is now listed as masked:
$ systemctl list-unit-files
On attempts to start the service, a message can be seen as shown below:
$ systemctl start nginx.service
Failed to start nginx.service: Unit nginx.service is masked.
To unmask a unit, making it available for use again, we can use the following command:
$ systemctl unmask nginx.service
[Need assistance to manage unit files? We are here for you!]
Systemd for Editing Unit Files
From the systemd version 218 and above, we can use it for modifying unit files.
The edit command can be used to open a unit file snippet.
$ systemctl edit nginx.service
To edit a full unit file instead of creating a snippet, we can pass the –full flag:
$ sudo systemctl edit --full nginx.service
For removing a fully modified unit file, we would type:
$ sudo rm /etc/systemd/system/nginx.service
After deleting the file or directory, we must reload the systemd process to stop it from reverting those files back to using the system copies.
$ systemctl daemon-reload
Adjusting the System State (Runlevel) with Targets
To find the default target for the system we can use the following command:
$ systemctl get-default
$ multi-user.target
Listing Available Targets
For the list of the available targets we can use the following command:
$ systemctl list-unit-files --type=target
To see all of the active targets we can use the following command:
$ systemctl list-units --type=target
Shortcuts for Important Events
systemctl has some shortcuts for events like powering off or rebooting a linux server.
To put the system into rescue (single-user) mode we can use the following command:
$ systemctl rescue
For halting the system, we can use the halt command:
$ systemctl halt
To initiate a full shutdown, we can use the following command:
$ systemctl poweroff
A restart can be started with the following command:
$ systemctl reboot
[Need assistance? We are here for you!]
Conclusion
To conclude, we saw how to manage Linux server using systemd. Also, we so the different commands that our Support Engineers use to Manage Linux serves with systemd.
0 Comments