Replace exit and reload logic with my new library

This commit is contained in:
Melon 2023-07-24 15:53:32 +01:00
parent bfdcb07613
commit a744f450f7
Signed by: melon
GPG Key ID: 6C9D970C50D26A25
3 changed files with 9 additions and 20 deletions

View File

@ -4,22 +4,19 @@ import (
"context" "context"
"database/sql" "database/sql"
"flag" "flag"
"fmt"
httpAcme "github.com/1f349/orchid/http-acme" httpAcme "github.com/1f349/orchid/http-acme"
"github.com/1f349/orchid/renewal" "github.com/1f349/orchid/renewal"
"github.com/1f349/orchid/servers" "github.com/1f349/orchid/servers"
"github.com/1f349/violet/utils" "github.com/1f349/violet/utils"
"github.com/MrMelon54/exit-reload"
"github.com/MrMelon54/mjwt" "github.com/MrMelon54/mjwt"
"github.com/google/subcommands" "github.com/google/subcommands"
_ "github.com/mattn/go-sqlite3" _ "github.com/mattn/go-sqlite3"
"gopkg.in/yaml.v3" "gopkg.in/yaml.v3"
"log" "log"
"os" "os"
"os/signal"
"path/filepath" "path/filepath"
"sync" "sync"
"syscall"
"time"
) )
type serveCmd struct{ configPath string } type serveCmd struct{ configPath string }
@ -94,20 +91,9 @@ func normalLoad(conf startUpConfig, wd string) {
log.Printf("[API] Starting API server on: '%s'\n", srv.Addr) log.Printf("[API] Starting API server on: '%s'\n", srv.Addr)
go utils.RunBackgroundHttp("API", srv) go utils.RunBackgroundHttp("API", srv)
// Wait for exit signal exit_reload.ExitReload("Violet", func() {}, func() {
sc := make(chan os.Signal, 1)
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt, os.Kill)
<-sc
fmt.Println()
// Stop servers
log.Printf("[Orchid] Stopping...")
n := time.Now()
// stop renewal service and api server // stop renewal service and api server
renewalService.Shutdown() renewalService.Shutdown()
srv.Close() srv.Close()
})
log.Printf("[Orchid] Took '%s' to shutdown\n", time.Now().Sub(n))
log.Println("[Orchid] Goodbye")
} }

1
go.mod
View File

@ -6,6 +6,7 @@ require (
github.com/1f349/violet v0.0.6 github.com/1f349/violet v0.0.6
github.com/AlecAivazis/survey/v2 v2.3.7 github.com/AlecAivazis/survey/v2 v2.3.7
github.com/MrMelon54/certgen v0.0.1 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/mjwt v0.1.1
github.com/go-acme/lego/v4 v4.12.3 github.com/go-acme/lego/v4 v4.12.3
github.com/google/subcommands v1.2.0 github.com/google/subcommands v1.2.0

2
go.sum
View File

@ -4,6 +4,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/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 h1:ycWdZ2RlxQ5qSuejeBVv4aXjGo5hdqqL4j4EjrXnFMk=
github.com/MrMelon54/certgen v0.0.1/go.mod h1:GHflVlSbtFLJZLpN1oWyUvDBRrR8qCWiwZLXCCnS2Gc= 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 h1:m+aTpxbhQCrOPKHN170DQMFR5r938LkviU38unob5Jw=
github.com/MrMelon54/mjwt v0.1.1/go.mod h1:oYrDBWK09Hju98xb+bRQ0wy+RuAzacxYvKYOZchR2Tk= github.com/MrMelon54/mjwt v0.1.1/go.mod h1:oYrDBWK09Hju98xb+bRQ0wy+RuAzacxYvKYOZchR2Tk=
github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2 h1:+vx7roKuyA63nhn5WAunQHLTznkw5W8b1Xc0dNjp83s= github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2 h1:+vx7roKuyA63nhn5WAunQHLTznkw5W8b1Xc0dNjp83s=