How to start Play! Framework 2.0 application as a Windows service

Run a Play framework application as a Windows Service with YAJSW kindly explains how to run a Play! 1.x applications as a Windows Service, but unfortunately it does not work for Play! 2.0 application. I could not find the good solution for Play! 2.0 applications on the internet, so I note my solution. Hope it would be someone’s help.

  1. Build your application for deploy.
  2. Deploy your application by using the stage task.

    $ play clean compile stage
    
  3. Download Yet Another Java Service Wrapper (YAJSW).
  4. Unzip YAJSW to %app% (where %app% is the path to your application) and rename the directory to wrapper.
  5. Create 2 directories: %app%\log (for log files) and %app%\temp (for temporary files).
  6. Edit %app%\wrapper\conf\wrapper.conf.

    Example (please change PATH_TO_YOUR_APP to %app%):

    # Example YAJSW configuration to run Play! application as service
    wrapper.working.dir=PATH_TO_YOUR_APP
    wrapper.java.app.mainclass = play.core.server.NettyServer
    wrapper.java.classpath.1 = ${wrapper.working.dir}/conf/*
    wrapper.java.classpath.2 = ${wrapper.working.dir}/target/staged/*
    wrapper.java.additional.1 = -Djava.io.tmpdir=temp
    wrapper.logfile=${wrapper.working.dir}/logs/wrapper.log
    wrapper.console.title = Play! service test
    wrapper.ntservice.name = Play! service test
    wrapper.ntservice.displayname = Play! service test
    wrapper.ntservice.description = Running a Play! app as windows service
    
  7. Execute %app%\wrapper\bat\runConsole.bat and confirm your application starts.
  8. Install the service. Execute %app%\wrapper\bat\installService.bat. The new Play! service test service should be created.
  9. Start the service via Service in Computer Management.

コメント

  1. Maurice Betzel より:

    There is a good possibility to run the PLAY! framework as windows service with JNA. I deployed several java implementations in this way on windows server 2008 SP2 successfully being monitored by PRTG (which has not intervened in a period of 6 months until now). If we decide to use PLAY! in our web stack i will write an article about it and publish it here.

  2. Thomas Themel より:

    Thanks, that was exceedingly helpful! I was already gearing up for a long struggle getting my application to run as a service with Apache procrun, but YAJSW is a joy to use, and with your example it was a breeze to get going.

  3. laguiz より:

    Help me to get a windows service that can be started/stopped and even restarted successfully. Thanks!

  4. Adrian より:

    Thank you. This is really great information and easy to follow.

  5. Zeljko Trogrlic より:

    application.conf fails to load because setting cp to wrapper.java.classpath.2 = ${wrapper.working.dir}/target/staged/*
    tries to load it from jars inside conf directory, but conf directory contains conf files themselves.

    Setting wrapper.java.classpath.2 = ${wrapper.working.dir}/target/staged solves the problem.

  6. Madwyn より:

    Thank you for the posting, this really helped a lot. I finally managed to get the service started, it took me a whole day though, wish I had seen this earlier.

%d人のブロガーが「いいね」をつけました。