Bobcares

Manage Linux server using systemd – Do it with ease

PDF Header PDF Footer

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.

manage linux server using systemd

We will use the Apache Service, known as httpd on RedHat Based Linux distributions as an example.

Starting:

$ systemctl start httpdCopy Code

Stopping:

$ systemctl stop httpdCopy Code

Restart:
This command Fully stops and starts a service:

$ systemctl restart httpdCopy Code

Reload:
Reloads a service’s configuration without causing the service to restart.

$ systemctl reload httpdCopy Code

Enable on Boot:
This will set the specified service to start up every time a system is booted.

$ systemctl enable httpdCopy Code

Disable on Boot:
This will set the specified service to not start up every time a system is booted up.

$ systemctl disable httpdCopy Code

Check Status:

$ systemctl status httpdCopy Code

 

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.serviceCopy Code

2. To see if the unit is enabled, we can use the following command:

$ systemctl is-enabled application.serviceCopy Code

3. To check whether the unit is in a failed state, we can use the following command:

$ systemctl is-failed application.serviceCopy Code

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-unitsCopy Code

We can get other information by adding additional flags as given below:

$ systemctl list-units --allCopy Code

Use other flags to filter results with the following command:

$ systemctl list-units --all --state=inactiveCopy Code

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=serviceCopy Code
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-filesCopy Code

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.serviceCopy Code
2. For Displaying Dependencies

To see a unit’s dependency tree, we can use the list-dependencies command:

$ systemctl list-dependencies sshd.serviceCopy Code
3. For Checking Unit Properties

To see the low-level properties of a unit, we can use the show command.

$ systemctl show sshd.serviceCopy Code

If we want to display a single property, we can pass the -p flag with the property name.

$ systemctl show sshd.service -p ConflictsCopy Code

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.serviceCopy Code

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-filesCopy Code

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.Copy Code

To unmask a unit, making it available for use again, we can use the following command:

$ systemctl unmask nginx.serviceCopy Code

[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.serviceCopy Code

To edit a full unit file instead of creating a snippet, we can pass the –full flag:

$ sudo systemctl edit --full nginx.serviceCopy Code

For removing a fully modified unit file, we would type:

$ sudo rm /etc/systemd/system/nginx.serviceCopy Code

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-reloadCopy Code

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.targetCopy Code
Listing Available Targets

For the list of the available targets we can use the following command:

$ systemctl list-unit-files --type=targetCopy Code

To see all of the active targets we can use the following command:

$ systemctl list-units --type=targetCopy Code

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 rescueCopy Code

For halting the system, we can use the halt command:

$ systemctl haltCopy Code

To initiate a full shutdown, we can use the following command:

$ systemctl poweroffCopy Code

A restart can be started with the following command:

$ systemctl rebootCopy Code

[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.

 

var google_conversion_label = "owonCMyG5nEQ0aD71QM";

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Get featured on the Bobcares blog and share your expertise with a global tech audience.

WRITE FOR US
server management

Spend time on your business, not on your servers.

TALK TO US

Or click here to learn more.

Speed issues driving customers away?
We’ve got your back!