When setting up runit logging for a service, you might encounter situations where your log directory remains empty despite proper configuration. The service appears to run normally according to sv status
, but the expected log files never appear in your designated directory.
A standard runit service with logging consists of these components:
/etc/sv/test/
├── run
├── finish
└── log/
├── run
└── config
The most common issue lies in the log/run
script configuration. Many developers make these mistakes:
- Forgetting the
exec
command - Not properly piping service output
- Incorrect permission settings
Here's the corrected version that actually works:
#!/bin/sh
exec svlogd -tt /var/log/test
Let me show a fully functional setup that handles both service management and logging:
Main service run script
#!/bin/sh
exec 2>&1
exec /path/to/your/service/binary 2>&1 | logger -t yourservice
Log directory run script
#!/bin/sh
exec chpst -ulogger svlogd -tt /var/log/test
When logs don't appear, follow this checklist:
- Verify all scripts are executable:
chmod +x /etc/sv/test/*/run
- Check ownership of log directory:
chown logger:logger /var/log/test
- Test log script manually:
/etc/sv/test/log/run
- Examine process tree:
ps auxf | grep -A5 svlogd
For better log management, create a config
file in your log directory:
# /etc/sv/test/log/config
s1000000
n10
t86400
!gzip
This configuration will:
- Rotate logs at 1MB (
s1000000
) - Keep 10 archived logs (
n10
) - Compress old logs (
!gzip
) - Add timestamps (
t86400
for daily rotation)
Remember these essential commands for managing runit services with logging:
# Check status
sv status test
sv status test/log
# Start/stop logging separately
sv up test/log
sv down test/log
# Full service control
sv restart test
sv force-stop test
Runit's logging system works through a separate logging service that runs parallel to your main service. The key components are:
/etc/sv/your_service/
├── run
├── log/
│ ├── run
│ └── config
From your description, several potential issues emerge:
- The logging service isn't properly starting (shown as "down: log")
- Potential permission issues with the log directory
- Configuration problems in the log/run script
Here's a fully working configuration example:
# /etc/sv/test/run
#!/bin/sh
exec 2>&1
exec your_service_command
# /etc/sv/test/log/run
#!/bin/sh
exec chpst -u logger svlogd -tt /var/log/test
1. Permission setup:
sudo mkdir -p /var/log/test
sudo chown -R logger:logger /var/log/test
sudo chmod 755 /var/log/test
2. Log rotation configuration (optional):
# /etc/sv/test/log/config
s1000000
n10
t86400
!gzip
Check service status:
sv status test
sv status test/log
Force restart both services:
sv restart test
sv restart test/log
For applications that need special log handling:
# Alternative log/run script using multilog
#!/bin/sh
exec chpst -u logger multilog t ./main
For syslog integration:
#!/bin/sh
exec chpst -u logger svlogd -tt /var/log/test | logger -t test-service