A lightweight service watchdog daemon written in C++.
rcwatch monitors configured services, detects unexpected process termination, and automatically restarts failed services according to configurable restart policies.
- Process health monitoring
- Automatic service restart
- Privilege dropping for monitoring processes
- IPC-based watcher/supervisor architecture
- Restart rate limiting
- Configurable restart windows
- Fixed, Linear, and Exponential backoff support
- Syslog-based logging
- Unit-tested core components
rcwatch uses a simple supervisor/watcher model.
+----------------+
| Supervisor |
| (privileged) |
+--------+-------+
^
|
Pipe IPC
|
v
+--------+-------+
| Watcher |
| (unprivileged) |
+----------------+
- Runs with reduced privileges
- Periodically checks service health
- Reports failed services to the supervisor
- Receives failure notifications
- Applies restart policies
- Restarts services when allowed
git clone https://github.com/mateofz/rcwatch.git
cd rcwatch/src
make
./rcwatch rcwatch.confExample:
service
service_name sshd
pid_file /var/run/sshd.pid
start_cmd /path/to/start/script/file
stop_cmd /path/to/stop/script/file
restart_cmd /path/to/restart/script/file
check_interval 10
max_restart 5
restart_window 60
backoff_method Fixed
delay_time 5
end_service
| Option | Description |
|---|---|
| service_name | Service identifier |
| pid_file | PID file path |
| start_cmd | Service start command |
| stop_cmd | Service stop command |
| restart_cmd | Service restart command |
| check_interval | Health check interval (seconds) |
| max_restart | Maximum restart attempts |
| restart_window | Restart window (seconds) |
| backoff_method | Fixed / Linear / Exponential |
| delay_time | Delay between restart attempts |
Current test coverage includes:
- Configuration parser
- IPC pipe communication
- Process state detection
Run tests:
cd test/test_config_manager
make run
cd ../test_ipc_pipe
make run
cd ../test_process
make runsrc/
├── config_manager.cpp
├── process.cpp
├── privilege.cpp
├── restart_manager.cpp
├── logger.cpp
├── rcwatch.cpp
└── ipc/
test/
├── test_config_manager/
├── test_ipc_pipe/
└── test_process/
- Minimal dependencies
- Unix-oriented design
- Separation of privileges
- Simple and maintainable codebase
- Educational implementation of service supervision concepts
- SIGHUP configuration reload
- Daemonization support
- Shared-memory configuration updates
- Integration tests
- Makefile/CMake build system
- Service state persistence
- Structured logging
GPL-3