从debian创建的SystemD的.deb:用于Play 2.4.2 App的packageBin没有Permisison来创建日志

时间:2015-08-29 23:45:48

标签: playframework-2.0 debian sbt sbt-native-packager

sbt debian:packageBin创建的SystemD安装脚本如何设置webapp的权限以写入PID /var/run或子目录?

只有root有权在pid中创建/var/run文件或创建包含/var/run/myWebApp/文件的pid目录。 debian:packageBin任务使webapp作为从webapp名称创建的特殊user:group运行。如果创建的目录与/var/run/myWebApp类似,则myWebApp组需要写入权限,但我看不到任何方法可以自动执行此操作。我错过了什么吗?

以下是我的一些配置文件:

dist/conf/application.ini

-Dpidfile.path=/var/run/webapp2/webapp2.pid

conf/application.conf

# This seems redundant ... should it be removed?
pidfile.path = /var/run/webapp2/pid
pidfile.path = ${?pidfile.path}

debian.sbt

import com.typesafe.sbt.packager.archetypes.ServerLoader.{Systemd, SystemV, Upstart}
import com.typesafe.sbt.SbtNativePackager.autoImport._

lazy val root = (project in file(".")).enablePlugins(PlayScala, DebianPlugin)

enablePlugins(JavaAppPackaging)
enablePlugins(JDebPackaging)
enablePlugins(JavaServerAppPackaging)

serverLoading in Debian := Systemd

maintainer in Linux      := "Mike Slinn <mslinn@mslinn.com>"
packageSummary in Linux  := "myWebApp blah blah"
packageDescription       := "myWebApp blah blah"
daemonUser in Linux      := normalizedName.value        // user which will execute the application, resolves to "myWebApp"
daemonGroup in Linux     := (daemonUser in Linux).value // group which will execute the application, resolves to "myWebApp"

更新

Play manages its own pid.。我无法展开${{app_name}},因此我改为编码myWebApp

sbt-native-packager docs表示应将pid放在/var/run/myWebApp中,将日志放在/var/log/myWebApp中。

/var/run有权限777通过权限775符号链接到/run;两者都归root:root所有。因此,非root进程可以写入/var/run的唯一方法是在/var/run下使用适当的权限创建目录。例如,postgres:postgres有权写入/var/run/postgres

$ ls -adlF /var/run/postgresql
drwxrwsr-x 3 postgres postgres 120 Aug 28 01:17 /var/run/postgresql/

这就是Play文档显示如何将pid放入/var/run应该有效,但这对我不起作用。

1 个答案:

答案 0 :(得分:0)

以下是解决方案,放在debian.sbt

linuxPackageMappings += packageTemplateMapping(s"/var/run/${name.value}/")() withUser name.value withGroup name.value

conf/application.conf中无需额外的条目。