Skip to content

Instantly share code, notes, and snippets.

@SamVanhoutte
Forked from clemensv/azureobd
Created April 10, 2014 12:23
Show Gist options
  • Save SamVanhoutte/10376130 to your computer and use it in GitHub Desktop.
Save SamVanhoutte/10376130 to your computer and use it in GitHub Desktop.
#! /bin/bash
### BEGIN INIT INFO
# Provides: azureobd
# Required-Start: $remote_fs $syslog $network $all
# Required-Stop: $remote_fs $syslog $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start AzureOBD at boot time
# Description: Start AzureOBD at boot time.
### END INIT INFO
# /etc/init.d/azureobd
USER=root
HOME=/root
VNCUSER=pi
RETRYCOUNT=20
export USER HOME
case "$1" in
start)
until [ $RETRYCOUNT -lt 1 ]; do
if ping -w 4 -I wlan0 -c 1 8.8.8.8 > /dev/null
then
echo "$(date) Network connection available" >> /var/log/azureobd.log
break
else
echo "$(date) Still trying network connection ..." >> /var/log/azureobd.log
fi
let RETRYCOUNT-=1
echo "$(date) Retry $RETRYCOUNT"
sleep 5
done
echo "$(date) Starting Azure OBD-2" >> /var/log/azureobd.log 2>&1
/usr/bin/azureobdlogger -s /dev/ttyUSB0 -b 38400 -q amqps://owner:{KEY}@{NAMESPACE}.servicebus.windows.net/{QUEUE} >> /var/log/azureobd.log 2>&1 &
echo "." >> /var/log/azureobd.log 2>&1
;;
stop)
echo "$(date) Stopping Azure OBD-2" >> /var/log/azureobd.log 2>&1
killall azureobdlogger
echo "." >> /var/log/azureobd.log 2>&1
;;
*)
echo "Usage: /etc/init.d/azurobd {start|stop}"
exit 1
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment