Skip to content

mateofz/rcwatch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rcwatch

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.

Features

  • 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

Architecture

rcwatch uses a simple supervisor/watcher model.

             +----------------+
             |   Supervisor   |
             |  (privileged)  |
             +--------+-------+
                      ^
                      |
                   Pipe IPC
                      |
                      v
             +--------+-------+
             |    Watcher     |
             | (unprivileged) |
             +----------------+

Watcher

  • Runs with reduced privileges
  • Periodically checks service health
  • Reports failed services to the supervisor

Supervisor

  • Receives failure notifications
  • Applies restart policies
  • Restarts services when allowed

Build

git clone https://github.com/mateofz/rcwatch.git
cd rcwatch/src
make

./rcwatch rcwatch.conf

Configuration

Example:

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

Parameters

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

Testing

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 run

Project Structure

src/
├── config_manager.cpp
├── process.cpp
├── privilege.cpp
├── restart_manager.cpp
├── logger.cpp
├── rcwatch.cpp
└── ipc/

test/
├── test_config_manager/
├── test_ipc_pipe/
└── test_process/

Design Goals

  • Minimal dependencies
  • Unix-oriented design
  • Separation of privileges
  • Simple and maintainable codebase
  • Educational implementation of service supervision concepts

Future Improvements

  • SIGHUP configuration reload
  • Daemonization support
  • Shared-memory configuration updates
  • Integration tests
  • Makefile/CMake build system
  • Service state persistence
  • Structured logging

License

GPL-3

About

BSD service watchdog

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors