systemctl networking restart

Linux Basics: Managing Services with Systemd also known as systemctl

TL;DR: 

Systemd is an initialization system and system manager in Linux, and is becoming the new standard for many distributions. It is used to bootstrap the user space and manage all processes subsequently. In this article, we’ll cover how to use the systemctl command to manage system services including starting, stopping, enabling, and disabling them.

Introduction

Systemd is a system and service manager for Linux. It is designed to be backward compatible with SysV init scripts, and provides a number of features such as parallel startup of system services at boot time, on-demand activation of daemons, or dependency-based service control logic. In systemd, a unit refers to any resource that the system knows how to operate on and manage.

Understanding Systemd Units

Units are resources that systemd knows how to manage. Units are categorized into different types, and each type has a corresponding unit file. These types include service units (.service), target units (.target), device units (.device), and many others. For the purposes of this article, we will focus on service units which represent system services.

Managing Services with Systemctl

The systemctl command is a utility which is responsible for inspecting and controlling the systemd system and service manager. Here are some common tasks:

Starting a Service

To start a service, use the start option with systemctl followed by the service name. For example, to start a service named httpd, you would use:

sudo systemctl start httpd

Stopping a Service

To stop a running service, use the stop option. For example:

sudo systemctl stop httpd

Restarting a Service

You can restart a service (stop and then start) with the restart option. For example:

sudo systemctl restart httpd

Enabling a Service

To enable a service to start on boot:

sudo systemctl enable httpd

Disabling a Service

To disable a service to prevent it from starting at boot:

sudo systemctl disable httpd

Checking the Status of a Service

To check the status of a service:

sudo systemctl status httpd

Restarting the SSH Service

sudo systemctl status sshd

systemctl status sshd

When working with the Secure Shell (SSH) protocol, it’s crucial to understand that any modifications made to the configuration file (/etc/ssh/sshd_config) require a restart of the sshd service for the changes to take effect. After altering the configuration, use the command sudo systemctl restart sshd. This command will immediately stop the SSH service and start it again, applying your new configuration. Be aware, if you’re connected to your server via SSH while executing this command, your current session may be terminated. It’s advisable to have another SSH session open, or to be directly logged in to your server’s console, in case there are issues with the new configuration that prevent the SSH service from starting correctly.

Conclusion

Systemd and systemctl provide a powerful framework for managing your system’s services. By understanding the basic commands to manage services, you can take full control of your Linux environment. For more advanced features and options, you can refer to the man pages (man systemd, man systemctl, man systemd.unit).

If you found this guide helpful, make sure to explore other tutorials in our Linux Basics Series on PureVoltage.com. This series is designed to equip beginners with the knowledge they need to navigate and operate Linux systems with ease. Stay tuned for more comprehensive guides and don’t hesitate to reach out with any questions or topics you’d like us to cover next.


Posted

in

,

by