Home > Package & System Management > service

service: System Service Management

The `service` command is used to manage system services by executing System V init scripts. It is primarily used for tasks such as starting, stopping, restarting, and checking the status of services. While `systemctl` is more recommended on `systemd`-based systems, `service` can still be useful for backward compatibility or in specific scenarios.

Overview

The `service` command provides a standardized interface for executing System V init scripts located in the `/etc/init.d/` directory. This allows users to perform service management tasks in a consistent manner. Although `service` can be used on modern Linux distributions that have adopted `systemd`, it may internally redirect to `systemctl` or be used solely for managing System V init scripts.

Key Functions

  • Start a service (start)
  • Stop a service (stop)
  • Restart a service (restart)
  • Check service status (status)
  • Check status of all services (--status-all)

Main Options and Actions

The `service` command primarily takes the `service_name` and an `action` as arguments. Some global options are also provided.

Service Actions

Global Options

Generated command:

Try combining the commands.

Description:

`service` Executes the command.

Combine the above options to virtually execute commands with AI.

Usage Examples

Start Apache Web Server

service apache2 start

Starts the Apache web server service.

Check MySQL Service Status

service mysql status

Checks the current status of the MySQL database service.

Restart Network Service

service network restart

Restarts the network-related service.

Check Status of All System V Services

service --status-all

Checks the status of all services managed by System V init scripts at a glance.

Tips & Notes

Information on points to note when using the `service` command and its relationship with `systemctl`.

Usage in systemd Environments

  • Relationship with systemctl: Most modern Linux distributions (e.g., Ubuntu 15.04+, CentOS 7+) use `systemd` as their default init system. In these environments, using the `service` command may internally translate to executing the `systemctl` command. Therefore, when managing `systemd` services, it is clearer and more powerful to use `systemctl` directly.
  • Recommendations: It is common practice to use `systemctl` on `systemd`-based systems and `service` on System V init-based systems. If you are unsure which command to use, try `systemctl` first, and consider `service` if it doesn't work or if you specifically need to manage System V init scripts.

Service Name

The service name must match the script file name in the `/etc/init.d/` directory. For example, if there is an `/etc/init.d/apache2` script, you would use it like `service apache2 ...`.


Same category commands