Systemd is a system and service manager for Linux operating systems. It is designed to be backward compatible with SysV init scripts, and most modern Linux distributions had now adopted systemd.
Previous versions of Linux, which were distributed with SysV init or Upstart, used init scripts written in bash located in the /etc/rc.d/init.d/ directory. These init scripts have been replaced with service units.
To start, stop, restart, enable, or disable Linux service you will use the systemctl command instead of the old service command.
systemctl [command] [service_name]
Start a Service Using systemctl
To start a service run systemctl command followed by 'start' then space service name.
systemctl start service-name
Example - To start nginx service using systemctl, run:
$ sudo systemctl start nginx
Stop a service using systemctl
To stop a service run systemctl command followed by 'stop' then space service name.
systemctl stop service-name
For example to stop nginx service, use:
$ sudo systemctl stop nginx
Restart a service using systemctl
To restart a service use systemctl followed by 'restart' then space service name. You can also use the try-restart option that will restart the service only if it's already running. Also, you have the reload option that will reload the configuration files.
systemctl restart service-name
$ sudo systemctl restart nginx $ sudo systemctl try-restart nginx $ sudo systemctl reload nginx
Check status of a service using systemctl
To check the status of a service use systemctl followed by 'status' then space service name.
systemctl status service-name
$ sudo systemctl status nginx
Enable/Disable service at boot time
You can use the systemctl enable/disable options to make a service run at boot time.
systemctl enable/disable service-name
For example, let's check how to enable and disable Nginx web server service on system startup:
$ sudo systemctl enable nginx
$ sudo systemctl disable nginx
To reboot your Linux computer type sudo systemctl reboot. I hope you enjoyed reading this article on knowing how to use systemctl command to restart, start and stop service in Linux.