Add daemon mode for background checks with systemd support
- Added daemon command with --interval, --pid-file, --since flags - Configurable check interval (s/m/h/d format) - PID file for status checking - Graceful shutdown on SIGTERM/SIGINT - Structured logging to stderr for systemd journal - Updated README with daemon docs and systemd service template - Added daemon tests (parse_interval, PID file, help)
This commit is contained in:
@@ -12,6 +12,7 @@ Some repositories (e.g., Zammad) only use git tags without creating GitHub relea
|
||||
- Built-in HTTP server for local feed access
|
||||
- Rate-limit-aware GitHub API client
|
||||
- Configurable via environment variables and CLI flags
|
||||
- Daemon mode for automatic background checks
|
||||
|
||||
## Installation
|
||||
|
||||
@@ -60,6 +61,7 @@ ghrel # Main command
|
||||
├── update <owner/repo> [--tags] [--release] # Update tracking mode
|
||||
├── list # List all tracked repositories
|
||||
├── check [--since N] # Fetch latest releases/tags
|
||||
├── daemon [--interval 30m] # Run as background daemon
|
||||
└── serve [--port 8080] [--host 127.0.0.1] # Start HTTP server
|
||||
```
|
||||
|
||||
@@ -117,6 +119,56 @@ ghrel serve # Default: 127.0.0.1:8080
|
||||
ghrel serve --port 9090 --host 0.0.0.0 # Custom port and host
|
||||
```
|
||||
|
||||
### `daemon [--interval INTERVAL] [--pid-file PATH] [--since N]`
|
||||
|
||||
Run as a background daemon that periodically checks all tracked repositories for new releases or tags.
|
||||
|
||||
```bash
|
||||
ghrel daemon # Default: 30m interval
|
||||
ghrel daemon --interval 1h # Check every hour
|
||||
ghrel daemon --interval 15m # Check every 15 minutes
|
||||
ghrel daemon --pid-file /run/ghrel.pid # Custom PID file
|
||||
ghrel daemon --since 24h # Only entries from last 24h
|
||||
```
|
||||
|
||||
**Interval format**: `N` followed by `s` (seconds), `m` (minutes), `h` (hours), or `d` (days).
|
||||
|
||||
The daemon writes a PID file for status checking and sends structured logs to stderr (suitable for systemd journal). It handles `SIGTERM` and `SIGINT` for graceful shutdown.
|
||||
|
||||
#### Systemd Service
|
||||
|
||||
Create `/etc/systemd/system/ghrel-daemon.service`:
|
||||
|
||||
```ini
|
||||
[Unit]
|
||||
Description=GitHub Release Monitor Daemon
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
ExecStart=/usr/local/bin/ghrel daemon --interval 30m --pid-file /run/ghrel.pid
|
||||
Restart=on-failure
|
||||
RestartSec=10
|
||||
Environment=GH_TOKEN=your_token_here
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
```
|
||||
|
||||
Enable and start:
|
||||
|
||||
```bash
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl enable --now ghrel-daemon
|
||||
sudo systemctl status ghrel-daemon
|
||||
```
|
||||
|
||||
View logs:
|
||||
```bash
|
||||
journalctl -u ghrel-daemon -f
|
||||
```
|
||||
```
|
||||
|
||||
## Configuration
|
||||
|
||||
| Setting | Default | Override |
|
||||
|
||||
Reference in New Issue
Block a user