mirror of
https://github.com/1f349/violet.git
synced 2024-11-21 19:01:39 +00:00
Replace exit and reload logic with my new library
This commit is contained in:
parent
1ca5a6205b
commit
b84df84d51
@ -5,7 +5,6 @@ import (
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
"github.com/1f349/violet/certs"
|
||||
"github.com/1f349/violet/domains"
|
||||
errorPages "github.com/1f349/violet/error-pages"
|
||||
@ -16,16 +15,14 @@ import (
|
||||
"github.com/1f349/violet/servers/api"
|
||||
"github.com/1f349/violet/servers/conf"
|
||||
"github.com/1f349/violet/utils"
|
||||
"github.com/MrMelon54/exit-reload"
|
||||
"github.com/MrMelon54/mjwt"
|
||||
"github.com/google/subcommands"
|
||||
"io/fs"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
"path/filepath"
|
||||
"syscall"
|
||||
"time"
|
||||
)
|
||||
|
||||
type serveCmd struct{ configPath string }
|
||||
@ -157,27 +154,18 @@ func normalLoad(startUp startUpConfig, wd string) {
|
||||
go utils.RunBackgroundHttps("HTTPS", srvHttps)
|
||||
}
|
||||
|
||||
// Wait for exit signal
|
||||
sc := make(chan os.Signal, 1)
|
||||
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt, os.Kill)
|
||||
<-sc
|
||||
fmt.Println()
|
||||
|
||||
// Stop servers
|
||||
log.Printf("[Violet] Stopping...")
|
||||
n := time.Now()
|
||||
|
||||
// close http servers
|
||||
if srvApi != nil {
|
||||
srvApi.Close()
|
||||
}
|
||||
if srvHttp != nil {
|
||||
srvHttp.Close()
|
||||
}
|
||||
if srvHttps != nil {
|
||||
srvHttps.Close()
|
||||
}
|
||||
|
||||
log.Printf("[Violet] Took '%s' to shutdown\n", time.Now().Sub(n))
|
||||
log.Println("[Violet] Goodbye")
|
||||
exit_reload.ExitReload("Violet", func() {
|
||||
allCompilables.Compile()
|
||||
}, func() {
|
||||
// close http servers
|
||||
if srvApi != nil {
|
||||
srvApi.Close()
|
||||
}
|
||||
if srvHttp != nil {
|
||||
srvHttp.Close()
|
||||
}
|
||||
if srvHttps != nil {
|
||||
srvHttps.Close()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
1
go.mod
1
go.mod
@ -5,6 +5,7 @@ go 1.20
|
||||
require (
|
||||
github.com/AlecAivazis/survey/v2 v2.3.7
|
||||
github.com/MrMelon54/certgen v0.0.1
|
||||
github.com/MrMelon54/exit-reload v0.0.1
|
||||
github.com/MrMelon54/mjwt v0.1.1
|
||||
github.com/MrMelon54/png2ico v1.0.1
|
||||
github.com/MrMelon54/rescheduler v0.0.1
|
||||
|
2
go.sum
2
go.sum
@ -2,6 +2,8 @@ github.com/AlecAivazis/survey/v2 v2.3.7 h1:6I/u8FvytdGsgonrYsVn2t8t4QiRnh6QSTqkk
|
||||
github.com/AlecAivazis/survey/v2 v2.3.7/go.mod h1:xUTIdE4KCOIjsBAE1JYsUPoCqYdZ1reCfTwbto0Fduo=
|
||||
github.com/MrMelon54/certgen v0.0.1 h1:ycWdZ2RlxQ5qSuejeBVv4aXjGo5hdqqL4j4EjrXnFMk=
|
||||
github.com/MrMelon54/certgen v0.0.1/go.mod h1:GHflVlSbtFLJZLpN1oWyUvDBRrR8qCWiwZLXCCnS2Gc=
|
||||
github.com/MrMelon54/exit-reload v0.0.1 h1:sxHa59tNEQMcikwuX2+93lw6Vi1+R7oCRF8a0C3alXc=
|
||||
github.com/MrMelon54/exit-reload v0.0.1/go.mod h1:PLiSfmUzwdpTTQP3BBfUPhkqPwaIZjx0DuXBnM76Bug=
|
||||
github.com/MrMelon54/mjwt v0.1.1 h1:m+aTpxbhQCrOPKHN170DQMFR5r938LkviU38unob5Jw=
|
||||
github.com/MrMelon54/mjwt v0.1.1/go.mod h1:oYrDBWK09Hju98xb+bRQ0wy+RuAzacxYvKYOZchR2Tk=
|
||||
github.com/MrMelon54/png2ico v1.0.1 h1:zJoSSl4OkvSIMWGyGPvb8fWNa0KrUvMIjgNGLNLJhVQ=
|
||||
|
Loading…
Reference in New Issue
Block a user