#! /bin/bash
# (c) Softaculous Ltd.
# Startup settings control       Bring up/down Startup settings for VPS
#
# chkconfig: 2345 99 90
# description: Activates/Deactivates the Startup settings for VPS
#

### BEGIN INIT INFO
# Provides:         zzvirtservice
# Required-Start: $local_fs $remote_fs $network virtualizor
# Required-Stop: $local_fs $remote_fs $network
# Default-Start: 2 3 4 5
# Default-Stop:	0 1 6
# Short-Description: Activates/Deactivates the Startup settings for VPS (c) Softaculous Ltd.
### END INIT INFO

rc=0

# See how we were called.
case "$1" in

  start)
	echo `date`: Starting...
	/usr/local/emps/bin/php /usr/local/virtualizor/zzvirtservice.php start
	echo `date`: Started
	which systemctl
    	if [ $? == '0' ] ; then
		if [ ! -f /etc/systemd/system/zzvirtservice.service ] ; then
		
			echo "Creating zzvirtservice.service file for systemd"
			echo "Creating zzvirtservice.service file for systemd" > /var/virtualizor/log/virtservice
			ln -s /usr/local/virtualizor/zzvirtservice.service /etc/systemd/system/zzvirtservice.service
			
			# Enable the service as well
			systemctl enable zzvirtservice
			
		fi
	fi
	;;
  stop)
	echo `date`: Stopping...
	/usr/local/emps/bin/php /usr/local/virtualizor/zzvirtservice.php stop
	echo `date`: Stopped
	;;
  status)
	echo `date`: Getting Status...
	/usr/local/emps/bin/php /usr/local/virtualizor/zzvirtservice.php status
	;;

  restart|reload)
    cd "$CWD"
	$0 stop
	$0 start
	;;
  *)
        echo $"Usage: $0 {start|stop|restart|reload}"
        exit 1
esac

exit $rc