我想自动拉动,停止&当我推送到我的服务器时重启我的Play Framework 2.1实例。
我创建了一个bash脚本,我从命令行运行以执行所有操作,但我希望它在推送后自动运行。我想通过post-receive
钩子执行它,但脚本运行时间太长,退出太快。
(编译和扩展命令需要太长时间)
这是我的剧本:
#!/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
如何从我的post-receive挂钩调用此脚本而无需等待整个停止,编译,阶段和放大启动命令完成?
感谢您的帮助! :)
答案 0 :(得分:2)
你可以考虑将你的脚本放在post-receive钩子之外,把它放到PATH中,然后在post-receive hook中调用它,最后用&
调用它(这样它就会从post中分离出来) - 接收剧本)。