#!/bin/bash
# processname: /usr/local/measure/trh/trh
# description: Temperarure and relative humidiy measure using specific sensor (DHT11,DHT22) by Hgtri

DAEMON="/usr/local/measure/trh/trh"
LOCK="/var/lock/trh"
PROGNAME="T & RH measure using DHT11 or DTH22 by Hgtri"

#start記憶ファイルのフルパスと名前
sname="/usr/local/measure/trh/trhstart.mem"

. /lib/lsb/init-functions

RETVAL=0

start() {
	log_daemon_msg "Starting $PROGNAME"
	echo "1" > $sname
        #$DAEMON & > /dev/null 2>&1
	/usr/local/measure/trh/trh &
	sleep 1
	RETVAL=$?
	echo
	[ $RETVAL = 0 ] && touch $LOCK
	log_end_msg 0
	return $RETVAL
}

stop() {
	log_daemon_msg "Stopping $PROGNAME"
	echo "0" > $sname
	sleep 1
	RETVAL=$?
	echo
	[ $RETVAL = 0 ] && rm -f $LOCK
	log_end_msg 0
	return $RETVAL
}


test -x $DAEMON || exit 0
case "$1" in

  start)
        start
	;;
  stop)
        stop
	;;
  restart)
	stop
	start
	;;
  status)
    	if [ -e $LOCK ]
    	then
        	echo "$PROGNAME is running."
    	else
        	echo "$PROGNAME is not running."
    	fi
	;;
   *)
   	echo "Usage: $0 {start|stop|restart|status}"
	exit 1
esac

exit $RETVAL

