我有播放应用程序,以便在Debian上轻松部署,
的方法是什么?使用标准的init.d脚本从代码中创建一个守护进程,这里的主要问题是如何优雅地停止应用程序?
如何将代码编译为胖jar,与多个文件和目录(部署Play应用程序的标准方式)相比,易于维护1个文件。
答案 0 :(得分:9)
/etc/init.d/play.myplayapp
#! /bin/sh
### BEGIN INIT INFO
# Provides: play
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description:
# Description:
### END INIT INFO
APP="myplayapp"
APP_PATH="/opt/play/$APP"
start() {
$APP_PATH/start &
}
stop() {
kill `cat $APP_PATH/RUNNING_PID`
}
case "$1" in
start)
echo "Starting $APP"
start
echo "$APP started."
;;
stop)
echo "Stopping $APP"
stop
echo "$APP stopped."
;;
restart)
echo "Restarting $APP."
stop
sleep 2
start
echo "$APP restarted."
;;
*)
N=/etc/init.d/play.$APP
echo "Usage: $N {start|stop|restart}" >&2
exit 1
;;
esac
exit 0
2。他们实际上没有单个项目文件分发。你能做的最好的就是运行“play dist”来生成一个可分发的包。即使它是作为单个文件分发的,它也可能在运行时被提取到文件系统,只是为了提高效率(只是如何处理war文件)。
答案 1 :(得分:0)
我准备了与play 2.2.x软件包兼容的新版脚本:
https://github.com/mgosk/play-app-deamon
#! /bin/sh
### BEGIN INIT INFO
# Provides: play
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description:
# Description:
### END INIT INFO
# configurable variables
APP_NAME="myplayapp"
APP_DIR="/opt/myplayapp"
CONF="application.conf"
# private variables
APP_SCRIPT="$APP_DIR/bin/$APP_NAME"
PID_FILE="/var/run/$APP_NAME.pid"
CONF_FILE="$APP_DIR/conf/$CONF"
start() {
$APP_SCRIPT -Dpidfile.path=$PID_FILE -Dconfig.file=$CONF_FILE > /dev/null &
}
stop() {
kill `cat $PID_FILE`
}
case "$1" in
start)
echo "Starting $APP_NAME"
if [ -e "$PID_FILE" ] ; then
echo "$APP_NAME already running"
echo "Try restart option or delete pid file at $PID_FILE"
else
start
echo "$APP_NAME started"
fi
;;
stop)
echo "Stopping $APP_NAME"
stop
echo "$APP_NAME stopped."
;;
restart)
echo "Restarting $APP_NAME"
stop
sleep 2
start
echo "$APP_NAME restarted."
;;
status)
if [ -e "$PID_FILE" ] ; then
echo "$APP_NAME is running (pid `cat $PID_FILE`)"
else
echo "$APP_NAME is not running"
fi
;;
*)
N="/etc/init.d/$APP_NAME"
echo "Usage: $N {start|stop|restart|status}" >&2
exit 1
;;
esac
exit 0