Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| gentoo:wireguard [2026/03/16 15:49] – willy | gentoo:wireguard [2026/03/19 08:21] (current) – [Watchdog] willy | ||
|---|---|---|---|
| Line 82: | Line 82: | ||
| # The services you want to restart | # The services you want to restart | ||
| - | SERVICES=" | + | SERVICES=" |
| - | PING_HOST=" | + | PING_HOST=" |
| + | LOG="/ | ||
| FAIL_COUNT_LIMIT=5 | FAIL_COUNT_LIMIT=5 | ||
| PING_TIMEOUT=1 | PING_TIMEOUT=1 | ||
| Line 102: | Line 103: | ||
| start() { | start() { | ||
| ebegin " | ebegin " | ||
| + | echo $(date)" | ||
| while : ; do | while : ; do | ||
| # Perform a quick ping. -q quiet, -c N packets, -W T timeout | # Perform a quick ping. -q quiet, -c N packets, -W T timeout | ||
| if ! ping -q -c ${PING_COUNT} -W ${PING_TIMEOUT} ${PING_HOST} >/ | if ! ping -q -c ${PING_COUNT} -W ${PING_TIMEOUT} ${PING_HOST} >/ | ||
| fail_count=$((fail_count + 1)) | fail_count=$((fail_count + 1)) | ||
| - | echo "Ping to ${PING_HOST} failed (attempt ${fail_count})" | + | echo $(date)" Ping to ${PING_HOST} failed (attempt ${fail_count})" |
| else | else | ||
| fail_count=0 | fail_count=0 | ||
| Line 113: | Line 115: | ||
| # If we hit the threshold, restart | # If we hit the threshold, restart | ||
| if [ " | if [ " | ||
| - | echo " | + | echo $(date)" Consecutive failures reached ${FAIL_COUNT_LIMIT}: |
| restart_service | restart_service | ||
| fail_count=0 | fail_count=0 | ||
| Line 122: | Line 124: | ||
| done & | done & | ||
| PID=$! | PID=$! | ||
| + | echo ${PID} > / | ||
| eend 0 | eend 0 | ||
| } | } | ||
| Line 127: | Line 130: | ||
| stop() { | stop() { | ||
| ebegin " | ebegin " | ||
| - | if [ -n " | + | if [ -f / |
| - | | + | PID=$(cat / |
| - | | + | |
| + | | ||
| + | else | ||
| + | | ||
| fi | fi | ||
| eend 0 | eend 0 | ||
| Line 141: | Line 147: | ||
| / | / | ||
| </ | </ | ||
| + | |||
| + | As a final note, don't forget to put log file **/ | ||