Mastering SystemCTL Commands for Service Management in Ubuntu
August 6th, 2024 10:57 AM Mr. Q Categories: Linux
In this tutorial, you’ll learn how to use the systemctl command to start, stop, restart, and manage other services on your Ubuntu server, along with listing all services and their statuses.
If you are not logged in as root, you will need to preface with sudo.
Table of Contents:
- Introduction to SystemCTL
- Listing All Services
- Starting Services
- Stopping Services
- Restarting Services
- Reloading Services
- Status of Services
- Enabling and Disabling Services
- Summary
Section 1: Introduction to SystemCTL
SystemCTL is a utility used in Linux systems, particularly in Ubuntu distributions, for managing system services. It is part of the systemd
suite, which provides a framework for managing services and dependencies.
Section 2: Listing All Services
To list all active services, run the following command in your terminal:
systemctl list-units --type=service
This will display a list of all currently active services, along with their statuses. You can use the grep
command to filter the output based on specific keywords or patterns.
This is another way to list all services
systemctl --type service --all --list
You can also pipe the output to grep a spicific services
systemctl --type service --all --list | grep snap.ollama.listener
Section 3: Starting Services
To start a specific service, use the following command in your terminal:
systemctl start [service_name]
Replace [service_name]
with the name of the service you want to start, such as webui
or apache2
.
Section 4: Stopping Services
To stop a specific service, use the following command in your terminal:
systemctl stop [service_name]
Replace [service_name]
with the name of the service you want to stop, such as webui
or apache2
.
Section 5: Restarting Services
To restart a specific service, use the following command in your terminal:
systemctl restart [service_name]
Replace [service_name]
with the name of the service you want to restart, such as webui
or apache2
.
Section 6: Reloading Services
To reload a specific service without stopping it, use the following command in your terminal:
systemctl reload [service_name]
Replace [service_name]
with the name of the service you want to reload, such as webui
or apache2
.
Section 7: Status of Services
To check the current status of a specific service, use the following command in your terminal:
systemctl status [service_name]
Replace [service_name]
with the name of the service you want to check, such as webui
or apache2
.
Section 8: Enabling and Disabling Services
To enable a specific service, use the following command in your terminal:
systemctl enable [service_name]
Replace [service_name]
with the name of the service you want to enable, such as webui
or apache2
. This sets up the service to start automatically when the system boots.
To disable a specific service, use the following command in your terminal:
systemctl disable [service_name]
Replace [service_name]
with the name of the service you want to disable, such as webui
or apache2
. This removes the service from the list of services that start automatically when the system boots.
Section 9: Summary
In this tutorial, you learned how to use the systemctl command to manage services on your Ubuntu server. You can list all active services, start and stop specific services, restart services, reload services without stopping them, check the status of services, and enable or disable services to control their automatic startup behavior. Mastering these commands will help you effectively manage and maintain your system’s services.