The Linux service command lets you run System V init scripts. Although many dis­tri­b­u­tions for Linux now use other init systems, Linux service will still work for most cases.

What is the Linux service command?

Older Linux dis­tri­b­u­tions in par­tic­u­lar still use the init system V designed to start and stop services properly. Services are programs that run au­to­mat­i­cal­ly in the back­ground when you boot your computer. This usually concerns system services re­spon­si­ble for system startup and the hardware, and post-installed server services. These services usually work without com­mu­ni­ca­tion with users and don’t have a graphical user interface. To execute a System V init script in­de­pen­dent­ly the Linux service command is used.

How does Linux service work?

To run the service command, you’ll need root priv­i­leges or should prepend the Linux sudo command. When you have the necessary priv­i­leges, you can use the command to start, stop, reboot, or get the status from in­di­vid­ual scripts, among other things. The System V init scripts are located in the folder /etc/init.d/SCRIPT on Linux. Many dis­tri­b­u­tions like Debian have switched to systemd. Linux service is still com­pat­i­ble with these. However, a better al­ter­na­tive for them is the Linux systemctl command. Basically, before you terminate or start a process, ensure it won’t neg­a­tive­ly affect your operating system.

What is the syntax of the service command?

The basic syntax of Linux service is:

$ service [Script] [Action] [Option]
bash

If you don’t specify the “[Action]” parameter, you’ll see all allowed actions in the command line.

What options and actions does Linux service have?

Strictly speaking, Linux service only has the default options “-h” or “–help”, “-v” or “–version”, and “-status-all”. However, you can specify the command with various actions. These are the most important ones:

  • start: Starts the script.
  • stop: Stops the script.
  • status: Shows the current status of the script.
  • restart: Ensures that the script is restarted.

Examples of using the Linux service command

To help you un­der­stand how the service command is used in practice, we’ll conclude with some examples of its main use.

$ sudo service sshd start
bash

This starts the sshd script.

$ sudo service sshd stop
bash

This forces the sshd script to stop.

$ sudo service sshd restart
bash

This command restarts the cor­re­spond­ing script.

$ sudo service sshd status
bash

This command is used to query the status of the script.

Go to Main Menu