public
Last active

init.d script to launch Play framework under CentOS/RedHat

  • Download Gist
gistfile1.sh
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
#!/bin/bash
# chkconfig: 345 20 80
# description: Play start/shutdown script
# processname: play
#
# Instalation:
# copy file to /etc/init.d
# chmod +x /etc/init.d/play
# chkconfig --add /etc/init.d/play
# chkconfig play on
#
# Usage: (as root)
# service play start
# service play stop
# service play status
#
# Remember, you need python 2.6 to run the play command, it doesn't come standard with RedHat/Centos 5.5
# Also, you may want to temporarily remove the >/dev/null for debugging purposes
 
# Path to play install folder
PLAY_HOME=/path/to/play_home
PLAY=$PLAY_HOME/play
 
# Path to the JVM
JAVA_HOME=/path/to/java_home
export JAVA_HOME
 
# User running the Play process
USER=apache
 
# Path to the application
APPLICATION_PATH=/path/to/application
APPLICATION_MODE=prod
 
#APPLICATION2_PATH=/path/to/application2
#APPLICATION_MODE=prod
 
# source function library
. /etc/init.d/functions
RETVAL=0
 
start() {
echo -n "Starting Play service: "
su -s /bin/sh $USER -c "${PLAY} start ${APPLICATION_PATH} --%${APPLICATION_MODE} >/dev/null"
RETVAL=$?
# You may want to start more applications as follows
# [ $RETVAL -eq 0 ] && su -s /bin/sh $USER -c "${PLAY} start ${APPLICATION2_PATH} --%${APPLICATION_MODE} > /dev/null"
# RETVAL=$?
 
if [ $RETVAL -eq 0 ]; then
echo_success
else
echo_failure
fi
echo
}
stop() {
echo -n "Shutting down Play service: "
${PLAY} stop ${APPLICATION_PATH} > /dev/null
# ${PLAY} stop ${APPLICATION2_PATH} > /dev/null
RETVAL=$?
 
if [ $RETVAL -eq 0 ]; then
echo_success
else
echo_failure
fi
echo
}
status() {
${PLAY} status ${APPLICATION_PATH}
#${PLAY} status ${APPLICATION2_PATH}
RETVAL=$?
}
clean() {
rm -f ${APPLICATION_PATH}/server.pid
#rm -f ${APPLICATION2_PATH}/service.pid
}
case "$1" in
start)
clean
start
;;
stop)
stop
;;
restart|reload)
stop
sleep 10
start
;;
status)
status
;;
clean)
clean
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
esac
exit 0

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.