#!/bin/bash
### BEGIN INIT INFO
# Provides:          new_twitter_sensor
# Required-Start:    $local_fs $remote_fs $network $syslog
# Required-Stop:     $local_fs $remote_fs $network $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts new_twitter_sensor
# Description:       starts new_twitter_sensor
### END INIT INFO

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
NAME=new_twitter_sensor
DESC=new_twitter_sensor

SM_HOME=/opt/bertin/mediacentric/bin
LAUNCHER=$SM_HOME/scrap_engine.sh
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
PORT=4063

test -x $LAUNCHER || exit 0


. /lib/lsb/init-functions

d_start() {
   $LAUNCHER -p $PORT start
}

d_stop() {
   $LAUNCHER -p $PORT stop
}

d_status() {
   $LAUNCHER -p $PORT status
}
case "$1" in
 start)
	 echo -n "Starting $DESC: "
	 if d_status; then
		 echo "$NAME is already running."
		 exit 1
	 fi
	 d_start
	 sleep 1
	 if d_status; then echo "OK"
	 else echo "KO"; exit 1
	 fi
	 ;;
 stop)
	 if d_status; then
	 	echo -n "Stopping $DESC: "
		 d_stop
		 sleep 1
		 if d_status; then echo "$NAME is still running"; exit 1
		 else echo "OK"
		 fi
	 else
	 	echo "$DESC is already stopped"
		exit 1
	 fi
	 ;;
 status)
	 if d_status; then echo "$NAME is running"
	 else echo "$NAME is not running"; exit 1
	 fi
	 ;;
 restart|force-reload)
	 echo -n "Restarting $DESC"
	 d_stop
	 d_start
	 echo "."
	;;
 *)
	 echo "Usage: $SCRIPTNAME {start|stop|restart|status}" >&2
	 exit 1
	 ;;
esac

exit 0

