Skip to content

Commit 2bc7595

Browse files
authored
Fix regression from #14623 - use debug SVC handler only on interactive sessions (#15210) (#15211)
Backport #15210 Unfortunately #14623 changed from the deprecated IsInteractiveSession to IsWindowsService without recognising that they are the complement of each other. This means that Windows SVC control is not working correctly. This PR adds some Tracing statements but also fixes the bug. Fix #15159 Signed-off-by: Andrew Thornton <[email protected]>
1 parent 92b2883 commit 2bc7595

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

modules/graceful/manager_windows.go

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,19 @@ func (g *Manager) start() {
6868
// Set the running state
6969
g.setState(stateRunning)
7070
if skip, _ := strconv.ParseBool(os.Getenv("SKIP_MINWINSVC")); skip {
71+
log.Trace("Skipping SVC check as SKIP_MINWINSVC is set")
7172
return
7273
}
7374

7475
// Make SVC process
7576
run := svc.Run
76-
isInteractive, err := svc.IsWindowsService()
77+
isWindowsService, err := svc.IsWindowsService()
7778
if err != nil {
78-
log.Error("Unable to ascertain if running as an Interactive Session: %v", err)
79+
log.Error("Unable to ascertain if running as an Windows Service: %v", err)
7980
return
8081
}
81-
if isInteractive {
82+
if !isWindowsService {
83+
log.Trace("Not running a service ... using the debug SVC manager")
8284
run = debug.Run
8385
}
8486
go func() {
@@ -94,38 +96,49 @@ func (g *Manager) Execute(args []string, changes <-chan svc.ChangeRequest, statu
9496
status <- svc.Status{State: svc.StartPending, WaitHint: uint32(setting.StartupTimeout / time.Millisecond)}
9597
}
9698

99+
log.Trace("Awaiting server start-up")
97100
// Now need to wait for everything to start...
98101
if !g.awaitServer(setting.StartupTimeout) {
102+
log.Trace("... start-up failed ... Stopped")
99103
return false, 1
100104
}
101105

106+
log.Trace("Sending Running state to SVC")
107+
102108
// We need to implement some way of svc.AcceptParamChange/svc.ParamChange
103109
status <- svc.Status{
104110
State: svc.Running,
105111
Accepts: svc.AcceptStop | svc.AcceptShutdown | acceptHammerCode,
106112
}
107113

114+
log.Trace("Started")
115+
108116
waitTime := 30 * time.Second
109117

110118
loop:
111119
for {
112120
select {
113121
case <-g.ctx.Done():
122+
log.Trace("Shutting down")
114123
g.DoGracefulShutdown()
115124
waitTime += setting.GracefulHammerTime
116125
break loop
117126
case <-g.shutdownRequested:
127+
log.Trace("Shutting down")
118128
waitTime += setting.GracefulHammerTime
119129
break loop
120130
case change := <-changes:
121131
switch change.Cmd {
122132
case svc.Interrogate:
133+
log.Trace("SVC sent interrogate")
123134
status <- change.CurrentStatus
124135
case svc.Stop, svc.Shutdown:
136+
log.Trace("SVC requested shutdown - shutting down")
125137
g.DoGracefulShutdown()
126138
waitTime += setting.GracefulHammerTime
127139
break loop
128140
case hammerCode:
141+
log.Trace("SVC requested hammer - shutting down and hammering immediately")
129142
g.DoGracefulShutdown()
130143
g.DoImmediateHammer()
131144
break loop
@@ -134,6 +147,8 @@ loop:
134147
}
135148
}
136149
}
150+
151+
log.Trace("Sending StopPending state to SVC")
137152
status <- svc.Status{
138153
State: svc.StopPending,
139154
WaitHint: uint32(waitTime / time.Millisecond),
@@ -145,8 +160,10 @@ hammerLoop:
145160
case change := <-changes:
146161
switch change.Cmd {
147162
case svc.Interrogate:
163+
log.Trace("SVC sent interrogate")
148164
status <- change.CurrentStatus
149165
case svc.Stop, svc.Shutdown, hammerCmd:
166+
log.Trace("SVC requested hammer - hammering immediately")
150167
g.DoImmediateHammer()
151168
break hammerLoop
152169
default:
@@ -156,6 +173,8 @@ hammerLoop:
156173
break hammerLoop
157174
}
158175
}
176+
177+
log.Trace("Stopped")
159178
return false, 0
160179
}
161180

0 commit comments

Comments
 (0)