Create Windows Service By Using NSSM for Multiple Versions of Applications.
In this case, I will give example Apache Tomcat.
1. Open CMD (run as Administrator)
2. For the first installation service :
$ nssm install Apache-Tomcat-p8001-v7.0.109
or you want to edit service :
$ nssm edit Apache-Tomcat-p8001-v7.0.109
3. Go to tab "Environment" :
JAVA_HOME="C:\Program Files\Java\jdk1.7.0_80"
JRE_HOME="C:\Program Files\Java\jdk1.7.0_80\jre"
4. Go to tab "Application" :
Path: C:\Windows\System32\cmd.exe
Startup directory: C:\Users\dell\programs\apache\tomcat-p8001-v7.0.109\bin
Arguments: /c catalina.bat run
5. Set the description :
$ nssm set Apache-Tomcat-p8001-v7.0.109 Description "Apache Tomcat v7.0.109 with port 8001, using JDK v7 x64."
6. Set app directory :
$ nssm set Apache-Tomcat-p8001-v7.0.109 AppDirectory C:\Users\dell\programs\apache\tomcat-p8001-v7.0.109\bin
7. If you want to run service manually, set and execute this :
$ nssm set Apache-Tomcat-p8001-v7.0.109 Start SERVICE_DEMAND_START
or you can go to tab "Details", and then choose "Startup Type" to Manual.
There menu are: Automatic, Automatic (Delayed Start), Manual, Disabled
8. Set the LogOn user (CRITICAL: ssh needs access to C:\Users\dell\.ssh)
$ nssm set Apache-Tomcat-p8001-v7.0.109 ObjectName ".\dell" "YOUR_WINDOWS_PASSWORD"
9. Set logs :
$ nssm set Apache-Tomcat-p8001-v7.0.109 AppStdout C:\Users\dell\programs\apache\tomcat-p8001-v7.0.109\logs\apache-tomcat-p8001-v7.0.109.log
$ nssm set Apache-Tomcat-p8001-v7.0.109 AppStderr C:\Users\dell\programs\apache\tomcat-p8001-v7.0.109\logs\apache-tomcat-p8001-v7.0.109.log
10. Start the service
$ net start Apache-Tomcat-p8001-v7.0.109
11. Stop the service
$ net stop Apache-Tomcat-p8001-v7.0.109
How do I get NSSM for Windows?
https://nssm.cc/builds
https://github.com/imvickykumar999/Non-Sucking-Service-Manager/releases
https://www.reko.ee/download/nssm/
So, What is NSSM?
NSSM stand for the Non-Sucking Service Manager.
nssm is a service helper which doesn't suck. srvany and other service helper programs suck because they don't handle failure of the application running as a service. If you use such a program you may see a service listed as started when in fact the application has died. nssm monitors the running service and will restart it if it dies. With nssm you know that if a service says it's running, it really is. Alternatively, if your application is well-behaved you can configure nssm to absolve all responsibility for restarting it and let Windows take care of recovery actions.
nssm logs its progress to the system Event Log so you can get some idea of why an application isn't behaving as it should.
nssm also features a graphical service installation and removal facility. Prior to version 2.19 it did suck. Now it's quite a bit better.

Comments
Post a Comment