Skip to content

Instantly share code, notes, and snippets.

@Itaqua
Forked from THemming/gist:2173037
Last active December 16, 2018 15:52
Show Gist options
  • Save Itaqua/3866098 to your computer and use it in GitHub Desktop.
Save Itaqua/3866098 to your computer and use it in GitHub Desktop.
init.d script to launch Play framework under CentOS/RedHat
#!/bin/bash
# chkconfig: 345 84 80
# description: Play start/shutdown script
# processname: play
#
# author: Octavio Luna
# email: [email protected]
#
# 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: "
rm -f ${APPLICATION_PATH}/server.pid
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=$?
}
case "$1" in
start)
clean
start
;;
stop)
stop
;;
restart|reload)
stop
sleep 10
start
;;
status)
status
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment