Skip to content

Commit 8a77680

Browse files
committed
Add systemd service support
1 parent 037bb7a commit 8a77680

2 files changed

Lines changed: 73 additions & 0 deletions

File tree

README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,44 @@ To build the project with CMake, you need to have CMake and GTest installed.
354354
./test/unit_tests
355355
```
356356

357+
## Systemd Service Installation (optional)
358+
359+
For production deployment on systemd-based Linux systems, you can install processWatchdog as a system service:
360+
361+
1. **Build and install the binary:**
362+
```bash
363+
make BUILD_TYPE=release
364+
sudo cp processWatchdog /usr/local/bin/
365+
sudo chmod +x /usr/local/bin/processWatchdog
366+
```
367+
368+
2. **Create configuration directory:**
369+
```bash
370+
sudo mkdir -p /etc/processwatchdog
371+
sudo mkdir -p /var/lib/processwatchdog
372+
sudo cp config.ini /etc/processwatchdog/
373+
```
374+
375+
3. **Install the service file:**
376+
```bash
377+
sudo cp processwatchdog.service /etc/systemd/system/
378+
sudo systemctl daemon-reload
379+
```
380+
381+
4. **Enable and start the service:**
382+
```bash
383+
sudo systemctl enable processwatchdog
384+
sudo systemctl start processwatchdog
385+
```
386+
387+
5. **Check service status:**
388+
```bash
389+
sudo systemctl status processwatchdog
390+
sudo journalctl -u processwatchdog -f # Follow logs
391+
```
392+
393+
**Note:** Edit `/etc/processwatchdog/config.ini` and adjust paths in `processwatchdog.service` as needed for your setup.
394+
357395
## Running the Application
358396
Use the provided `run.sh` script to start the Process Watchdog application. This script includes a mechanism to restart the watchdog itself if it crashes, providing an additional level of protection.
359397

processwatchdog.service

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
[Unit]
2+
Description=Process Watchdog - Monitor and restart applications
3+
Documentation=https://github.com/diffstorm/processWatchdog
4+
After=network.target
5+
Wants=network.target
6+
7+
[Service]
8+
Type=simple
9+
ExecStart=/usr/local/bin/processWatchdog -i /etc/processwatchdog/config.ini
10+
ExecReload=/bin/kill -SIGUSR1 $MAINPID
11+
Restart=on-failure
12+
RestartSec=5
13+
TimeoutStopSec=30
14+
15+
# Security settings
16+
NoNewPrivileges=true
17+
PrivateTmp=true
18+
ProtectSystem=strict
19+
ProtectHome=true
20+
ReadWritePaths=/var/log /var/run /tmp
21+
22+
# User and group (uncomment and adjust as needed)
23+
# User=processwatchdog
24+
# Group=processwatchdog
25+
26+
# Working directory
27+
WorkingDirectory=/var/lib/processwatchdog
28+
29+
# Logging
30+
StandardOutput=journal
31+
StandardError=journal
32+
SyslogIdentifier=processwatchdog
33+
34+
[Install]
35+
WantedBy=multi-user.target

0 commit comments

Comments
 (0)