mirror of
https://github.com/wavetermdev/backup.git
synced 2026-08-05 13:57:07 -07:00
fix shutdown loop -- have to ignore SIGHUP
This commit is contained in:
+16
-1
@@ -9,6 +9,7 @@ import (
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
"runtime/debug"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -451,8 +452,10 @@ func stdinReadWatch() {
|
||||
if err != nil {
|
||||
log.Printf("[prompt] stdin closed/error, shutting down: %v\n", err)
|
||||
sendTelemetryWrapper()
|
||||
time.Sleep(1 * time.Second)
|
||||
log.Printf("[prompt] closing db connection\n")
|
||||
sstore.CloseDB()
|
||||
log.Printf("[prompt] *** shutting down local server\n")
|
||||
time.Sleep(1 * time.Second)
|
||||
syscall.Kill(syscall.Getpid(), syscall.SIGINT)
|
||||
break
|
||||
}
|
||||
@@ -461,6 +464,17 @@ func stdinReadWatch() {
|
||||
syscall.Kill(syscall.Getpid(), syscall.SIGKILL)
|
||||
}
|
||||
|
||||
// ignore SIGHUP
|
||||
func installSignalHandlers() {
|
||||
sigCh := make(chan os.Signal, 1)
|
||||
signal.Notify(sigCh, syscall.SIGHUP)
|
||||
go func() {
|
||||
for sig := range sigCh {
|
||||
fmt.Printf("[prompt] got signal %v (ignoring)\n", sig)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
func main() {
|
||||
scbase.BuildTime = BuildTime
|
||||
|
||||
@@ -537,6 +551,7 @@ func main() {
|
||||
if err != nil {
|
||||
log.Printf("[error] updating activity: %v\n", err)
|
||||
}
|
||||
installSignalHandlers()
|
||||
go telemetryLoop()
|
||||
go stdinReadWatch()
|
||||
go runWebSocketServer()
|
||||
|
||||
@@ -117,6 +117,19 @@ func GetDB(ctx context.Context) (*sqlx.DB, error) {
|
||||
return globalDB, globalDBErr
|
||||
}
|
||||
|
||||
func CloseDB() {
|
||||
globalDBLock.Lock()
|
||||
defer globalDBLock.Unlock()
|
||||
if globalDB == nil {
|
||||
return
|
||||
}
|
||||
err := globalDB.Close()
|
||||
if err != nil {
|
||||
log.Printf("[db] error closing database: %v\n", err)
|
||||
}
|
||||
globalDB = nil
|
||||
}
|
||||
|
||||
type ClientWinSizeType struct {
|
||||
Width int `json:"width"`
|
||||
Height int `json:"height"`
|
||||
|
||||
Reference in New Issue
Block a user