我一直在尝试为我的 play2 应用程序编写启动脚本,但我无法让它作为后台任务工作。我从文档开始,想出了下面的脚本。
脚本:
#! /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
我用谷歌搜索了这个问题并找到了这样的解决方案,但他们使用的是 我的Red Hat Enterprise Linux Server 5.6 (Tikanga) dist上没有的start-stop-daemon 。如果可能的话,我宁愿不安装任何其他软件来完成这项工作。为了使这项工作作为后台任务并将其与控制台分离,我错过了什么?CTRL+D 不起作用,CTRL+C 退出进程。