Linux service command

The service command in Linux is a command-line tool used to control system services on Linux distributions that use the System V init system. It provides a simple and consistent interface for starting, stopping, restarting, and checking the status of services.

The service command follows the following syntax:

service [option] <service_name> <action>

Here are some common options and actions used with the service command:

  1. Common Options:
  • --status-all: Display the status of all services.
  • --help: Show the help message.
  1. Common Actions:
  • start: Start a service.
  • stop: Stop a service.
  • restart: Restart a service.
  • status: Check the status of a service.
  • reload: Reload the configuration of a service.
  • enable: Enable a service to start automatically on boot.
  • disable: Disable a service from starting automatically on boot.

Examples:

  1. Start a service:
   service apache2 start
  1. Stop a service:
   service apache2 stop
  1. Restart a service:
   service apache2 restart
  1. Check the status of a service:
   service apache2 status
  1. Enable a service to start automatically on boot:
   service apache2 enable
  1. Disable a service from starting automatically on boot:
   service apache2 disable

Note that the availability and usage of the service command may vary depending on the Linux distribution and the init system it uses. For systems that use the systemd init system, the systemctl command is generally used instead. It provides more advanced control over services and is recommended for modern Linux distributions.

To learn more about the service command and the services available on your specific Linux distribution, you can refer to the command’s manual page by running man service in the terminal.