Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Play 2.0 - starting as Windows service after server restart

I have the Play! application running as a windows service. It is implemented according to this guidance.

The problem is that the RUNNING_PID at the root folder of the application is not removed when the server is restarted and the application cannot start again. I have to remove this file and start the service again manually.

Is there any option to solve it?

like image 731
Jolene Avatar asked Feb 26 '13 12:02

Jolene


People also ask

How do I start Windows Server service?

Start a service from Server Explorer Expand the Services node, and then locate the service you want to start. Right-click the name of the service, and then select Start.

How do I start a service manually?

Start serviceOpen Start. Search for Command Prompt, right-click the top result, and select the Run as administrator option. Type the following command to start a service and press Enter: net start "SERVICE-NAME" In the command, replace "SERVICE-NAME" for the name or display name of the service.

How do I start services in Windows 10?

You can launch services by opening Start, typing: services then hitting Enter. Or, you can press Windows key + R, type: services. msc then hit Enter. Services feature a very basic interface, but within it are hundreds of services, most bundled with Windows 10 and others added by third parties.


3 Answers

YAJSW

In case of YAJSW I found this answer with better understanding. It's of course pretty similar to link you gave, anyway keep in mind that it's more often advised to use dist command instead of stage as it has got better developers attention (more bugs fixed in dist). And Mikhail's answer is just clearer (vote him up!)

RUNNING_PID

In case of RUNNING_PID, there was some pull requests which suggested to add an option of disabling pidfile... anyway as I can see, none of them was accepted still...

Actually if you can't avoid creating it, you can... remove it right after application's start, preferably with Globals object's onStart() method. To stay informed what is current PID of the working instance, just rename the file to something, which won't be checked by Play at the startup - for an example RUNNING_PID_INFO. In such case after server's restart service will run your application without problems.

import play.GlobalSettings;
import java.io.File;

public class Global extends GlobalSettings {
    @Override
    public void onStart(Application application) {
        File pidFile = new File("RUNNING_PID");
        pidFile.renameTo(new File("RUNNING_PID_INFO"));
    }

    @Override
    public void onStop(Application application) {
        File pidFile = new File("RUNNING_PID_INFO");
        pidFile.delete();
    }
}

(note: changing pidfile.path in apllication.conf will NOT solve the problem, as play will use that for checking if instance is working).

like image 58
biesior Avatar answered Nov 05 '22 07:11

biesior


Since Play Framework 2.1 you can disable the PID file by setting the pidfile.path property:

Windows:

-Dpidfile.path=NUL

Unix:

-Dpidfile.path=/dev/null

Found at https://groups.google.com/forum/#!topic/play-framework/4amD9o37Ki4

like image 21
coeing Avatar answered Nov 05 '22 07:11

coeing


I recently installed a play framework app using YAJSW by following this answer. I noticed that now, RUNNING_PID is automatically deleted and you don't have to worry about modifying your code to delete the file. Also, if your service depends on other services, it is better to set DELAYED_AUTO_START as the start mode to ensure the service is properly started after server reboot.

like image 36
ami91 Avatar answered Nov 05 '22 06:11

ami91