#!/bin/sh
#
# SGINet light http ping daemon
# flexion 2026
#
# Version 20260221-0930
#
# Periodically sends a sign of life to the SGINet cloud through a local nginx proxy
#
# Installation instructions:
#
# Place the sginet-light-http executable in /usr/sgug/bin/ 
# copy this service file to /etc/init.d and run:
# sudo ln -s /etc/init.d/sginet-light-daemon /etc/rc2.d/S89sginet-light
# sudo ln -s /etc/init.d/sginet-light-daemon /etc/rc0.d/K02sginet-light
# sudo chkconfig -f sginet-light-daemon on
#
# Configure nginx proxy name (or IP) and port below:

NGINX_PROXY_ADDR="sginet-proxy.local"
NGINX_PROXY_PORT="8077"

IS_ON=/etc/chkconfig
CONFIG=/etc/config
DAEMON="/usr/sgug/bin/sginet-light-http -s --proxyhost $NGINX_PROXY_ADDR --port $NGINX_PROXY_PORT"

if $IS_ON verbose; then
        ECHO=echo
else
    	# For a quiet startup and shutdown
        ECHO=:
fi

case "$1" in
	'start')
        if $IS_ON sginet-light-daemon && test -x $DAEMON ; then
                $ECHO "[sginet-light-daemon] Starting up\c"
                $DAEMON
                $ECHO "."
        fi
	;;

	'stop')
        if test -x $DAEMON ; then
                $ECHO "[sginet-light-daemon] Stopping\c"
                /etc/killall -TERM sginet-light-http
                $ECHO "."
        fi
	;;

        'restart')
        if $IS_ON sginet-light-daemon && test -x $DAEMON ; then
                $ECHO "[sginet-light-daemon] Restarting\c"
                /etc/killall -TERM sginet-light-http
                $DAEMON
                $ECHO "."
        fi
	;;

	*)
	echo "usage: $0 {start|stop|restart}"
        ;;
esac
