我一直在尝试为我的play2应用程序编写一个启动脚本,但我不能让它作为后台任务工作。我从docs开始,并提出了下面的脚本。
脚本:
#! /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
我已经谷歌问题并找到像this这样的解决方案,但他们正在使用 我在 Red Hat Enterprise Linux Server 5.6(Tikanga) dist上没有的 start-stop-daemon 。如果可能的话,我宁愿不安装任何其他软件来使这项工作。我错过了什么让这项工作作为后台任务并将其从控制台中分离出来? CTRL + D不起作用,CTRL + C退出该过程。
答案 0 :(得分:1)
好的,这是来自favoretti的提示之后的一个解决方案:
#! /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
# created by: Jakob
. /etc/rc.d/init.d/functions
PLAY_HOME=/opt/play
PLAY=$PLAY_HOME/play
NAME=autocomplete
DESC="autocomplete application"
# 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: $APPLICATION_PATH/target/start $DAEMON_OPTS &"
$APPLICATION_PATH/target/start $DAEMON_OPTS &
}
stop()
{
echo -n $"Stopping $DESC:"
kill `cat $APPLICATION_PATH/RUNNING_PID`
}
case "$1" in
start)
start
;;
stop)
stop
;;
esac
exit $RETVAL
你需要按CTRL + D离开控制台,这不是我想到的。也许有人有更好的解决方案?
答案 1 :(得分:0)
这是我在Amazon AMI Linux下自动启动Play 2.2应用程序的版本。这同样适用于CentOS和RedHat。其他Linux风格可能需要很少的适应。该脚本在单独的用户下启动播放应用程序。
#!/bin/bash
# description: MyWorkCalendar Play App
# processname: myworkcalendar
# chkconfig: 234 20 80
# User running the Play process
USER=mywork
USER_HOME=/home/mywork
# Java home, add java and play to path
export JAVA_HOME=$USER_HOME/java_home
export PATH=$JAVA_HOME/bin:$USER_HOME/play_home:$PATH
# Path to the application
APP_PATH=$USER_HOME/app/work-calendar/target/universal/stage
APP_OPTS="-Dconfig.file=$APP_PATH/conf/application-prod.conf"
RETVAL=0
case "$1" in
start)
echo -n "Starting Play service"
rm -f ${APP_PATH}/RUNNING_PID
su $USER -c "$APP_PATH/bin/myworkcalendar $APP_OPTS >/dev/null" &
RETVAL=$?
;;
stop)
echo -n "Shutting down Play service"
kill `cat $APP_PATH/RUNNING_PID`
RETVAL=$?
;;
esac
exit $RETVAL
将脚本放到/etc/init.d,使其可执行并使用chkconfig注册:
sudo chmod 755 script-name
sudo chkconfig --add script-name
sudo chkconfig script-name on
答案 2 :(得分:-1)
以下是我的Play 2.2启动/停止脚本版本:
http://vladsprogrammingblog.blogspot.com/2014/01/play-startstop-script.html