Systemd provides a standard process for controlling what programs run when a Linux system boots up.
Here at Ibmi Media, as part of our Server Management Services, we regularly help our Customers to perform Systemd related tasks on Linux.
In this context, we shall look into how to use systemd to manage Linux Server.
Here, you will see how to Manage Linux server using systemd with ease.
Also, 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 Apache:
$ systemctl start httpdStopping Apache:
$ systemctl stop httpdRestart Apache:
This command Fully stops and starts a service:
$ systemctl restart httpdReload Apache:
Reloads a service’s configuration without causing the service to restart.
$ systemctl reload httpdEnable Apache on Boot:
This will set the specified service to start up every time a system is booted.
$ systemctl enable httpdDisable Apache on Boot:
This will set the specified service to not start up every time a system is booted up.
$ systemctl disable httpdCheck Apache Status:
$ systemctl status httpd1. To check to see if a unit is currently active (running), we can use the following command:
$ systemctl is-active application.service2. To see if the unit is enabled, we can use the following command:
$ systemctl is-enabled application.service3. To check whether the unit is in a failed state, we can use the following command:
$ systemctl is-failed application.serviceWe 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-unitsWe can get other information by adding additional flags as given below:
$ systemctl list-units --allUse other flags to filter results with the following command:
$ systemctl list-units --all --state=inactiveAnother 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=service2. 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-filesNow 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.service2. For Displaying Dependencies
To see a unit’s dependency tree, we can use the list-dependencies command:
$ systemctl list-dependencies sshd.service3. For Checking Unit Properties
To see the low-level properties of a unit, we can use the show command.
$ systemctl show sshd.serviceIf we want to display a single property, we can pass the -p flag with the property name.
$ systemctl show sshd.service -p ConflictsWe can replace Conflicts with any property we wish to check
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.serviceThis 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-filesOn attempts to start the service, a message can be seen as shown below:
$ systemctl start nginx.serviceFailed 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.serviceFrom 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.serviceTo edit a full unit file instead of creating a snippet, we can pass the –full flag:
$ sudo systemctl edit --full nginx.serviceFor removing a fully modified unit file, we would type:
$ sudo rm /etc/systemd/system/nginx.serviceAfter 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-reloadTo find the default target for the system we can use the following command:
$ systemctl get-default
$ multi-user.targetFor the list of the available targets we can use the following command:
$ systemctl list-unit-files --type=targetTo see all of the active targets we can use the following command:
$ systemctl list-units --type=targetsystemctl 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 rescueFor halting the system, we can use the halt command:
$ systemctl haltTo initiate a full shutdown, we can use the following command:
$ systemctl poweroffA restart can be started with the following cmmand:
$ systemctl reboot
Like the init #daemon, #systemd is a daemon that manages other daemons, which, including systemd itself, are background #processes. systemd is the first daemon to start during booting and the last daemon to terminate during shutdown.
This article will guide you on how to manage #Linux server using systemd. Additionally, we saw the different commands used to Manage Linux serves with systemd. While systemd is compatible with SysV and Linux Standard Base (LSB) init scripts, systemd is meant to be a drop-in replacement for these older ways of getting a Linux system running.
To start (activate) a service , you will run the command 'systemctl start my_service. service', this will start the service immediately in the current session.
To enable a service at boot , you will run 'systemctl enable my_service. service'.