#!/bin/bash
#
# Play Admin Script
# This script is to be used to handle operations with our Play
# servers. This script is able to start, stop, and report on the
# status of our servers
#
play_home="/home/play"
app_id="my-play-app"
app_port="9000"
out_file="${play_home}/logs/${app_id}/${app_id}.out"
do_start () {
local app_path="${play_home}/webapps/${app_id}"
local config_file="${play_home}/etc/application.conf"
local logger_file="${play_home}/etc/logger.xml"
local path="${play_home}/lib/play/*:${app_path}/current/*"
local opts="-Dapp.id=${app_id} -Dhttp.port=${app_port} -Xms128m -Xmx512m -server -XX:MaxPermSize=128m -Dconfig.file=${config_file} -Dlogger.file=${logger_file}"
local exit_code=10
while [ $exit_code -eq 10 ]; do
"${JAVA_HOME}/bin/java" ${opts} -cp "${path}" play.core.server.NettyServer "${app_path}"
exit_code=$?
done
}
do_stop () {
pkill -f "app.id=${app_id}"
exit $?
}
do_status () {
pkill -0 -f "app.id=${app_id}" > /dev/null 2>&1 && echo "Process is running" && exit 0
echo "Process is not running" && exit 0
}
### main ###
if [ "$(whoami)" != "play" ]; then
echo "This script must be run as ubuntu user" 1>&2
exit 1
fi
if [ "${JAVA_HOME}" == "" ]; then
echo "JAVA_HOME Not set. Install the JRE and set the JAVA_HOME in your initialization file"
exit 1
fi
if [ ! -d "${JAVA_HOME}" ] ; then
echo "Java ${JAVA_HOME} Directory doesn't exist."
exit 1
else
if [ ! -x "${JAVA_HOME}/bin/java" ] ; then
echo "Java binary error: not found or not executable"
exit 1
fi
fi
case ${1} in
start)
do_start
;;
stop)
do_stop
;;
status)
do_status
;;
nohup)
nohup $0 $1 start > "${out_file}" 2>&1 &
;;
*)
echo "Usage: $0 start|nohup|stop|status"
exit 1
;;
esac
exit 0