etcd: Cannot run etcd as a Windows service

Repro:

  1. Extract etcd binaries to C:\etcd
  2. mkdir C:\etcd\data
  3. Grant “Full Access” (rwx) to “NT AUTHORITY\Local Service” on C:\etcd
  4. Start an elevated command prompt
  5. Install the service: sc create etcd binpath= "C:\etcd\etcd.exe --data-dir C:\etcd\data" obj= "NT AUTHORITY\Local Service
  6. Start the service: net start etcd

Expected:

ectd service starts

Actual:

  • etcd service start times out

  • Windows event log shows two errors:

    • Service Control Manger: “A timeout was reached (120000 milliseconds) while waiting for the etcd service to connect.”
    • Service Control Manger: “The etcd service failed to start due to the following error: The service did not respond to the start or control request in a timely fashion.”
  • C:\etcd\data contains the following files:

    FullName, Length C:\etcd\data\member, 1 C:\etcd\data\member\snap, 1 C:\etcd\data\member\wal, 1 C:\etcd\data\member\snap\db, 32768 C:\etcd\data\member\snap\db.lock, 0 C:\etcd\data\member\wal\0.tmp, 64000000 C:\etcd\data\member\wal\0000000000000000-0000000000000000.wal, 64000000

Workaround:

  • None

Additional information:

Running etcd.exe from the command prompt works fine. However, etcd service won’t even run as “LocalSystem” (that’s the “Do whatever you want” built-in account). I was able to reproduce the issue on multiple Win10 machines. I assume that it has something to do with the working directory (that’s at least the most likely cause from my experience if an application can be started from cmd.exe but not as a service). The default working directory for a Windows service is C:\Windows\system32 (which is locked down for good reasons).

Environment:

  • Windows 10.0.16299 Build 16299 x64
  • etcd.exe --version etcd Version: 3.3.11 Git SHA: 2cf9e51d2 Go Version: go1.10.7 Go OS/Arch: windows/amd64

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 24 (15 by maintainers)

Most upvoted comments

@haroldHT I managed to botch up the code base enough to make etcd run as a windows service. It properly interacts with Windows Service Control Manager through x/sys/windows/svc. I haven’t fully tested it yet, but as far as I can tell it works for ordinary cluster members, level 4 gateways and gRPC proxies. Log output is redirected to Windows Event Log or a file (logs are confusing indeed, I ended up redirecting every log that didn’t hide well enough 🙃). I need to clean up some stuff before I can push it to a public repo, but I will do so tomorrow so you can take a look.

cc: @hexfusion @tskarman

@hexfusion I dont mind trying out some things and learning some go in the process. I got the PR working with some minor changes and will take a look at some go services that run on windows (i.e. gnatsd, Elastic Filebeat) to see how they do it.