- basics of init-script working

- basic shell script which enables virtualenv environment and calls traceroute.py at intervals
- added stubs to only call webhook based on a specified latency
- still need to store offline data in redis - coming soon
This commit is contained in:
Brian Martin 2015-07-27 22:40:40 -04:00
commit ffd8158c25
4 changed files with 152 additions and 7 deletions

64
init-script/traceroute Normal file
View file

@ -0,0 +1,64 @@
#!/bin/bash
# traceroute.py daemon
# chkconfig: 345 20 80
# description: traceroute.py daemon
# processname: traceroute.py
DAEMON_PATH="/var/lib/python/traceroute"
DAEMON=traceroute.sh
DAEMONOPTS=""
NAME=traceroute.py
DESC="Traceroute Python Tool"
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
case "$1" in
start)
printf "%-50s" "Starting $NAME..."
cd $DAEMON_PATH
PID=`$DAEMON $DAEMONOPTS > /dev/null 2>&1 & echo $!`
#echo "Saving PID" $PID " to " $PIDFILE
if [ -z $PID ]; then
printf "%s\n" "Fail"
else
echo $PID > $PIDFILE
printf "%s\n" "Ok"
fi
;;
status)
printf "%-50s" "Checking $NAME..."
if [ -f $PIDFILE ]; then
PID=`cat $PIDFILE`
if [ -z "`ps axf | grep ${PID} | grep -v grep`" ]; then
printf "%s\n" "Process dead but pidfile exists"
else
echo "Running"
fi
else
printf "%s\n" "Service not running"
fi
;;
stop)
printf "%-50s" "Stopping $NAME"
PID=`cat $PIDFILE`
cd $DAEMON_PATH
if [ -f $PIDFILE ]; then
kill -HUP $PID
printf "%s\n" "Ok"
rm -f $PIDFILE
else
printf "%s\n" "pidfile not found"
fi
;;
restart)
$0 stop
$0 start
;;
*)
echo "Usage: $0 {status|start|stop|restart}"
exit 1
esac

19
init-script/traceroute.sh Executable file
View file

@ -0,0 +1,19 @@
#!/bin/bash
EXEC_DIR=/var/lib/python/traceroute
VIRTUALENV_DIR=/var/lib/python/traceroute/env
# Repeat every 5 seconds
INTERVAL=5 #
source $VIRTUALENV_DIR/bin/activate
cd $EXEC_DIR
# TODO add some logging later
while true;
do
python ./traceroute.py --ip_address=8.8.8.8 -c LO --webhook=http://localhost:8081/test;
sleep $INTERVAL;
done