I'd like to automatically pull, stop & restart my Play Framework 2.1 instance when I push to my server.
I made a bash script that I run from the command line to do all the stuff, but I'd like it to be run automatically after a push. I thought to execute it via a post-receive hook but the script take too long to be run, and exit too quickly.
(What takes too long is the compile & stage command)
Here's my script :
#!/bin/bash
#
# /etc/rc.d/init.d/myscript
#
# Starts the myscript Play Framework daemon
#
### BEGIN INIT INFO
# Provides: myscript
# Required-Start: $local_fs $remote_fs $network $syslog
# Required-Stop: $local_fs $remote_fs $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start myscript server at boot time
### END INIT INFO
### BEGIN vars
PORT=9500
BASE_DIR=/path/to/project/
ENV=dev
PLAY_VERSION=2.1rc1
### END vars
#export _JAVA_OPTIONS="-Xms64m -Xmx1024m -Xss2m"
# Exit immediately if a command exits with a nonzero exit status.
set -e
update() {
    cd $BASE_DIR$ENV
    # Updating the project
    git pull origin master
    # Creating new project (MUST BE ON THE GOOD DIR)
    /opt/play/$PLAY_VERSION/play clean compile stage
}
start() {
    /sbin/start-stop-daemon --start --quiet --oknodo --user cyril --chuid cyril --background --startas $BASE_DIR$ENV"/target/start" -- "-Dhttp.port="$PORT" -Dconfig.file="$BASE_DIR$ENV".conf"
}
stop() {
    /sbin/start-stop-daemon --stop --quiet --oknodo --user cyril --chuid cyril --pidfile $BASE_DIR$ENV"RUNNING_PID"
    rm -f $BASE_DIR$ENV"RUNNING_PID"
}
case "$1" in
    start)
        echo "Updating and starting the server"
        update
        start
    ;;
    force-start)
        echo "Starting server"
        start
    ;;
    stop)
        echo "Stopping server"
        stop
    ;;
    restart)
        echo "Updating and re-starting the server"
        stop
        update
        start
    ;;
    force-restart)
        echo "Re-starting the server"
        stop
        start
    ;;
    *)
        echo $"Usage: $0 {start|force-start|stop|restart|force-restart}"
esac
exit 0
How can I do to call this script from my post-receive hook without waiting the whole stop, compile, stage & start commands to be completed ?
 
     
    