#!/bin/sh # this might make systemd actually listen to us export XDG_RUNTIME_DIR=/run/user/1001 echo -e "$(date)\tPING 172.16.69.2 $(ping -qc1 172.16.69.2 2>&1 | awk -F'/' 'END{ print (/^rtt/? "OK "$5" ms":"FAIL") }')" >> /tmp/monitor.log ping -c 1 172.16.69.4 >/dev/null 2>&1 good=0 for i in {1..3}; do http_proxy='' curl --fail -so /dev/null https://twibooru.org if [[ $? -eq 0 ]]; then good=1 break fi echo -e "$(date)\tAttempt $i, cURL exited nonzero, good=0" >> /tmp/monitor.log done if [[ $good -eq 0 ]]; then echo -e "$(date)\tSite's down, restarting" >> /tmp/monitor.log systemctl --user restart twibooru sleep 10 # so we don't flap or anything else echo -e "$(date)\tOK" >> /tmp/monitor.log fi exit 0