Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to specify owner of created /usr/share/<project> in systemd unit #769

Closed
el-dom opened this issue Apr 7, 2016 · 3 comments
Closed

Comments

@el-dom
Copy link

el-dom commented Apr 7, 2016

Hey.

I'm currently trying to deploy a play 2.4 application using the native-packager's debian and systemd support
My stripped down build.sbt looks as follows

val generalSettings = Seq(
  ...
  serverLoading in Debian := ServerLoader.Systemd,
  daemonUser in Linux := "deploy",
  daemonGroup in Linux := "deploy"
)

lazy val shop = project.in(file("modules/shop"))
  .settings(generalSettings: _*)
  .enablePlugins(PlayScala, JavaServerAppPackaging, JDebPackaging)```

and the generated systemd unit looks like this:

[Unit]
Description=shop
Requires=network.target

[Service]
Type=simple
WorkingDirectory=/usr/share/shop
ExecStart=/usr/share/shop/bin/shop
ExecReload=/bin/kill -HUP $MAINPID
Restart=always
RestartSec=60
User=deploy
ExecStartPre=/bin/mkdir -p /run/shop
ExecStartPre=/bin/chown deploy:deploy /run/shop
ExecStartPre=/bin/chmod 755 /run/shop
PermissionsStartOnly=true

[Install]
WantedBy=multi-user.target

My problem is now, that the target server needs elevated rights for installing the generated .deb package via dpkg. Thus, the folder /user/share/shop is owned by root after installation, but the systemd service is started by deploy. As a result play won't start with java.io.FileNotFoundException: /usr/share/shop/RUNNING_PID (Permission denied)

Is there a way to tell the packager that the systemd service should chown the /usr/share/<project> folder for the user specified by the daemonUser SettingKey? Or do i need to create a custom template for doing this?

If the latter, where would I put this template? The documentation at [http://www.scala-sbt.org/sbt-native-packager/archetypes/java_server/customize.html#override-start-script](Override Start Script) says it should be put at /src/templates, but there is no such folder in a play application. Can the template location be customized?

@muuki88
Copy link
Contributor

muuki88 commented Apr 9, 2016

Hi @el-dom

Thanks for your detailed bug report. You are hitting a common issue with configuring play for production. Play, by default, has a custom pid handling, which you can disable. There is also a small section on native packager and in our documentation. The best way is to disable plays pid handling.

Important take away: /usr/share/<yourapp> is and should always be owned by root. If you need write access to the file system. The JavaServerAppPackaging archetype provides to folders

  • /var/log/<yourapp> - write log files
  • /var/run/<yourapp - you could add a pid file here

@muuki88 muuki88 closed this as completed Apr 9, 2016
@el-dom
Copy link
Author

el-dom commented Apr 9, 2016

My bad. I somehow completely missed that part of the documentation. Sorry for bothering you. Thanks a lot :)

@muuki88
Copy link
Contributor

muuki88 commented Apr 10, 2016

No problem :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants