1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2024-11-28 09:21:13 -05:00

Fix regression from #14623 - use debug SVC handler only on interactive sessions (#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 <art27@cantab.net>

Co-authored-by: techknowlogick <techknowlogick@gitea.io>
This commit is contained in:
zeripath 2021-03-31 20:48:48 +01:00 committed by GitHub
parent 79ac7468dc
commit 113c1557ff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -68,17 +68,19 @@ func (g *Manager) start() {
// Set the running state // Set the running state
g.setState(stateRunning) g.setState(stateRunning)
if skip, _ := strconv.ParseBool(os.Getenv("SKIP_MINWINSVC")); skip { if skip, _ := strconv.ParseBool(os.Getenv("SKIP_MINWINSVC")); skip {
log.Trace("Skipping SVC check as SKIP_MINWINSVC is set")
return return
} }
// Make SVC process // Make SVC process
run := svc.Run run := svc.Run
isInteractive, err := svc.IsWindowsService() isWindowsService, err := svc.IsWindowsService()
if err != nil { if err != nil {
log.Error("Unable to ascertain if running as an Interactive Session: %v", err) log.Error("Unable to ascertain if running as an Windows Service: %v", err)
return return
} }
if isInteractive { if !isWindowsService {
log.Trace("Not running a service ... using the debug SVC manager")
run = debug.Run run = debug.Run
} }
go func() { go func() {
@ -94,38 +96,49 @@ func (g *Manager) Execute(args []string, changes <-chan svc.ChangeRequest, statu
status <- svc.Status{State: svc.StartPending, WaitHint: uint32(setting.StartupTimeout / time.Millisecond)} status <- svc.Status{State: svc.StartPending, WaitHint: uint32(setting.StartupTimeout / time.Millisecond)}
} }
log.Trace("Awaiting server start-up")
// Now need to wait for everything to start... // Now need to wait for everything to start...
if !g.awaitServer(setting.StartupTimeout) { if !g.awaitServer(setting.StartupTimeout) {
log.Trace("... start-up failed ... Stopped")
return false, 1 return false, 1
} }
log.Trace("Sending Running state to SVC")
// We need to implement some way of svc.AcceptParamChange/svc.ParamChange // We need to implement some way of svc.AcceptParamChange/svc.ParamChange
status <- svc.Status{ status <- svc.Status{
State: svc.Running, State: svc.Running,
Accepts: svc.AcceptStop | svc.AcceptShutdown | acceptHammerCode, Accepts: svc.AcceptStop | svc.AcceptShutdown | acceptHammerCode,
} }
log.Trace("Started")
waitTime := 30 * time.Second waitTime := 30 * time.Second
loop: loop:
for { for {
select { select {
case <-g.ctx.Done(): case <-g.ctx.Done():
log.Trace("Shutting down")
g.DoGracefulShutdown() g.DoGracefulShutdown()
waitTime += setting.GracefulHammerTime waitTime += setting.GracefulHammerTime
break loop break loop
case <-g.shutdownRequested: case <-g.shutdownRequested:
log.Trace("Shutting down")
waitTime += setting.GracefulHammerTime waitTime += setting.GracefulHammerTime
break loop break loop
case change := <-changes: case change := <-changes:
switch change.Cmd { switch change.Cmd {
case svc.Interrogate: case svc.Interrogate:
log.Trace("SVC sent interrogate")
status <- change.CurrentStatus status <- change.CurrentStatus
case svc.Stop, svc.Shutdown: case svc.Stop, svc.Shutdown:
log.Trace("SVC requested shutdown - shutting down")
g.DoGracefulShutdown() g.DoGracefulShutdown()
waitTime += setting.GracefulHammerTime waitTime += setting.GracefulHammerTime
break loop break loop
case hammerCode: case hammerCode:
log.Trace("SVC requested hammer - shutting down and hammering immediately")
g.DoGracefulShutdown() g.DoGracefulShutdown()
g.DoImmediateHammer() g.DoImmediateHammer()
break loop break loop
@ -134,6 +147,8 @@ loop:
} }
} }
} }
log.Trace("Sending StopPending state to SVC")
status <- svc.Status{ status <- svc.Status{
State: svc.StopPending, State: svc.StopPending,
WaitHint: uint32(waitTime / time.Millisecond), WaitHint: uint32(waitTime / time.Millisecond),
@ -145,8 +160,10 @@ hammerLoop:
case change := <-changes: case change := <-changes:
switch change.Cmd { switch change.Cmd {
case svc.Interrogate: case svc.Interrogate:
log.Trace("SVC sent interrogate")
status <- change.CurrentStatus status <- change.CurrentStatus
case svc.Stop, svc.Shutdown, hammerCmd: case svc.Stop, svc.Shutdown, hammerCmd:
log.Trace("SVC requested hammer - hammering immediately")
g.DoImmediateHammer() g.DoImmediateHammer()
break hammerLoop break hammerLoop
default: default:
@ -156,6 +173,8 @@ hammerLoop:
break hammerLoop break hammerLoop
} }
} }
log.Trace("Stopped")
return false, 0 return false, 0
} }