Last active
March 4, 2016 08:12
-
-
Save scottoffen/edf11e77cd58258a84dc to your computer and use it in GitHub Desktop.
MongoDB Windows Service Setup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
if %1.==. goto UseDefaults | |
set srvname=%1 | |
if %2.==. goto UseDefaultApp | |
set app=%2 | |
if %3.==. goto UseDefaultConfig | |
set config=%3 | |
goto Configured | |
:TakeDefaults | |
set srvname=MongoDB | |
set app=C:\mongodb\bin\mongod.exe | |
set config=C:\mongodb\mongod.cfg | |
goto Configured | |
:UseDefaultApp | |
set app=C:\mongodb\bin\mongod.exe | |
set config=C:\mongodb\mongod.cfg | |
goto Configured | |
:UseDefaultConfig | |
set config=C:\mongodb\mongod.cfg | |
goto Configured | |
:Configured | |
set binPath="\"%app%\" --service --config=\"%config%\"" | |
sc create %srvname% binPath= %binPath% | |
sc config %srvname% DisplayName= "%srvname%" | |
sc config %srvname% start= "auto" | |
:: usage | |
:: mongodb-service.bat [service name] [path to mongod.exe] [path to config file] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Correcting above
:Configured
set binPath= ""%app%" --service --config= "%config%""
sc create %srvname% binPath= %binPath%
sc config %srvname% DisplayName= "%srvname%"
sc config %srvname% start= "auto"
each “option name includes the equal sign”, but it also includes the space after the equal sign.