#!/bin/bash

case "$1" in
stop)
echo "Stopping manchon UPnP"
# kill all the processes like lil bitches
killall -9 python
killall -9 pigpiod
rm /var/run/manchonrunning
;;

start)
echo "Starting manchon UPnP"
echo "Starting\n" >> /home/pi/software/upnp/manchon.log

if [ -f /var/run/manchonrunning ]; then
    echo "already started. aborting"
    exit 0;
fi

touch /var/run/manchonrunning

/home/pi/software/flowsensor/PIGPIO/pigpiod
cd /home/pi/software/upnp/
python manchon.py >>/home/pi/software/upnp/manchon.log 2>&1 &
;;

*)
echo "Usage: /etc/init.d/manchon {start|stop}"
exit 1
;;
esac
