#!/bin/sh

# AthenaċNXNvg
#
#  [USAGE] ./start
#
#  AthenaNԂł͎sȂŉB
#  T[o[̏ԂmFXNvg삷̂ŁAVFɖ߂܂B
#  Athena~߂Ƃ Ctrl+C ŏIĂB
#@
#   ./start & ƂăobNOEhŋN
#  VFɖ߂Ă܂AT[o[̒~ʓ|łB

L_SRV=./bin/login-server
C_SRV=./bin/char-server
M_SRV=./bin/map-server

if [ $(ps ax | grep -E "${M_SRV}|${C_SRV}|${L_SRV}" | grep -v grep | wc -l) -ne 0 ]; then
	echo "Athena is already running..."
else
	./athena-start start
	sleep 30
	
	while true
	do
		if [ $(ps ax | grep -E "${M_SRV}|${C_SRV}|${L_SRV}" | grep -v grep | wc -l) -lt 3 ]; then
			printf "Error:"
			date
			sleep 10
			printf "Checking:"
			date
			if [ $(ps ax | grep -E "${M_SRV}|${C_SRV}|${L_SRV}" | grep -v grep | wc -l) -lt 3 ]; then
				printf "Error Confirmation:"
				date
				printf "Restoration:"
				date
				./athena-start restart
				else
				printf "Check Miss Sorry:"
				date
			fi
		#else
			#printf "Check OK:"
			#date
		fi
		sleep 10
	done
fi
