我正在尝试将 Java 应用程序部署到 VPS 上。我正在使用带有“应用程序”插件的 Gradle 构建系统。我希望应用程序随服务器一起启动。
在部署过程中,我运行 ./gradlew install
来准备运行脚本。直接运行时,它们可以正常工作。
我用了http://www.whiteboardcoder.com/2014/02/ubuntu-upstart-job-with-java-jar.html作为 Upstart 配置的基础:
description "the test server"
start on runlevel [2345]
stop on runlevel [!2345]
expect fork
script
cd /opt/testserver/
exec ./build/install/testserver/bin/testserver
end script
但是 upstart 在运行 start testserver
后报告的 PID 与使用 ps
发现的不同。我的猜测是,原因是生成脚本的最后一行:
exec "$JAVACMD""${JVM_OPTS[@]}"-classpath "$CLASSPATH"mypackage.TestServer"$@"
因此,Upstart 无法停止该应用程序。有没有办法让 upstart 看到正确的 PID?
最佳答案
看起来这里没有 fork ,所以您应该尝试删除 expect fork
位。
关于java - 如何使用 upstart 正确启动 gradle 生成的脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26475176/