#!/bin/sh


SMBDPID=/opt/apps/tech.sanway.ecoengine/entries/conf/smbd.pid

# clear conflicting settings from the environment
unset TMPDIR

# See if the daemons are there
test -x /usr/sbin/smbd || exit 0

case $1 in
	start)
             echo $SMBDPID
                if ! start-stop-daemon --start --quiet --oknodo --pidfile $SMBDPID --exec /usr/sbin/smbd -- -D -s /opt/apps/tech.sanway.ecoengine/entries/conf/smb.conf; then
			echo "start error"
			exit 1
		fi

             echo "start success"
		;;
	stop)

		echo "Stopping SMB daemon" smbd

		start-stop-daemon --stop --quiet --pidfile $SMBDPID
		# Wait a little and remove stale PID file
		sleep 1
		if [ -f $SMBDPID ] && ! ps h `cat $SMBDPID` > /dev/null
		then
			# Stale PID file, remove it (should be removed by
			# smbd itself IMHO).
			rm -f $SMBDPID
		fi

		echo "stop success"

		;;
	
	restart|force-reload)
		$0 stop
		sleep 1
		$0 start
		;;
esac

exit 0
