Running influxdb as a service on windows

I know the windows version of influxdb doesn’t provide an installer or anything, and I know there are some 3rd parties out there that make programs that I can use to create a windows service, out of any executable.
I wonder, if there is one that influxData recommends, or uses internally when testing on windows (if they test on windows)?
We install influx as part of our application, as a storage engine, and our installer does the influx install for linux, but we currently don’t support windows using influx, but would like to. If you have any suggestions on how to get influx to startup as a service on windows, that would be appreciated.
Thanks.

1 Like

No thoughts on this?

You can create it and save it as bat file with the following command

influxd.exe -config influxdb.conf

save it as example: startInflux.bat
and set it up in you windows startup

A startup script is far from a Windows Service. Would be nice to have a common or suggested way to provide telegraf as a Windows service.

You shoul use NSSM, Non-Sucking Service Manager, a opensource tool ,
which support send ctrl+c to exit the console program.

1 Like

As @Raidsan said, NSSM is an easy option. I just built an installation script that deploys InfluxDB, Kapacitor, and Grafana on a Windows server, and I use NSSM to install all three as Windows Services. I will post the full script later when I finish everything.

Here is the gist (some details are removed because you can probably guess what they do)

$runtimeFiles =
@{
 "influxdb" = [PSCustomObject] @{name="InfluxDB run-time files"; id="InfluxDB"; daemonExe="influxd.exe"; ...};
"kapacitor" = [PSCustomObject] @{name="Kapacitor run-time files"; id="Kapacitor"; daemonExe="kapacitord.exe"; ...};
  "grafana" = [PSCustomObject] @{name="Grafana run-time files"; id="Grafana"; daemonExe="grafana-server.exe"; ...};
}

foreach ($key in $($runtimeFiles.keys)) {
    $id = $runtimeFiles[$key].id
    if (!(IsServiceInstalled $key)) {

        # GetCmdLine returns something like "c:\influxdb\influxd.exe -config `"c:\influxdb\custom.conf`""
        $cmdLine = GetCmdLine $key
        $Arguments =  @()
        $Arguments += "install"
        $Arguments += $key
        $Arguments += $cmdLine

        Write-Host "... Trying to install service `"$key`" with: $nssmExe $Arguments ..."
        Start-Process "$nssmExe" -ArgumentList $Arguments -Wait -PassThru -NoNewWindow | Out-Null
        if (IsServiceInstalled $key) {
            Write-Host "Success: installed service: $key"
        } else {
            Write-Host "FAILED: did not install service: $key"
            ExitWithCode $errorCode
        }
    }

    $description = "Provides $id windows service"
    $display = "$id"
    Write-Host "... Trying to configure service `"$key`" ..."
    Start-Process "$nssmExe" -ArgumentList "set $key AppExit Default Restart" -Wait -PassThru -NoNewWindow | Out-Null
    Start-Process "$nssmExe" -ArgumentList "set $key AppNoConsole 1" -Wait -PassThru -NoNewWindow | Out-Null
    Start-Process "$nssmExe" -ArgumentList "set $key AppRestartDelay 60000" -Wait -PassThru -NoNewWindow | Out-Null
    Start-Process "$nssmExe" -ArgumentList "set $key ObjectName LocalSystem" -Wait -PassThru -NoNewWindow | Out-Null
    Start-Process "$nssmExe" -ArgumentList "set $key Start SERVICE_AUTO_START" -Wait -PassThru -NoNewWindow | Out-Null
    Start-Process "$nssmExe" -ArgumentList "set $key Type SERVICE_WIN32_OWN_PROCESS" -Wait -PassThru -NoNewWindow | Out-Null
    Start-Process "$nssmExe" -ArgumentList "set $key DisplayName `"$display`"" -Wait -PassThru -NoNewWindow | Out-Null
    Start-Process "$nssmExe" -ArgumentList "set $key Description `"$description`"" -Wait -PassThru -NoNewWindow | Out-Null
}

Look at gthub under influxdata/influxdb. (https://github.com/influxdata/influxdb/issues/9922)
Issue #9922 has a suggestion on how to install InfluxDB as a service.

1 Like

NSSM is being flagged as vulnerable by security scanning tools. Are there any other options to run Influxdb as windows service?