SoftInstigate / restheart

Rapid API Development with MongoDB
https://restheart.org
GNU Affero General Public License v3.0
805 stars 171 forks source link

Running as Windows Service #212

Closed afraniosm closed 7 years ago

afraniosm commented 7 years ago

I had to make minor modifications to install RestHeart as a service in Windows via Apache Procrun (used by Tomcat). The problem is that org.restheart.Bootstrapper.shutdown() can't be used as --StopMethod parameter for procrun as the documentation says:

Name of method to be called when service is stopped. It must be static void and have argument (String args[]). Only applies to jvm mode. In Java mode, the main method is always used.

So to use procrun you may either:

I think procrun is the easiest/fastest way to install restheart as Windows service, but it needs just a little tweak to make it go smoothly. Now it's up to you the most suitable solution to integrate.

mkjsix commented 7 years ago

Hi @afraniosm, I'd go for adding the dummy parameter to Bootstrapper because it looks like the smallest modification. In case, could you please do that and open a Pull Request? I don't use Windows, so I can't test it by myself.

mkjsix commented 7 years ago

PR merged, thank you.

afraniosm commented 7 years ago

Ok, I've compiled and tested.

I've installed the service with:

restheart.exe install --DisplayName=RestHeart --Install=C:\restheart-3.1.0-SNAPSHOT\restheart.exe --Description="RestHeart HAL API for MongoDB Service" --Jvm=auto --StartMode=jvm --StopMode=jvm --StartClass=org.restheart.Bootstrapper --StopClass=org.restheart.Bootstrapper --StartParams=etc/restheart.yml --StartMethod=main --StopMethod=shutdown --StartPath=C:\restheart-3.1.0-SNAPSHOT --LogPath=C:\restheart-3.1.0-SNAPSHOT\log --Classpath=restheart.jar

where prunsrv.exe is renamed to restheart.exe, see procrun docs .

after restheart.exe start, in C:\restheart-3.1.0-SNAPSHOT\log:

type C:\restheart-3.1.0-SNAPSHOT\log\commons-daemon.2017-05-11.log

[2017-05-11 13:25:08] [info] [ 3988] Commons Daemon procrun (1.0.15.0 64-bit) started [2017-05-11 13:25:08] [info] [ 3988] Service restheart name RestHeart [2017-05-11 13:25:09] [info] [ 3988] Service 'restheart' installed [2017-05-11 13:25:09] [info] [ 3988] Commons Daemon procrun finished [2017-05-11 13:27:50] [info] [ 1780] Commons Daemon procrun (1.0.15.0 64-bit) started [2017-05-11 13:27:50] [info] [ 1780] Running 'restheart' Service... [2017-05-11 13:27:50] [info] [ 1832] Starting service... [2017-05-11 13:28:01] [info] [ 1832] Service started in 10321 ms.

type C:\restheart-3.1.0-SNAPSHOT\log\restheart.log

13:28:01.509 [main] INFO  org.restheart.Bootstrapper - Starting RESTHeart instance default 13:28:01.512 [main] INFO  org.restheart.Bootstrapper - version 3.1.0-SNAPSHOT 13:28:01.514 [main] INFO  org.restheart.Bootstrapper - Logging to file C:\restheart-3.1.0-SNAPSHOT\log\restheart.log with level INFO 13:28:01.514 [main] INFO  org.restheart.Bootstrapper - Stop logging to console 13:28:07.595 [main] INFO  org.restheart.Bootstrapper - MongoDB connection pool initialized 13:28:07.595 [main] INFO  org.restheart.Bootstrapper - MongoDB version 3.4.4 13:28:11.808 [main] INFO  org.restheart.Bootstrapper - Token based authentication enabled with token TTL 15 minutes 13:28:11.922 [main] INFO  org.restheart.Bootstrapper - HTTP listener bound at 0.0.0.0:80 13:28:11.925 [main] INFO  org.restheart.Bootstrapper - Local cache for db and collection properties enabled with TTL 1000 msecs 13:28:11.925 [main] INFO  org.restheart.Bootstrapper - Local cache for schema stores enabled with TTL 1000 msecs 13:28:13.250 [main] INFO  org.restheart.Bootstrapper - URL / bound to MongoDB resource * 13:28:14.041 [main] INFO  org.restheart.Bootstrapper - URL /browser bound to static resources C:\restheart-3.1.0-SNAPSHOT\halbrowser. Access Manager: true 13:28:14.071 [main] INFO  org.restheart.Bootstrapper - URL /_logic/ping bound to application logic handler org.restheart.handlers.applicationlogic.PingHandler. Access manager: false 13:28:14.071 [main] INFO  org.restheart.Bootstrapper - URL /_logic/roles bound to application logic handler org.restheart.handlers.applicationlogic.GetRoleHandler. Access manager: true 13:28:14.072 [main] INFO  org.restheart.Bootstrapper - URL /_logic/ic bound to application logic handler org.restheart.handlers.applicationlogic.CacheInvalidator. Access manager: true 13:28:14.073 [main] INFO  org.restheart.Bootstrapper - URL /_logic/csv bound to application logic handler org.restheart.handlers.applicationlogic.CsvLoaderHandler. Access manager: true 13:28:15.286 [main] INFO  org.restheart.Bootstrapper - RESTHeart started

Obs: I've defined restheart.log in etc/restheart.yml