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

Stale PID file prevents service from starting with Upstart #377

Closed
artempyanykh opened this issue Oct 15, 2014 · 11 comments
Closed

Stale PID file prevents service from starting with Upstart #377

artempyanykh opened this issue Oct 15, 2014 · 11 comments

Comments

@artempyanykh
Copy link
Contributor

I'm trying to package my Play 2 App as a .deb package, and have certain difficulties on the way.

Don't know if doing something wrong, but the story is:

  1. I package my app with debian:packageBin task.
  2. Then I install the package with sudo dpkg -i target/the_app.deb. At this point my application starts and writes its PID to /usr/share/the_app/RUNNING_PID (assume the PID is 1415).
  3. Then I restart a server. If I look at the contents of /usr/share/the_app/RUNNING_PID it is still 1415 (dead process from step 2.) and app is not running (I expected it should autostart because of start on runlevel [2345] in init config).
  4. Next if I try sudo service the_app start I get a flapping service and a stream of
Play server process ID is 5886
This application is already running (Or delete /usr/share/odin/RUNNING_PID file).

in /var/log/upstart/the_app.log.

I'm using Play 2.3.4, Scala 2.11.1.
All the experiments were made on a clean Ubuntu 12.04.
I don't use any custom packaging configuration, except required minimum (maintainer, summary, description, daemonUser and daemonGroup).

@muuki88
Copy link
Contributor

muuki88 commented Oct 15, 2014

Take a look at the

Running the app with service will start your app with the daemonUser permissions, so it shouldn't be able to generate the PID file in the first place. However if it starts then it's not able to clean up the PID afterwards, so you have a PID still laying arround.

@artempyanykh
Copy link
Contributor Author

Well, I'm trying to get my head around this...

@muuki88 I tried the packaging procedure with vanilla Play 2.3.5 app, and as you've said I got the following error:
Exception in thread "main" java.io.FileNotFoundException: /usr/share/vanila-play/RUNNING_PID (Permission denied).

Fine. But there are two things that bothers me:

  1. Vanilla Play 2 cannot be started with the default procedure described in the docs. Is it expected behavior?
  2. App tries to write pid to the project root. Shouldn't it write it to /var/run/vanila-play/ folder in the first place? (I saw something related in the Default Mappings section of the docs).

Also, do I understand correctly, that for the application to write pid-file properly, I should create a src/templates/etc-default file with the following contents:

# Available replacements
# ------------------------------------------------
# ${{author}}           debian author
# ${{descr}}            debian package description
# ${{exec}}             startup script name
# ${{chdir}}            app directory
# ${{retries}}          retries for startup
# ${{retryTimeout}}     retry timeout
# ${{app_name}}         normalized app name
# ${{daemon_user}}      daemon user
# -------------------------------------------------

# For play applications you may set
-Dpidfile.path=/var/run/${{app_name}}/vanilla-play.pid

@kardapoltsev
Copy link
Member

Shouldn't it write it to /var/run/vanila-play/

Yes it should, but play application knows nothing about packaging. And because of this we have 2 pidfiles - one created by /etc/init script and second created by play application itself. Currently you could only specify pidfile directory explicitly in /etc/default/app_name template.

@muuki88
Copy link
Contributor

muuki88 commented Oct 15, 2014

  1. Vanilla Play 2 cannot be started with the default procedure described in the docs. Is it expected behavior?

Unfortunately yes. Running play and deploying play are currently two different beasts. I'm still not sure if the playframework should provide a default-etc which fixes this. @huntc @jroper WDYT?

  1. App tries to write pid to the project root. Shouldn't it write it to /var/run/vanila-play/ folder in the first place? (I saw something related in the Default Mappings section of the docs).

By default play uses the current path of execution to create the PID, which is okay. That's why you can specify a system prop to change this behaviour.

Also, do I understand correctly, that for the application to write pid-file properly, I should create a src/templates/etc-default file with the following contents:...

That's correct. I would recommend that as you can specify all other runtime settings there as well, e.g. memory, logging configurations and other JVM options.

@muuki88 muuki88 closed this as completed Oct 15, 2014
@artempyanykh
Copy link
Contributor Author

I'm still not sure if the playframework should provide a default-etc which fixes this.

A small remark in the docs definitely won't hurt!

@ludwigm
Copy link

ludwigm commented Dec 3, 2015

I also had this problem now and it took my a long time to figure out. I think this could be documented a little better on original Play frameworks documentations page.

@francisdb
Copy link
Contributor

Do I understand this correctly that if the JVM dies (oom, ...) the PID file sticks around, on restart play finds it but has no way to check if the process is still alive so it bails out.

@dandeezy
Copy link

dandeezy commented Oct 5, 2016

I'm running into this issue and did not understand exactly how to fix it. I do not have a src folder but an app folder. In play 2.5, should I add a src/templates/etc-default for this purpose only?

@muuki88
Copy link
Contributor

muuki88 commented Oct 6, 2016

The best solution is to let play not handle the pid file. Simply add this to your start configuration

-Dpidfile.path=/dev/null

e.g. in yourr build.sbt

javaOptions in Universal += "--Dpidfile.path=/dev/null"

or in your application.conf

pidfile.path = "/dev/null"

@mcwiise
Copy link

mcwiise commented May 1, 2017

Hi @ALL:

I am trying to run my play application as standalone (as explained here https://www.playframework.com/documentation/2.5.x/Deploying). I've already created a binary distribution using sbt assembly plugin, but every time i try to start the app, I got the following error and I do not know what is happening

com.typesafe.config.ConfigException$Missing: No configuration setting found for key 'play.application' at com.typesafe.config.impl.SimpleConfig.findKeyOrNull(SimpleConfig.java:152) at com.typesafe.config.impl.SimpleConfig.findKey(SimpleConfig.java:145) at com.typesafe.config.impl.SimpleConfig.findOrNull(SimpleConfig.java:172) at com.typesafe.config.impl.SimpleConfig.findOrNull(SimpleConfig.java:176) at com.typesafe.config.impl.SimpleConfig.findOrNull(SimpleConfig.java:193) at com.typesafe.config.impl.SimpleConfig.findOrNull(SimpleConfig.java:198) at com.typesafe.config.impl.SimpleConfig.getIsNull(SimpleConfig.java:208) at play.api.ConfigLoader$$anon$4.load(Configuration.scala:1078) at play.api.ConfigLoader$$anon$4.load(Configuration.scala:1076) at play.api.PlayConfig.get(Configuration.scala:918) at play.utils.Reflect$.configuredClass(Reflect.scala:112) at play.api.ApplicationLoader$.apply(ApplicationLoader.scala:56) at play.core.server.ProdServerStart$.start(ProdServerStart.scala:46) at play.core.server.ProdServerStart$.main(ProdServerStart.scala:22) at play.core.server.ProdServerStart.main(ProdServerStart.scala)
It seems, the key 'play.application' key has not been configured in the application.conf file, but I haven't found any document explaining how to configure this key. If someone here has run into the same issue, I appreciate any advice. Currently I am using play framework 2.5

thanks

@muuki88
Copy link
Contributor

muuki88 commented May 1, 2017

Hi,

Thanks for your question. This is unfortunately the wrong place as you have an issue with sbt-assembly, play and typesafe config, not with sbt-native-packager. Also this issue here is unrelated.

Use Stackoverflow for this kind of question. Issues are for bug reports and feature requests.

Also include your build configuration and how you start your application, so people can help you.

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

7 participants