4

当我推送到我的服务器时,我想自动拉取、停止和重新启动我的 Play Framework 2.1 实例。

我制作了一个从命令行运行的 bash 脚本来执行所有操作,但我希望它在推送后自动运行。我想通过一个post-receive钩子来执行它,但是脚本运行时间太长,并且退出太快。

(需要太长时间的是 compile & stage 命令)

这是我的脚本:

#!/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

如何在不等待整个停止、编译、阶段和启动命令完成的情况下从我的接收后挂钩调用此脚本?

4

1 回答 1

2

您可以考虑将脚本放在 post-receive 钩子之外,将其放在 PATH 中,然后从 post-receive 钩子中调用它,并&在末尾加上 a(以便它与 post-receive 脚本分离运行)。

于 2012-12-14T17:02:22.077 回答