Play 2.0 - starting as Windows service after server restart

后端 未结 3 911
攒了一身酷
攒了一身酷 2021-02-04 19:04

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 fo

3条回答
  •  無奈伤痛
    2021-02-04 19:48

    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).

提交回复
热议问题