mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-11 02:15:48 +02:00
feat: use risefront
to replace overseer
in order to supports Windows
This commit is contained in:
parent
cf531e3f09
commit
bfba7ba2c2
2 changed files with 36 additions and 21 deletions
|
@ -7,6 +7,7 @@ import (
|
|||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
@ -16,7 +17,6 @@ import (
|
|||
"github.com/0xJacky/Nginx-UI/internal/helper"
|
||||
"github.com/0xJacky/Nginx-UI/internal/version"
|
||||
"github.com/0xJacky/Nginx-UI/settings"
|
||||
"github.com/jpillora/overseer"
|
||||
"github.com/minio/selfupdate"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/uozi-tech/cosy/logger"
|
||||
|
@ -269,7 +269,6 @@ func (u *Upgrader) PerformCoreUpgrade(tarPath string) (err error) {
|
|||
}
|
||||
|
||||
// gracefully restart
|
||||
overseer.Restart()
|
||||
|
||||
return
|
||||
cmd := exec.Command(os.Args[0])
|
||||
return cmd.Start()
|
||||
}
|
||||
|
|
50
main.go
50
main.go
|
@ -5,17 +5,25 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"context"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
|
||||
"github.com/0xJacky/Nginx-UI/internal/cert"
|
||||
"github.com/0xJacky/Nginx-UI/internal/cmd"
|
||||
|
||||
"code.pfad.fr/risefront"
|
||||
"github.com/0xJacky/Nginx-UI/internal/kernel"
|
||||
"github.com/0xJacky/Nginx-UI/internal/migrate"
|
||||
"github.com/0xJacky/Nginx-UI/model"
|
||||
"github.com/0xJacky/Nginx-UI/router"
|
||||
"github.com/0xJacky/Nginx-UI/settings"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/jpillora/overseer"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/uozi-tech/cosy"
|
||||
cKernel "github.com/uozi-tech/cosy/kernel"
|
||||
"github.com/uozi-tech/cosy/logger"
|
||||
|
@ -23,9 +31,9 @@ import (
|
|||
cSettings "github.com/uozi-tech/cosy/settings"
|
||||
)
|
||||
|
||||
//go:generate go generate ./cmd/...
|
||||
func Program(confPath string) func(state overseer.State) {
|
||||
return func(state overseer.State) {
|
||||
func Program(confPath string) func(l []net.Listener) error {
|
||||
return func(l []net.Listener) error {
|
||||
listener := l[0]
|
||||
defer logger.Sync()
|
||||
defer logger.Info("Server exited")
|
||||
|
||||
|
@ -47,20 +55,22 @@ func Program(confPath string) func(state overseer.State) {
|
|||
logger.Init(cSettings.ServerSettings.RunMode)
|
||||
defer logger.Sync()
|
||||
|
||||
if state.Listener == nil {
|
||||
return
|
||||
}
|
||||
// Gin router initialization
|
||||
cRouter.Init()
|
||||
|
||||
// Kernel boot
|
||||
cKernel.Boot()
|
||||
|
||||
addr := fmt.Sprintf("%s:%d", cSettings.ServerSettings.Host, cSettings.ServerSettings.Port)
|
||||
srv := &http.Server{
|
||||
Addr: addr,
|
||||
Handler: cRouter.GetEngine(),
|
||||
}
|
||||
// defer Shutdown to wait for ongoing requests to be served before returning
|
||||
defer func(srv *http.Server, ctx context.Context) {
|
||||
err := srv.Shutdown(ctx)
|
||||
if err != nil {
|
||||
logger.Fatal(err)
|
||||
}
|
||||
}(srv, context.Background())
|
||||
var err error
|
||||
if cSettings.ServerSettings.EnableHTTPS {
|
||||
// Load TLS certificate
|
||||
|
@ -80,11 +90,11 @@ func Program(confPath string) func(state overseer.State) {
|
|||
srv.TLSConfig = tlsConfig
|
||||
|
||||
logger.Info("Starting HTTPS server")
|
||||
tlsListener := tls.NewListener(state.Listener, tlsConfig)
|
||||
tlsListener := tls.NewListener(listener, tlsConfig)
|
||||
err = srv.Serve(tlsListener)
|
||||
} else {
|
||||
logger.Info("Starting HTTP server")
|
||||
err = srv.Serve(state.Listener)
|
||||
err = srv.Serve(listener)
|
||||
}
|
||||
if err != nil && !errors.Is(err, http.ErrServerClosed) {
|
||||
logger.Fatalf("listen: %s\n", err)
|
||||
|
@ -97,10 +107,16 @@ func main() {
|
|||
|
||||
confPath := appCmd.String("config")
|
||||
settings.Init(confPath)
|
||||
overseer.Run(overseer.Config{
|
||||
Program: Program(confPath),
|
||||
Address: fmt.Sprintf("%s:%d", cSettings.ServerSettings.Host, cSettings.ServerSettings.Port),
|
||||
TerminateTimeout: 5 * time.Second,
|
||||
Debug: cSettings.ServerSettings.RunMode == gin.DebugMode,
|
||||
|
||||
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
|
||||
defer cancel()
|
||||
|
||||
err := risefront.New(ctx, risefront.Config{
|
||||
Run: Program(confPath),
|
||||
Debug: cSettings.ServerSettings.RunMode == gin.DebugMode,
|
||||
Addresses: []string{fmt.Sprintf("%s:%d", cSettings.ServerSettings.Host, cSettings.ServerSettings.Port)},
|
||||
})
|
||||
if !errors.Is(err, context.DeadlineExceeded) {
|
||||
logger.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue