Play 框架创建 DEB 并将其部署在 Ubuntu 14.04

Play framework create DEB and deploy it on Ubuntu 14.04

我在 Scala 中使用 Play Framework 2.3.8,我正在尝试创建 DEB 包以将其安装在产品服务器上。安装后它应该自动 运行 到 "services"

我已经添加到 build.sbt:

import com.typesafe.sbt.packager.Keys._

packageDescription := """Admin Application"""

maintainer := """Admin <contact@maintainer.com>"""

执行后

activator debian:packageBin

它生成 deb 文件,但安装后脚本 /etc/init.d/testApplication 不工作

如何让它在 Ubuntu 14.04 上运行?

我尝试在 http://www.scala-sbt.org/sbt-native-packager/archetypes/java_server/

的基础上使用 Java Application Archetype

我添加了:

import com.typesafe.sbt.SbtNativePackager._
import NativePackagerKeys._

packageArchetype.java_application

但是还是没有成功

=====更新

设置 Upstart 后,在安装过程中我得到:

Selecting previously unselected package testApplication.
(Reading database ... 61317 files and directories currently installed.)
Preparing to unpack testApplication_0.1_all.deb ...
Unpacking testApplication (0.1) ...
Setting up testApplication (0.1) ...
Creating system group: testApplication
Adding group `testApplication' (GID 115) ...
Done.
Creating user testApplication in group testApplication
start: Unknown job: testApplication
testApplication could not be started. Try manually with service testApplication start
Processing triggers for ureadahead (0.100.0-16) ...

并且运行手动执行脚本仍然没有给出任何结果

michal@cantrace:~$ sudo /etc/init.d/testApplication start
 * Starting testApplication                                  [ OK ]
michal@cantrace:~$ ps aux |grep java
michal    1807  0.0  0.0  11744   920 pts/0    S+   18:33   0:00 grep --color=auto java

DebianLike 系统中有两个基本的服务管理器。

  • Upstart 默认为 Ubuntu 14
  • SystemV 默认为 Debian 7

根据目标系统,您应该使用 UpstartSystemV

import com.typesafe.sbt.packager.archetypes.ServerLoader.YourServiceManager

packageArchetype.java_server

serverLoading in Debian := YourServiceManager

Upstart 将脚本存储在 /etc/init

SystemV 将脚本存储在 /etc/init.d

这里有关于此配置的更多信息:

http://www.scala-sbt.org/sbt-native-packager/archetypes/java_server/index.html#customize

我在 Debian 上遇到了类似的问题。 DEB 包的默认配置已损坏。默认情况下,应用程序会在启动时在 /usr/share/[your application name] 中创建一个 RUNNING_PID 文件。由于文件权限无效,这将失败。修复:

  • 安装好DEB包后,编辑/etc/default/[your applicaiton name],取消下面一行的注释,重启服务:

    -Dpidfile.path=/var/run/[your application name]/play.pid

  • 或者,将 sbt-native-packager 升级到 v1.0.0 并覆盖默认配置。

要升级,

  1. [project root]/project/plugins.sbt中添加:

addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.0.0")

  1. [project root]/build.sbt 中,删除以下导入:

//import com.typesafe.sbt.SbtNativePackager._
//import NativePackagerKeys._

  1. 创建 [project root]/dist/conf/application.ini 并指定新的默认值:

# Since play uses separate pidfile we have to provide it with a proper path
-Dpidfile.path=/var/run/[your application name]/play.pid

希望对您有所帮助。