Created
January 23, 2018 07:22
-
-
Save chrishuan9/c9a3b497398f4fc4689090666fdc7dae to your computer and use it in GitHub Desktop.
cron-monitor for lorawan kerlink iot station
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Description: Script that checks if LoRaWAN packet forwarder is running | |
# On a Kerlink Wirnet Station | |
# | |
# author: Chris Yereaztian <[email protected]> | |
# last-changed: 2017-08-08 | |
PIDFILE=/var/run/firefly.pid | |
## if PID file does not exist process has not been started | |
## | |
if [ ! -f $PIDFILE ]; then | |
echo "LoraWAN Packet Forwarder not running!" | |
/etc/init.d/firefly start | |
exit 0 | |
fi | |
## if PID file exists, read pid and check running process | |
## if process isn't running, packet forwarder has crashed | |
while IFS='' read -r line || [[ -n "$line" ]]; do | |
PID=$line | |
echo "PID is $PID" | |
done < "$PIDFILE" | |
# check that process is running | |
isrunning="$(ps | awk -e '{ print $1}' | grep $PID | wc -l)" | |
# if process is running exit with 0 | |
if [ $isrunning -gt 0 ]; then | |
echo "Isrunning $isrunning" | |
echo "Process is running. Exiting ... "; | |
exit 0 | |
else | |
echo "Process is not running. Restarting system service." | |
/etc/init.d/firefly start | |
exit 0 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment