Skip to content

Instantly share code, notes, and snippets.

@thomo
Last active January 4, 2016 14:46
Show Gist options
  • Save thomo/80b11f1637c66bae326b to your computer and use it in GitHub Desktop.
Save thomo/80b11f1637c66bae326b to your computer and use it in GitHub Desktop.
initd script to start pir sensor monitor
#!/bin/sh
# chkconfig: 123456 90 10
# Startscript fuer den PIR-Sensor
#
verzeichnis=/usr/local/bin
scriptname=pi-pir.py
start() {
cd $verzeichnis
/usr/bin/python $verzeichnis/$scriptname 2>&1 >> /var/log/pirsensor.log &
echo "PIR-Sensor gestartet."
}
stop() {
pid=`ps -ef | grep "[p]ython $verzeichnis/$scriptname" | awk '{ print $2 }'`
[ -n "$pid" ] && echo "found running script: $pid"
[ -n "$pid" ] && kill $pid
sleep 2
echo "PIR-Sensor beendet."
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo "Benutzung: /etc/init.d/pirsensor {start|stop|restart}"
exit 1
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment