I've been trying to write a startup script for my play2 application but I can't get it to work as a background task. I started out at the docs and came up with the script below.
Script:
#! /bin/sh
# description: Starts autocomplete play app using daemon
# 1. Go to $APPLICATION_PATH and prepare for dev by doing: play clean compile stage
# This will create a start script at target/start
# 2. Start the application by running this script
. /etc/rc.d/init.d/functions
PLAY_HOME=/opt/play
PLAY=$PLAY_HOME/play
NAME=autocomplete
DESC="autocomplete application"
PID_FILE=/var/run/autocomplete/$NAME.pid
# Path to the JVM
JAVA_HOME=/usr/java/latest
export JAVA_HOME
export PATH=$PATH:$JAVA_HOME/bin
APPLICATION_PATH=/opt/playapps/autocomplete
DAEMON_OPTS="-Dconfig.file=/opt/playapps/autocomplete/conf/application-dev.conf"
start()
{
echo -n "Starting $DESC with: --pidfile $PID_FILE ${APPLICATION_PATH}/target/start $DAEMON_OPTS"
daemon --pidfile $PID_FILE "${APPLICATION_PATH}/target/start $DAEMON_OPTS"
}
stop()
{
echo -n $"Stopping $DESC:"
#NOT DONE YET
}
case "$1" in
start)
start
;;
stop)
stop
;;
esac
exit $RETVAL
I have google the issue and found solutions like this but they are using the start-stop-daemon that I do not have on my Red Hat Enterprise Linux Server release 5.6 (Tikanga) dist. I would rather not install any other software to make this work if it's possible. What have I missed to make this work as a background task and detach it from the console? CTRL+D do not work and CTRL+C quits the process.