Code‎ > ‎

Run Wave as a Windows Service

Running WIAB as a Windows Service.

Introduction

Running WIAB as a Windows Service allows Wave to run in the background when the host machine is started. This negates the need for you to log in and run the batch file from the command line. To accomplish this you must register Wave with the Windows Service Manager. The Windows Service Manager does not have native support for running batch (.bat) files, therefore you must use an external program to execute Wave through the Service Manager. The two most prevalent options are the Windows Resource Kit and NSSM (the Non-Sucking Service Manager). These instructions focus on the NSSM installation.

NSSM vs Windows Resource Kit

NSSM Windows Resource Kit
Support for 64-bit Platforms Yes No (src: http://www.microsoft.com/downloads/en/details.aspx?FamilyID=9d467a69-57ff-4ae7-96ee-b18c4790cffd&displaylang=en)
Failure of Application Supports 4 modes. Restart Wave upon failure, Ignore failure (appears failed program is still running in Service Manager), Exit (Service Manager shows program as stopped), Suicide (simulates a crash so custom recovery action can occur. Must be used for Windows Versions prior to Vista). Supports ignore only. Appears failed program is still running, no custom recovery action may occur, and the only way to know if service is running is to test that WIAB is running.
System Events Startup, Failure, and other system events (along with exit codes) logged to Windows Event Log. No monitoring of system events.
Windows Registry Registry used to edit default failure action (default is restart) and to add service dependencies (e.g. - start mongodb first). Registry used to configure all aspects of service creation. Note: once service is created, certain actions can be performed in Windows Service Manager.
Service Shutdown Stopping the WaveInABox service from the Windows Service Manager does NOT stop the underlying program (will be seen as java.exe in Windows Task Manager). This is behavior is consistent across both NSSM and the Windows Resource Kit. The issue is the program that runs the Wave batch file (run-nofed-config.bat) does not have knowledge of the programs started by the batch file and therefore does not have a handle to stop the java.exe Wave program.

To stop Wave you must open the Windows Task Manager and stop the java.exe program. Note: If you have multiple java programs running, you will see multiple java.exe programs executing. There is no fool proof method to determine which java.exe program corresponds to Wave (please advise if you know of a method).

Service Installation (NSSM)

Download and extract NSSM-<version>.zip from http://iain.cx/src/nssm/ into a path on local machine (note: advise to use path without spaces)

Open a Command Prompt at the directory NSSM is installed (if not placed on system path) and run:
  • nssm install WaveInABox (note: you can substiture WaveInABox for the service name of your choice)
After executing this command a Graphical UI will appear. On the UI edit the Application field to
  • c:\<path-to>\run-nofed-config.bat

Edit Default Behavior on AppExit

The default behavior of NSSM is to restart WaveInaBox if it errors out or is killed. To set it to gracefully exit:
  • open regedit (start > run > type regedit or open command prompt and type regedit)
  • navigate to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\WaveInABox <or your chosen service name>\Parameters\AppExit
  • Edit (Default) key to equal Exit or Ignore or Suicide or Restart (Restart is default)

Create A Dependency for service

You must edit the registry to set up a dependency for the WaveInABox service. This is useful, for example, to ensure your XMPP server (e.g. - OpenFire) or persistent store (e.g. - mongodb) is started before WaveInABox is started. Also, any attempt to kill the XMPP server or mongodb will alert that WaveInABox will also be affected. To create a dependency:
  • open regedit (start > run > type regedit or open command prompt and type regedit)
  • navigate to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\WaveInABox <or your chosen service name>
  • Right click on this folder (WaveInABox) and select New > Multi-String Value
  • Edit the value name to DependOnService and then click OK.
  • Double-Click the DependOnService key to open the Data dialog box. Type the name or names of the services that you prefer to start before the wave service. You must input one entry for each line, and then click OK. For example:
    MongoDB
    OpenFire

    Note: The name of the service you would enter in the Data dialog box is the exact name of the service as it appears in the Windows Service Manager (start > run > type services.msc or open command prompt then type services.msc).

Verify Service Installed

The final step is to verify the service was installed correctly and to start up your wave in a box service.
  • Go to services.msc (start > run > type services.msc or open command prompt then type services.msc). You should see your new wave service WaveInABox.
  • start WaveInABox by selecting service and clicking Start in left pane. You may also set other options at this point by right-clicking on the serice and selecting properties.
Comments