Search code examples
scalaubuntuplayframeworksbtsbt-native-packager

Play Framework Ubuntu Rogue Process


I've packaged my Play application using the sbt-native-packager Debian Plugin. I installed the .deb file using the typical sudo dpkg -i tyrion_1.0-SNAPSHOT_all.deb. Once I did that, it created the daemon user and group and started the process as per the following:

aczerwon@vps57610:~/work/tyrion/target$ sudo dpkg -i tyrion_1.0-SNAPSHOT_all.deb 
Selecting previously unselected package tyrion.
(Reading database ... 53135 files and directories currently installed.)
Preparing to unpack tyrion_1.0-SNAPSHOT_all.deb ...
Unpacking tyrion (1.0-SNAPSHOT) ...
Setting up tyrion (1.0-SNAPSHOT) ...
Creating system group: tyrion
Creating system user: tyrion in tyrion with tyrion user-daemon and shell /bin/false
tyrion start/running, process 30525
Processing triggers for ureadahead (0.100.0-16) ...

I see a java process running at 50% - which is nuts because the app should be idle. I'm assuming it's using the application.conf configuration but I get a ERR_CONNECTION_REFUSED when I try to hit the website.

Process is Starting and Stopping

Watching top, I now see the CPU is pinned because the process is starting and dying over and over. The pid is changing and VisualVM can't see it - it's not listed.


Solution

  • A ERR_CONNECTION_REFUSED error is probably due to miss configuration of play. See sbt-native-packager docs and play pid configuration.

    Example configuration

    javaOptions in Universal ++= Seq(
      // Since play uses separate pidfile we have to provide it with a proper path
      s"-Dpidfile.path=/var/run/${packageName.value}/play.pid",
    
      // setting the http port explicitly
      "-Dhttp.port=9000"
    )
    

    For the high CPU utilization I would recommend profiling the app with VisualVM or MissionControl to see what's going on.

    Update

    For play applications the PID file must be named play.pid otherwise play doesn't start up.