How To Start/Stop/Restart Services Using Systemctl in Linux

How To Start/Stop/Restart Services Using Systemctl in Linux. Managing services in Linux is a basic task for a system administrator.

Hence, it is important to manage the services in Linux because most of the applications that are installed on your server need some of the services that are already running. If you want to change or add any service, you have to restart it first.

All in all, you manage services using the different methods provided by the Linux system, but the open-source software system called systemd is one of the most robust and efficient methods.

Systemd is a replacement for the System V init daemon. Basically, it is a service manager that provides an interface for controlling system services, including managing users, sessions, volumes and tty devices.

Though, Systemd makes system administration tasks more convenient and easier while improving security and stability.

Systemctl is the command line interface for systemd. It manages the systemd services.

In this article how to Start/Stop/Restart Services Using Systemctl in Linux, you  learn about the systemctl and how it contributes to systemd features. Following that, you get to know how to use the systemctl command to start/stop/restart and manage other aspects of services management in Linux.

What is Systemd in Linux

Systemd is a system and service manager for Linux that has replaced the older Upstart, Sysvinit, and System V init systems. First released in 2010.

Secondly, it is designed to replace the older upstart and sysv, which have been deprecated in favour of systemd. It aims to combine the benefits of System V with the advantages of newer technologies in an easy to use package. So, the systemd inherits all the features introduced by its predecessors but adds new features as well.

Systemd provides the basic functionality for managing and monitoring the state of a system and its services. It is responsible for starting and stopping services, managing user sessions, automating device management, and providing several other administrative tasks.

For example, systemd uses socket activation instead of a more complicated process that is sometimes difficult to understand. It also has better performance than previous versions of System V because it’s written in C++ instead of C.

What is a service? You might ask, in Linux, a service is a program that runs as a background process in the background of your computer. It allows you to schedule them to run periodically or immediately.

What is Systemctl Command

Subsequently, Systemd is an umbrella project for several systemd services, including systemctl, the command-line tool.

It means that systemctl is the command line interface for systemd. Used to manage the systemd services, including starting them, stopping them, restarting them, and checking if they need to be started or stopped.

Additionally, Systemd uses systemctl to manage its own internal state and to interact with other processes using the D-BUS messaging system. Systemd uses D-Bus to allow users to access the management interface via the command line or a GUI tool.

Its primary purpose is to provide a system and service manager that is used to manage a computer without having to know how each component works.

Image Source : Medium 

Systemctl allows users to control various aspects of their system, including changing settings, starting and stopping services, reloading configuration files, and more.

Follow this post to learn how to use the systemctl command to manage services in the Linux operating system.

How To Start/Stop/Restart Services Using Systemctl in Linux

Prerequisites

You will need the following:

    • A user account with sudo or root privilege.

    • Terminal/command-line access on Linux.

Basic Syntax of systemctl Command

Before diving into managing services, you need to understand the basic structure of the systemctl command. Doing so will make it easier to recall the commands.

The systemctl command has the following basic syntax:

				
					systemctl [command] [service_name]
				
			

Remember that these commands require sudo privileges, so you will need to execute these commands as a superuser, with each command beginning with sudo.

Check Services Status Using Systemctl Command

One more thing you need to learn before managing services is to check their current status. This is essential because the service status serves as verification of the command’s success or failure.

You can use the status subcommand to check the status of any service.

				
					sudo systemctl status cups
				
			

You can get information about the service status from the Active and Process fields in the output.

Start Services Status With Systemctl Command

If any service is not started on the system or just stopped due to some reason, you can use the following command with a start subcommand to start it manually.

				
					sudo systemctl start cups
				
			

This command does not produce any output, so you have to check the service’s status to verify this command’s success.

Stop Services With Systemctl Command

Similarly if you need to stop any specific service, use the stop subcommand in the systemctl command.

				
					sudo systemctl stop cups
				
			

You can see the service being inactive in the service status.

Restart Services Using Systemctl Command

You can simply restart any stopped service using the following command.

				
					sudo systemctl restart cups
				
			

Run the systemctl status command to verify that the service has been restarted.

Reload Services With Systemctl Command

Restart service works as its name indicates, it shuts the service down and starts it again. But if you do not want to stop the service while achieving the same effect as restarting service, You can use the reload subcommand.

				
					sudo systemctl reload NetworkManager
				
			

Service reload command tells the daemon to reload its configuration. When these configurations are updated, any changes made in the services configuration files take effect, eliminating the need to restart the service.

Of course, you use the restart command just to be through, but this command will do in a pinch when you can not stop the service immediately.

Mask/Unmask Services Using Systemctl Command

When you disable a service, a user or process can still start it with the systemctl start command. You can use the mask subcommand to avoid this from happening.

Masking the service makes its configuration to /dev/null. Any user or process cannot start this service.

				
					sudo systemctl mask cups
				
			

The start command cannot start the masked service in the output.

To reverse this setting, use the unmask subcommand.

				
					sudo systemctl unmask cups
				
			

Enable/Disable Services With Systemctl Command 

Systemctl command facilitates the service to start at boot. Particularly helpful when dealing with services you frequently use on your system. You can achieve it using the enable subcommand with the systemctl command.

				
					sudo systemctl enable cups
				
			

Similarly, you can use the disable command to reverse this configuration.

				
					sudo systemctl disable cups
				
			

More About Systemctl Command

Run the following command to learn more about systemctl subcommand options. It helps you to explore the true extent and potential of the systemctl command.

				
					man systemctl
				
			

That’s how you use the systemctl command to start/ stop/restart service on Linux.

Thank you for reading How To Start/Stop/Restart Services Using Systemctl in Linux. We shall conclude this article blog. 

How To Start/Stop/Restart Services Using Systemctl in Linux Conclusion

Linux distributions use Systemd which is a service manager. It provides core functionality such as logging, resource control, and process management. Systemd is responsible for starting services and daemons at boot time and stopping them when they are no longer needed, as well as performing other maintenance tasks.

Systemd is similar to Upstart and SystemV init, but with more features. However, unlike SysV Init, systemd uses a different approach to managing services.

Systemctl represents the command line interface for systemd. It is a utility that manages systemd services. It is used to start, stop, enable and disable services.

Explore our Linux section to learn more.

Avatar for Sobia Arshad
Sobia Arshad

Information Security professional with 4+ years of experience. I am interested in learning about new technologies and loves working with all kinds of infrastructures.

5 1 vote
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x