Skip to content

Instantly share code, notes, and snippets.

@scottoffen
Last active March 4, 2016 08:12
Show Gist options
  • Save scottoffen/edf11e77cd58258a84dc to your computer and use it in GitHub Desktop.
Save scottoffen/edf11e77cd58258a84dc to your computer and use it in GitHub Desktop.
MongoDB Windows Service Setup
@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]
Copy link

ghost commented Mar 4, 2016

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment