18

I have a Play Framework 2.0 application that I want to deploy (production) on Windows Server 2008 R2. How do I get it to run as a service?

Peter Moberg
  • 3,088
  • 4
  • 27
  • 34

5 Answers5

44

This worked for me on Windows 7:

  1. Create folder C:\my_app
  2. Go to your Play! app folder in command line and type

    play dist

  3. Copy generated "something-SNAPSHOT" folder to C:\my_app
  4. Download YAJSW and extract to C:\my_app
  5. In C:\my_app\something-SNAPSHOT\ make a new file start.bat and fill it with command like this:

    java -cp "C:\my_app\something-SNAPSHOT\lib\*" play.core.server.NettyServer

  6. Save it and launch start.bat. Your play app must start and work as usual. Take a look at server's PID. You will use it in the next step.

  7. Now using command prompt go to C:\my_app\yajsw\bat and type

    genConfig.bat < PID from previous step >

  8. You generated C:\my_app\yajsw\conf\wrapper.conf. Edit this file and change these params like so:

    wrapper.ntservice.name=My App Name
    wrapper.ntservice.displayname=My App Name


    Save file.

  9. Terminate the start.bat script you started in 6. then, in C:\my_app\yajsw\bat launch

    runConsole.bat

    If app starts, do a Ctrl c (and answer y) to terminate the batch file and proceed to next step.

  10. To install service launch (Run as administrator)

    installService.bat

  11. To start service launch

    startService.bat

Now you can see your "My App Name" service in Windows services. To stop service you can use stopService.bat. To uninstall it uninstallService.bat.

Michael Szczepaniak
  • 1,600
  • 19
  • 32
Mikhail
  • 556
  • 5
  • 8
  • 6
    Clear info, like it, additionally I suggest to rename `RUNNING_PID` file to something else to prevent startup problems after sudden server restart, ([here's more informations in other answer](http://stackoverflow.com/a/15105099/1066240)) – biesior Feb 27 '13 at 05:59
3

You should take a look at this question: Run Java application as a service

You'll have to use the play dist command and then adapt the start script in order to run on Windows.

Community
  • 1
  • 1
ndeverge
  • 20,808
  • 4
  • 54
  • 84
1

If you get an error in step 5. that looks something like this:

Play server process ID is 1132

[info] play - database [default] connected at jdbc:h2:file:db/h2/play

[warn] play - Your production database [default] needs evolutions!

... bunch of SQL statements in the console ...

[warn] play - Run with -DapplyEvolutions.default=true if you want to run them automatically (be careful)

Oops, cannot start the server.

@6gme0o9k5: Database 'default' needs evolution!

Then run the command like this instead:

java -cp "C:\my_app\something-SNAPSHOT\lib\*" -DapplyEvolutions.default=true play.core.server.NettyServer

Two additional items in the process Mikhail described tripped me up:

First, before step 9., make sure you terminate the start.bat script you started in step 6.. Not doing this caused the grief I posted here:

How do I fix server Oops error when deploying Play Framework 2.0 application as a Windows service?

Lastly, make sure you Run as administrator when you open your DOS command window. I could not run the installService.bat script without being administrator when I was doing my deployment.

Community
  • 1
  • 1
Michael Szczepaniak
  • 1,600
  • 19
  • 32
0

We had difficulty with the start.bat methods listed in other answers here. Two major issues are the lack of bootstrapping when the server decides to reboot itself on Patch Tuesday, and the requirement to use VBS and other decoration to prevent needing to keep the command window open to keep the JVM alive.

We have had success with using the Commons Daemon to run Play applications on Windows in production.

We use dist to package the application for distribution, then install as a Windows service using the Commons Daemon.

kpollard
  • 71
  • 6
0

Fore newer play versions you can use sbt-native-packager that prepare installer and service almost automatically

http://www.scala-sbt.org/sbt-native-packager/formats/windows.html

mgosk
  • 1,768
  • 13
  • 22