Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
admpub committed Jan 20, 2024
1 parent 2176ff7 commit adca6f3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
13 changes: 11 additions & 2 deletions application/cmd/utils_signal.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ func stopWebServerForce(_ int, eng engine.Engine, exitCode int) {
stopWebServerWithTimeout(eng, time.Second*5, exitCode)
}

const (
ExitCodeStopFailed = 2
ExitCodeShutdownFailed = 4
ExitCodeDefaultError = 3
ExitCodeSelfRestart = 124
)

func stopWebServer(i int, eng engine.Engine, exitCode int) {
if i > 0 {
err := eng.Stop()
Expand All @@ -62,7 +69,7 @@ func stopWebServer(i int, eng engine.Engine, exitCode int) {
if exitCode > 0 {
os.Exit(exitCode)
} else {
os.Exit(2)
os.Exit(ExitCodeStopFailed)
}
}
log.Warn("SIGINT: Shutting down")
Expand All @@ -72,7 +79,7 @@ func stopWebServer(i int, eng engine.Engine, exitCode int) {
exitedCode := exitCode
if err != nil {
log.Error(err.Error())
exitedCode = 4
exitedCode = ExitCodeShutdownFailed
}
os.Exit(exitedCode)
}()
Expand All @@ -82,6 +89,8 @@ func CallSignalOperation(sig os.Signal, i int, eng engine.Engine) {
var exitCode int
if ec, ok := sig.(ExitCoder); ok {
exitCode = ec.ExitCode()
} else {
exitCode = ExitCodeDefaultError
}
if operations, ok := signalOperations[sig]; ok {
for _, operation := range operations {
Expand Down
4 changes: 2 additions & 2 deletions application/handler/manager/self_upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import (
)

func selfExit() {
cmd.SendSignal(os.Interrupt, 124)
cmd.SendSignal(os.Interrupt, cmd.ExitCodeSelfRestart)
time.Sleep(time.Second)
os.Exit(124)
os.Exit(cmd.ExitCodeSelfRestart)
}

func selfUpgrade(ctx echo.Context) error {
Expand Down
1 change: 1 addition & 0 deletions tool/startup/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,6 @@ START:
goto START
}
log.Println(`exitCode:`, state.ExitCode())
os.Exit(state.ExitCode())
}
}

0 comments on commit adca6f3

Please sign in to comment.