Skip to content

Instantly share code, notes, and snippets.

@chrishuan9
Created January 23, 2018 07:22
Show Gist options
  • Save chrishuan9/c9a3b497398f4fc4689090666fdc7dae to your computer and use it in GitHub Desktop.
Save chrishuan9/c9a3b497398f4fc4689090666fdc7dae to your computer and use it in GitHub Desktop.
cron-monitor for lorawan kerlink iot station
#!/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