Controlling Services with systemctl Commands
The systemctl
command is the primary tool for managing system services in a systemd-based Linux distribution like Ubuntu 22.04. With systemctl
, you can start, stop, restart, and check the status of system services, as well as enable or disable services to control their behavior during system boot.
Starting, Stopping, and Restarting Services
To start a service, use the start
subcommand:
sudo systemctl start my-service.service
To stop a service, use the stop
subcommand:
sudo systemctl stop my-service.service
To restart a service, use the restart
subcommand:
sudo systemctl restart my-service.service
Checking Service Status
To check the status of a service, use the status
subcommand:
systemctl status my-service.service
This will display information about the service, including its current state, the process ID of the running service, and any recent log entries.
Enabling and Disabling Services
To enable a service to start automatically at system boot, use the enable
subcommand:
sudo systemctl enable my-service.service
To disable a service from starting automatically at system boot, use the disable
subcommand:
sudo systemctl disable my-service.service
Managing Service Dependencies
systemd also allows you to manage dependencies between services. You can use the systemctl
command to view the dependencies of a service, as well as the services that depend on a particular service.
## View dependencies of a service
systemctl list-dependencies my-service.service
## View services that depend on a service
systemctl list-dependencies --reverse my-service.service
By understanding and utilizing the various systemctl
commands, you can effectively control and manage system services in your Ubuntu 22.04 environment.