user908853
user908853

Reputation:

How to run two instances of the same Play! Framework application?

I am trying to run two instances of the same Play application in order to transparently upgrade the application in the future.

When I launch the first instance, everything goes fine obviously. When I launch the start 9525 command to launch the second instance of the application on port 9525, I get the following error:

Play server process ID is 8909
This application is already running (Or delete .../RUNNING_PID file)

Any idea how to work around this?

Upvotes: 4

Views: 2841

Answers (1)

biesior
biesior

Reputation: 55798

This Play's doc already describes using of Apache for 'transparent upgrading'. In general you need to start two instances in two separate folders

At the beginning:

  1. Create dist package inside your folder with apps sources
  2. Unzip it to some subfolder ie. instance1
  3. Start instance1 on desired port for an example 9998 it will be your every-day instance

After changes, when you want to redeploy app transpalently:

  1. Push changes to server (assuming that you are using some versioning system, ie. git)
  2. Create dist and unzip it to other folder ie. instance2
  3. Start it on the other port ie. 9999
  4. Stop application in folder instance1
  5. Copy unzipped dist from instance2 to instance1
  6. Start application in instance1 and stop application on instance2
  7. Repeat this procedure every time you need to redeploy with new changes.

Of course creating simple shell script which will perform all steps at once will be great helper for you.

TIP:

To avoid often re-deployment, especially when you need just to replace/modify some public and static contents like CSS or images, you can also use Apache common vhost for handling these resources. Just create a vhost for some folder as a subdomain ie. http://static.domain.tld or better with separate domain: http://my-cdn.tld so you can use a path like:

<img src="http://static.domain.tld/images/photo.png" alt="" />

instead of

<img src="/public/images/photo.png" alt="" />

The benefits:

  • You don't need to redeoploy the app to change these files.
  • You don't send the cookies, which are mostly redundant for public assets (if vhost's domain is other than main project)
  • You can use HTTP server's configuration for setting cache tags (performance!)
  • You are sharing statics automatically between all instances.
  • You don't waste JVM resources for serving the pictures :) I noticed that, although Play's default server can be really fast, serving static contents with simple HTTP server is probably faster...

And finally, from my experience, nginx is faster than Apache. So if only task for HTTP server in your case is load-balancing the Play's apps, consider using nginx it's just lighter.

Upvotes: 5

Related Questions