Configuration system for managing Linux service processes, dependencies, and behaviors
Core Idea: Systemd service units are configuration files that define how applications run as system services, including startup behavior, environment variables, dependencies, and resource controls, enabling reliable process management on Linux systems.
Key Elements
-
Unit File Structure
[Unit]
section: Description, dependencies, ordering[Service]
section: Execution, restart, user/group settings[Install]
section: Activation targets and enablement- File naming convention:
servicename.service
- Storage location:
/etc/systemd/system/
or/usr/lib/systemd/system/
-
Service Types
simple
: Default type, main process is the executed processforking
: Process forks, parent exits, child continuesoneshot
: Executes and exitsnotify
: Process sends notification when readydbus
: Process acquires a D-Bus name when readyidle
: Delayed start until system is less busy
-
Key Directives
ExecStart
: Command to execute when service startsUser
/Group
: Which user/group runs the serviceWorkingDirectory
: Service working directoryEnvironment
: Environment variable definitionsRestart
: Restart behavior (always, on-failure, etc.)RestartSec
: Time to wait before restartAfter
/Before
: Ordering relative to other unitsRequires
/Wants
: Dependency definitions
-
Implementation Example
# /usr/lib/systemd/system/application@.service [Unit] Description=Application Service After=network.target postgresql.service [Service] Type=simple User=%i WorkingDirectory=/home/%i/application/ ExecStart=/home/%i/go/bin/application Restart=on-failure RestartSec=5s [Install] WantedBy=multi-user.target
- **Management Commands**
- `systemctl start|stop|restart service`: Control service state
- `systemctl enable|disable service`: Control autostart
- `systemctl status service`: Check service status
- `systemctl daemon-reload`: Reload systemd configuration
- `journalctl -u service`: View service logs
## Connections
- **Related Concepts**: Linux Service Management (broader concept), Process Supervision (general approach), Init Systems (historical context)
- **Broader Context**: Linux System Administration (domain)
- **Applications**: VPS CI/CD Pipeline (implementation component), Go Application Deployment (use case)
- **Components**: Systemd Unit Files (configuration format), Systemd Timers (scheduling feature)
## References
1. Systemd documentation: https://www.freedesktop.org/software/systemd/man/systemd.service.html
#linux #systemd #service-management #devops
---
**Connections:**
-
---
**Sources:**
- From: Getting back to the EU from Google Cloud to Self-Hosted EU Infrastructure