Skip to main content

Introduction

systemd is a system and service manager for Linux operating systems. It is used to manage services, processes, and system states. This guide covers creating, managing, and troubleshooting custom systemd services.

Updating Systemd After Service Creation

After creating or modifying a systemd service unit file, always reload the systemd daemon to apply changes:

Creating a Systemd Service

  1. Service Unit File Path Service unit files are typically located in /etc/systemd/system/ for custom services and /lib/systemd/system/ for official services. To create a new service, use the following path:
  2. Script Path Place your service script in a standard executable location:

Example Service Unit Files

Custom Apache2 Service

To create a custom systemd service for Apache2:
Service unit file content:

Official Apache2 Service

To view the official Apache2 service unit file:
Official service unit file content:

Running a Script

To create a service that executes a script:
Service unit file content:

Running a Script Every 30 Seconds

To create a service that runs a script every 30 seconds:
Service unit file content:

Gunicorn Service for a Test Application

To create a service for running Gunicorn:
Service unit file content:

Conclusion

Systemd is a powerful tool for managing system services and processes. By creating and configuring service unit files, you can control how services start, stop, and behave. Always remember to reload the systemd daemon after making changes to service files to ensure your configurations take effect.
This guide covers essential aspects of creating and managing systemd services, including paths for service unit files, sample configurations, and instructions for updating systemd after changes.