Do you need any of your third-party applications or software to run automatically when your system boots? The best way to do that is by deploying them as Windows Service.
Running your apps as Windows service ensures permanent availability unless you want to stop the service yourself. You can start or stop any Windows service through the Services console that you can access by running services.msc.
The problem is, there is no easy way within Windows OS to do that. Sure you can deploy a native Windows app as a service using New-Service.
But if you want other 3rd party applications to run as Windows service then you will need to leverage the help of a specific Tool or a Utility.
The easiest way to do that is with NSSM.
What is NSSM (Non-Sucking Service Manager)?
NSSM is basically a service helper that allows you to convert any executable file into a Windows service. The difference between NSSM and other utilities of this sort is that NSSM monitors the services. So if a particular service fails, it will detect the failure and re-start it at once.
In my opinion, the biggest advantage of using NSSM is the ease-of-use and simple deployment.
Now I am going to demonstrate on how to use it.
For the sake of this tutorial, we are going to deploy Nginx as a service. Nginx is a Web server just like apache and it’s available for Windows as well.
The problem that most Windows users face is Nginx does not register itself as a Windows service. You always have to start it manually to run your Localhost web applications.
What could be a better candidate than this one right?
How to Run Nginx as a Windows Service
Now I will show you step-by-step on how to run Nginx as a Windows service using NSSM.
Step-1: Download Nginx
The first step is of course to download Nginx for Windows. You can download it from HERE.
Once it’s downloaded, you will need to extract it to a folder. For this exercise you need to extract it and rename the folder as “nginx”. Then place the folder in the C: drive on this path:
Inside the nginx folder, you should be able to see the nginx.exe file. This is the main file that we will need later to be run as a service.
Step-2: Download NSSM
Now we need to download NSSM. You can download it from HERE.
If you are running Windows 10, be sure to download the new version as shown in the screenshot.
Once it’s downloaded, extract it to a folder. For this exercise, I have downloaded and extracted it to folder with the same name as the download.
Step-3: Running NSSM
Now it’s time to run the Non-sucking Service manager. To that that we need to open the command prompt and traverse to the path where NSSM exe file is located.
When you open the command prompt, the correct path should look like this:
Now we are ready to create the new service. Move on to the next step.
Step-4: Install Nginx service with NSSM
This is the most important step. If this goes well, we will have a new nginx service in the services manager.
On the command prompt, run this command:
nssm install nginxservice
Where nginxservice is the service name we have chosen for our new service. You can type any name you want.
As soon as you type and enter the above command, a dialog box will appear as shown in the screenshot. Here you will need to browse and add the path of the nginx.exe file in the C:/nginx/ path.
And that’s it. All you need to do now is to click the Install Service button. When it’s done you should get a success message like this one:
And your new service has been installed.
Step-5: Verify the service in Services manager
This step is just for verifying if your services has actually been deployed in the Windows services manager. To do that you need to type the following command in Run dialog box.
This should open the Windows services console. Now browse through the services and find the one that you created.
The new service won’t probably be running the first time you see it. To start the service, simply right-click on the service and click Start.
This should start your new service and if you have configured any web page in your localhost on nginx, you should be able to browse the localhost in the browser.
Pretty simple right? This small utility is quite amazing in its functionality. You can configure other options in it as well like Automatic start, Manual start, Delayed start etc.