Archive for July, 2012

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

Tuesday, July 10th, 2012

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.