-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added service wrapper code #6220
Conversation
258c310
to
7c27b45
Compare
7c27b45
to
460178b
Compare
@angrycub What's left to get this ready for review? Would be nice to ship service support in 10.1 |
This looks good to go based on prelim. testing. I was able to start Nomad as a service and manage it from the native Windows tooling. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉
@@ -179,6 +183,22 @@ testing. | |||
|
|||
- `log_json` `(bool: false)` - Output logs in a JSON format. | |||
|
|||
- `log_file` `(string: "")` - Specifies the path for logging. If the path |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for handling this 👍
service_os/service_windows.go
Outdated
|
||
func (serviceWindows) Execute(args []string, r <-chan wsvc.ChangeRequest, s chan<- wsvc.Status) (svcSpecificEC bool, exitCode uint32) { | ||
const accCommands = wsvc.AcceptStop | wsvc.AcceptShutdown | ||
s <- wsvc.Status{State: wsvc.StartPending} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this necessary since the next line sends Running? If Windows requires us sending it first we should comment to that effect.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the win32 API docs for this concept, it looks like the expectation is that services set SERVICE_START_PENDING
at the very beginning, and then wait to set SERVICE_STARTED
only once we're ready to receive any shutdown signals. But the way this Execute
gets invoked, the change request channel already exists by the time we're called, so we're good-to-go at that point. Compare to https://docs.microsoft.com/en-us/windows/win32/services/writing-a-servicemain-function where they have to set up the stop signal handler first.
So I don't think there's any particular reason to have this line here. Removed in aa0b3f7
(That being said, all signal handling is racy during startup, including on Linux. If we get a signal before the signal handler has been created, we die without being able to gracefully shut down. The API for Windows implies they don't send you a shutdown notice until you've indicated you're ready to receive one via SERVICE_START_PENDING
, but that's just from the service manager. Some other process could come along and SIGINT you and you'd be just as dead as under Unix.)
service_os/service_windows.go
Outdated
c := <-r | ||
switch c.Cmd { | ||
case wsvc.Interrogate: | ||
s <- c.CurrentStatus |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any clue why Go's example service does a wacky send/sleep/send instead of just sending back CurrentStatus?! https://github.com/golang/sys/blob/master/windows/svc/example/service.go#L38-L42
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the background in https://code.google.com/archive/p/winsvc/issues/4 it looks like the comment they have here "Testing deadlock" literally means "we've left testing code in here in order to see if we can trigger this deadlock." I don't think we want to keep that.
service_os/service_windows.go
Outdated
s <- c.CurrentStatus | ||
case wsvc.Stop, wsvc.Shutdown: | ||
chanGraceExit <- 1 | ||
s <- wsvc.Status{State: wsvc.StopPending} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should swap the order of these 2 lines to notify Windows we're intending to stop before signally to Nomad to stop. Either that or make the chan buffered so L35 doesn't block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. It looks like this was introduced in hashicorp/consul@319a0ae#diff-b58928334218b555d4fbe9d2b431a706 but there was a giant sleep in that commit, so I suspect the order wasn't well-defined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in f107b52
log should be written to before it needs to be rotated. Must be a duration | ||
value such as 30s. | ||
|
||
- `log_rotate_max_files` `(int: 0)` - Specifies the maximum number of older log |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've rebased this on master and I think I've addressed the open code review comments. Next I'm going to take it for a spin on the Windows e2e infra to verify it still works. |
Success!
|
@schmichael this was previously approved by @endocrimes but you had some open questions on it, so I want to make sure you're happy with my answers before we merge this. |
2e4d85f
to
e5156da
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 I'll pick those up as well as the CHANGELOG conflict. |
* guide for installing as a windows service. * configuration for logging to file from PR #6429
* fix layout on guide for sidebar * link downloads * correct md formatting for links inside of monospace * shorten title
87858d0
to
5b5f7ce
Compare
I've made those updates and rebased on master. Once the tests pass I'll squash-and-merge this. |
5b5f7ce
to
608f4da
Compare
I'm going to lock this pull request because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active contributions. |
This is the basic code to add the Windows Service Manager hooks to Nomad. There is still a need to add logging to file in order to fully support this feature.