#!/bin/bash
# VERSION=1

BEROCONF="/usr/fallback/beroconf"

function log () {
	echo "[init_cloud] ${1}"
}

function start () {
	# if cloud disabled, leave
	if [ "$(${BEROCONF} get root redirect_cfg | grep -v failed)" == "off" ]; then
		log "Disabled."
		exit 0
	fi
	# get the redirect_server
	# redirect_server=$(${BEROCONF} get root redirect_server | grep -v failed)
	
	/usr/bin/env -i bash -c "/usr/local/php/redirect.php"

	log "Started."
}

function stop () {
	log "Stopped."
}

case "${1}" in
	start)
		start
		;;
	stop)
		stop
		;;
	restart)
		stop
		sleep 1
		start
		;;
	*)
		echo "Usage: ${0} [start|stop|restart]" >&2
		exit 1
		;;
esac

exit 0
