Last active
December 16, 2015 10:09
-
-
Save Notalifeform/5418287 to your computer and use it in GitHub Desktop.
play! framework 1.x init.d file - could need some tuning; use for inspiration only :-)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
### BEGIN INIT INFO | |
# Provides: skeleton | |
# Required-Start: $remote_fs | |
# Required-Stop: $remote_fs | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: Example initscript | |
# Description: This file should be used to construct scripts to be | |
# placed in /etc/init.d. | |
### END INIT INFO | |
# Author: Robert Bakker | |
# Note: first try @ init.d script...returncodes are not right yet | |
# Do NOT "set -e" | |
# PATH should only include /usr/* if it runs after the mountnfs.sh script | |
PATH=/sbin:/usr/sbin:/bin:/usr/bin | |
DESC="Play portal service" | |
NAME=play_portal_production | |
USER=www-data | |
# ENVIRONMENT can be "production" or "staging" - this should equal the mode in the application conf | |
ENVIRONMENT="production" | |
DAEMON=/var/www/play/framework/play/play | |
APPDIR=/var/www/play/application/portal/portal/play | |
PRECOMPILE_MODE=" -Dprecompiled=true" | |
DAEMON_ARGS="/var/www/play/application/portal/portal/play --%prodc" | |
SCRIPTNAME=/etc/init.d/$NAME | |
PIDFILE=$APPDIR"/server.pid" | |
### DO NOT EDIT THIS SCRIPT BELOW THIS LINE ### | |
# Exit if the package is not installed | |
[ -x "$DAEMON" ] || exit 0 | |
# Read configuration variable file if it is present | |
[ -r /etc/default/$NAME ] && . /etc/default/$NAME | |
# Load the VERBOSE setting and other rcS variables | |
. /lib/init/vars.sh | |
# Define LSB log_* functions. | |
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present. | |
. /lib/lsb/init-functions | |
if [ $(id -u) != "0" ] | |
then | |
echo "You should be root to run this script." | |
exit 1 | |
fi | |
# | |
# Function that starts the daemon/service | |
# | |
do_start() | |
{ | |
# Return | |
# 0 if daemon has been started | |
# 1 if daemon was already running | |
# 2 if daemon could not be started | |
if [ $ENVIRONMENT = "production" ] | |
then | |
EXTRAOPT=$PRECOMPILE_MODE | |
fi | |
cleanup_pid_file | |
cd $APPDIR && su $USER -c "umask 002 && $DAEMON start $DAEMON_ARGS $EXTRAOPT" && return 0 | |
# Add code here, if necessary, that waits for the process to be ready | |
# to handle requests from services started subsequently which depend | |
# on this one. As a last resort, sleep for some time. | |
} | |
# | |
# Function that stops the daemon/service | |
# | |
do_stop() | |
{ | |
# Return | |
# 0 if daemon has been stopped | |
# 1 if daemon was already stopped | |
# 2 if daemon could not be stopped | |
# other if a failure occurred | |
cd $APPDIR && su $USER -c "umask 002 && $DAEMON stop $DAEMON_ARGS" && return 0 | |
} | |
do_status() | |
{ | |
# Return | |
# 0 if daemon has been started | |
# 1 if daemon was already running | |
# 2 if daemon could not be started | |
# play status does not like new relic | |
DARGS=`echo $DAEMON_ARGS | sed -e 's/-javaagent.*//'` | |
cd $APPDIR && su $USER -c "umask 002 && $DAEMON status $DARGS" && return 0 | |
# Add code here, if necessary, that waits for the process to be ready | |
# to handle requests from services started subsequently which depend | |
# on this one. As a last resort, sleep for some time. | |
} | |
# | |
# Function that sends a SIGHUP to the daemon/service | |
# | |
do_precompile() { | |
# | |
# If the daemon can reload its configuration without | |
# restarting (for example, when it is sent a SIGHUP), | |
# then implement that here. | |
# | |
if [ $ENVIRONMENT = "staging" ] | |
then | |
echo "Stagin portals do not need precompiling since they run in play development mode." | |
exit 1 | |
fi | |
cd $APPDIR && su $USER -c "umask 002 && $DAEMON precompile " && return 0 | |
return 0 | |
} | |
# | |
# check if we have a bogus pid-file | |
# this could be a left-over from a server-crash | |
# in this case: remove it | |
# | |
cleanup_pid_file() | |
{ | |
pidfile=$PIDFILE | |
#echo $PIDFILE | |
# file does not exist? ok, nothin to do | |
if [ ! -f "$pidfile" ] | |
then | |
return | |
fi | |
procpid=`cat "$pidfile"` | |
# echo "found pid: " $procpid | |
psline=`ps -p $procpid | grep java`; | |
# echo $psline | |
if [ -z "$psline" ] | |
then | |
echo "(check pid) process not running - REMOVING BOGUS PIDFILE $PIDFILE FOR $procpid"; | |
su $USER -c "rm -f $pidfile" | |
else | |
echo "(check pid) process is running ($procpid) - leaving pidfile" | |
fi | |
} | |
case "$1" in | |
start) | |
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME" | |
do_start | |
case "$?" in | |
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; | |
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; | |
esac | |
;; | |
stop) | |
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME" | |
do_stop | |
case "$?" in | |
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; | |
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; | |
esac | |
;; | |
status) | |
[ "$VERBOSE" != no ] && log_daemon_msg "Status $DESC" "$NAME" | |
do_status | |
case "$?" in | |
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; | |
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; | |
esac | |
;; | |
precompile) | |
[ "$VERBOSE" != no ] && log_daemon_msg "Precompiling $DESC" "$NAME" | |
do_precompile | |
case "$?" in | |
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; | |
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; | |
esac | |
;; | |
restart|force-reload) | |
# | |
# If the "reload" option is implemented then remove the | |
# 'force-reload' alias | |
# | |
log_daemon_msg "Restarting $DESC" "$NAME" | |
do_stop | |
case "$?" in | |
0|1) | |
do_start | |
case "$?" in | |
0) log_end_msg 0 ;; | |
1) log_end_msg 1 ;; # Old process is still running | |
*) log_end_msg 1 ;; # Failed to start | |
esac | |
;; | |
*) | |
# Failed to stop | |
log_end_msg 1 | |
;; | |
esac | |
;; | |
*) | |
echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload|precompile|status}" >&2 | |
exit 3 | |
;; | |
esac | |
: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment