我想自动拉动,停止&当我推送到我的服务器时重启我的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挂钩调用此脚本.启动命令完成?
谢谢你的帮助 ! 🙂
最佳答案 你可以考虑把你的脚本放在post-receive钩子之外,把它放到PATH,然后用一个&的后接收挂钩调用它.最后(以便它与后接收脚本分离).