How to Enable and Manage systemd Services on Arch Linux

How to Enable and Manage systemd Services on Arch Linux

Systemd is the default system and service manager in Arch Linux, responsible for booting the system, managing services, and handling system processes. One of its most powerful features is its ability to enable, start, stop, restart, and manage services. This article will guide you through how to enable and manage systemd services on Arch Linux in a clear and structured manner. Whether you’re new to systemd or need to brush up on your skills, this guide will help you get a solid grasp of service management on Arch Linux.

What is systemd?

Systemd is a system and service manager that initializes system components during boot and manages services throughout the system’s runtime. It was designed to replace the traditional SysV init system, offering faster boot times, parallelized service startup, and advanced features such as service dependencies and logging.

In Arch Linux, systemd is used to control the following aspects of system services:

  • Unit files: Configurations for services, sockets, targets, devices, and other system components.
  • Service management: Starting, stopping, and reloading services.
  • Boot management: Controlling the system startup process.
  • Logging: Systemd includes journald, a logging service that aggregates logs for easier management.

Basic Terminology

Before we dive into the details, it’s essential to understand a few basic systemd concepts:

  1. Unit Files: These are configuration files used by systemd to define services and other system components. Unit files can define various types of units, including:

    • Service units: For managing system services (e.g., httpd.service for Apache).
    • Socket units: For managing sockets that services listen to (e.g., sshd.socket for SSH).
    • Target units: For defining system states or run levels (e.g., graphical.target for multi-user graphical mode).
  2. Services: Systemd services represent running processes or programs, such as web servers, databases, or custom applications.

  3. systemctl: The command-line utility used to interact with systemd. It allows you to manage units, check service status, enable or disable services, and more.

Managing systemd Services

Now that we understand the basics of systemd, let’s take a look at the various ways to enable, start, stop, and manage services on Arch Linux.

1. Checking the Status of a Service

The first step in managing services is to check their status. You can use the systemctl status command to see whether a service is active or not. For example, to check the status of the Apache HTTP server (httpd.service), you would use the following command:

sudo systemctl status httpd.service

This will return output similar to this:

● httpd.service - Apache Web Server
     Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
     Active: active (running) since Mon 2025-04-08 10:20:22 UTC; 1h 10min ago
   Main PID: 1234 (httpd)
      Tasks: 5 (limit: 4915)
     Memory: 7.2M
     CGroup: /system.slice/httpd.service
             ├─1234 /usr/bin/httpd -DFOREGROUND
             └─1235 /usr/bin/httpd -DFOREGROUND

In this example, the service is active and running.

2. Starting and Stopping Services

You can start or stop a service using the systemctl start and systemctl stop commands. For example, to start the Apache service:

sudo systemctl start httpd.service

If you want to stop the service:

sudo systemctl stop httpd.service

After starting or stopping a service, you can verify its status using systemctl status as shown earlier.

3. Enabling and Disabling Services

Enabling a service means that it will start automatically when the system boots. Disabling a service means it will not start automatically on boot but can be manually started when needed. To enable a service, use the systemctl enable command:

sudo systemctl enable httpd.service

To disable the service:

sudo systemctl disable httpd.service

Enabling or disabling services affects their behavior only during boot-up. Disabling a service won’t stop it if it’s currently running, and enabling a service won’t start it immediately.

4. Rebooting the System with Services

Sometimes, after enabling or disabling a service, you may want to reboot the system to see the effects. You can reboot your Arch Linux system with the following command:

sudo reboot

This will restart the system, and any services you’ve enabled will automatically start.

5. Restarting Services

To restart a service, which is useful if you have made configuration changes or need to refresh the service, use the systemctl restart command. For example, to restart the Apache service:

sudo systemctl restart httpd.service

This will stop and then start the service, ensuring that it’s running with the latest configuration.

6. Reloading Services

In some cases, you may not need to fully restart a service. If you only need to reload the configuration files (without stopping the service), you can use the systemctl reload command:

sudo systemctl reload httpd.service

This command instructs the service to re-read its configuration files and apply the changes without fully restarting it.

7. Checking Logs for Services

Systemd integrates with journald, a logging system that collects logs from all system services. To view logs for a specific service, you can use the journalctl command. For example, to view logs for the Apache service:

sudo journalctl -u httpd.service

You can use various options to filter logs, such as:

  • -f: Follow the log output in real-time.
  • --since "YYYY-MM-DD HH:MM:SS": Show logs since a specific date and time.
  • --until "YYYY-MM-DD HH:MM:SS": Show logs until a specific date and time.

For instance, to follow the logs in real-time:

sudo journalctl -u httpd.service -f

8. Listing All Active Services

You can list all active services on your system with the systemctl list-units command. This will display all the services currently running:

systemctl list-units --type=service

This will give you a list of all active services, their status, and the unit files they use. You can also filter the list based on different parameters.

9. Masking and Unmasking Services

Sometimes, you may want to prevent a service from starting entirely, even if it’s enabled. To do this, you can mask the service, which prevents systemd from starting it. Masking a service can be useful in cases where you don’t want a service to start under any circumstances, even if another service depends on it.

To mask a service:

sudo systemctl mask httpd.service

To unmask the service and allow it to be started again:

sudo systemctl unmask httpd.service

10. Creating Custom Services

In some cases, you might want to create your own systemd service to manage custom applications or scripts. A systemd service unit file is usually located in /etc/systemd/system/. For example, to create a simple service to run a script, follow these steps:

  1. Create a service unit file in /etc/systemd/system/mycustom.service.
sudo nano /etc/systemd/system/mycustom.service
  1. Add the following content to the file:
[Unit]
Description=My Custom Service

[Service]
ExecStart=/usr/bin/mycustomscript.sh
Restart=always

[Install]
WantedBy=multi-user.target

This will ensure that mycustomscript.sh runs as a service and is automatically restarted if it fails.

  1. Reload systemd to recognize the new service:
sudo systemctl daemon-reload
  1. Enable and start the service:
sudo systemctl enable mycustom.service
sudo systemctl start mycustom.service

Conclusion

Managing systemd services on Arch Linux is an essential skill for system administrators and users who wish to control the startup and behavior of services on their system. By using the systemctl command, you can easily enable, disable, start, stop, and monitor services, as well as troubleshoot issues by accessing logs.

Whether you’re managing pre-installed services or creating custom ones, systemd provides powerful tools to ensure that your system runs smoothly and efficiently. Mastering service management will give you greater control over your Arch Linux system and help optimize your workflow.