Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #!/bin/bash
  2. #
  3. # Play Admin Script
  4. # This script is to be used to handle operations with our Play
  5. # servers. This script is able to start, stop, and report on the
  6. # status of our servers
  7. #
  8.  
  9. play_home="/home/play"
  10. app_id="my-play-app"
  11. app_port="9000"
  12. out_file="${play_home}/logs/${app_id}/${app_id}.out"
  13.  
  14. do_start () {
  15.     local app_path="${play_home}/webapps/${app_id}"
  16.     local config_file="${play_home}/etc/application.conf"
  17.     local logger_file="${play_home}/etc/logger.xml"
  18.     local path="${play_home}/lib/play/*:${app_path}/current/*"
  19.     local opts="-Dapp.id=${app_id} -Dhttp.port=${app_port} -Xms128m -Xmx512m -server -XX:MaxPermSize=128m -Dconfig.file=${config_file} -Dlogger.file=${logger_file}"
  20.  
  21.     local exit_code=10
  22.     while [ $exit_code -eq 10 ]; do
  23.         "${JAVA_HOME}/bin/java" ${opts} -cp "${path}" play.core.server.NettyServer "${app_path}"
  24.         exit_code=$?
  25.     done
  26. }
  27.  
  28. do_stop () {
  29.     pkill -f "app.id=${app_id}"
  30.     exit $?
  31. }
  32.  
  33. do_status () {
  34.     pkill -0 -f "app.id=${app_id}" > /dev/null 2>&1 && echo "Process is running" && exit 0
  35.     echo "Process is not running" && exit 0
  36. }
  37.  
  38. ### main ###
  39.  
  40. if [ "$(whoami)" != "play" ]; then
  41.    echo "This script must be run as ubuntu user" 1>&2
  42.    exit 1
  43. fi
  44.  
  45. if [ "${JAVA_HOME}" == "" ]; then
  46.     echo "JAVA_HOME Not set. Install the JRE and set the JAVA_HOME in your initialization file"
  47.     exit 1
  48. fi
  49.  
  50. if [ ! -d "${JAVA_HOME}" ] ; then
  51.     echo "Java ${JAVA_HOME} Directory doesn't exist."
  52.     exit 1
  53. else
  54.     if [ ! -x "${JAVA_HOME}/bin/java" ] ; then
  55.         echo "Java binary error: not found or not executable"
  56.         exit 1
  57.     fi
  58. fi
  59.  
  60. case ${1} in
  61.     start)
  62.         do_start
  63.     ;;
  64.  
  65.     stop)
  66.         do_stop
  67.     ;;
  68.  
  69.     status)
  70.         do_status
  71.     ;;
  72.  
  73.     nohup)
  74.         nohup $0 $1 start > "${out_file}" 2>&1 &
  75.     ;;
  76.  
  77.     *)
  78.         echo "Usage: $0 start|nohup|stop|status"
  79.         exit 1
  80.     ;;
  81. esac
  82.  
  83. exit 0