Overview
For production Linux deployments, systemd provides robust process management, automatic restarts, and service dependency handling. This guide covers creating systemd unit files and managing Template Worker as a system service.Basic Service Unit
Here’s a complete systemd service unit file for Template Worker:Service Configuration Explained
| Directive | Purpose |
|---|---|
Type=simple | Process doesn’t fork; stays in foreground |
User=antiraid | Run as non-privileged user |
WorkingDirectory | Sets working directory for config.yaml |
ExecStart | Command to start the worker |
ExecReload | Send HUP signal for graceful reload |
KillMode=mixed | Send SIGTERM to main, SIGKILL to others |
TimeoutStopSec=5 | Wait 5s for graceful shutdown |
PrivateTmp=true | Isolate /tmp directory for security |
Restart=always | Auto-restart on failure |
RestartSec=1 | Wait 1s before restart attempt |
Installation
Create systemd unit file
Create the service file at Paste the unit file content from above.
/etc/systemd/system/template-worker.service:Service Management
Common Commands
Service Status
Check if the service is running:Worker Type Configuration
Template Worker supports multiple worker modes via command-line arguments. See Scaling for detailed comparison.Process Pool (Recommended)
Thread Pool
Custom Worker Count
Multi-Service Deployment
For complex deployments with multiple services, create a target unit to manage them together.Create Target Unit
Create/etc/systemd/system/antiraid-v6.target:
Link Services to Target
In each service unit file, add:Example: Multiple Services
Sandwich Gateway Service (ar-sandwich.service):
template-worker.service):
Managing the Service Stack
Environment Variables
To pass environment variables to your service, use theEnvironment directive:
Security Hardening
For production deployments, add these security directives:Monitoring and Logs
Structured Logging
Template Worker logs to stdout/stderr. Systemd captures these via journald:Log Rotation
Configure journald log retention in/etc/systemd/journald.conf:
Troubleshooting
Service Won’t Start
-
Check service status:
-
View recent logs:
-
Test binary manually:
Permission Errors
Ensure the service user owns all required files:Service Keeps Restarting
-
Check for crashes in logs:
-
Verify configuration:
-
Temporarily disable auto-restart to debug:
Next Steps
- Configure worker scaling for optimal performance
- Review configuration options for tuning
- Explore Architecture to understand the system internals