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.
service command follows the following syntax:
service [option] <service_name> <action>
Here are some common options and actions used with the
- Common Options:
--status-all: Display the status of all services.
--help: Show the help message.
- 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.
- Start a service:
service apache2 start
- Stop a service:
service apache2 stop
- Restart a service:
service apache2 restart
- Check the status of a service:
service apache2 status
- Enable a service to start automatically on boot:
service apache2 enable
- 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.