Skip to content

Commit a4c11d5

Browse files
authored
Merge pull request #997 from 0xJacky/feat/platform-windows
feat: platform windows
2 parents 3fe4d85 + 85a4644 commit a4c11d5

File tree

8 files changed

+58
-37
lines changed

8 files changed

+58
-37
lines changed

.air.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ delay = 1000 # ms
3333
# Stop running old binary when build errors occur.
3434
stop_on_error = true
3535
# Send Interrupt signal before killing process (windows does not support this feature)
36-
send_interrupt = false
36+
send_interrupt = true
3737
# Delay after sending Interrupt signal
3838
kill_delay = 500 # ms
3939

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ jobs:
187187
env:
188188
GOOS: linux
189189
GOARCH: amd64
190-
run: go generate
190+
run: go generate cmd/version/generate.go
191191

192192
- name: Install musl cross compiler
193193
if: env.GOOS == 'linux'

go.mod

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module github.com/0xJacky/Nginx-UI
33
go 1.24.2
44

55
require (
6+
code.pfad.fr/risefront v1.0.0
67
github.com/0xJacky/pofile v1.0.0
78
github.com/BurntSushi/toml v1.5.0
89
github.com/caarlos0/env/v11 v11.3.1
@@ -77,7 +78,7 @@ require (
7778
github.com/Azure/go-autorest/logger v0.2.2 // indirect
7879
github.com/Azure/go-autorest/tracing v0.6.1 // indirect
7980
github.com/AzureAD/microsoft-authentication-library-for-go v1.4.2 // indirect
80-
github.com/Microsoft/go-winio v0.4.14 // indirect
81+
github.com/Microsoft/go-winio v0.6.2 // indirect
8182
github.com/OpenDNS/vegadns2client v0.0.0-20180418235048-a3fa4a771d87 // indirect
8283
github.com/StackExchange/wmi v1.2.1 // indirect
8384
github.com/akamai/AkamaiOPEN-edgegrid-golang v1.2.2 // indirect
@@ -312,6 +313,7 @@ require (
312313
)
313314

314315
replace (
316+
code.pfad.fr/risefront => github.com/nginxui/risefront v0.0.0-20250428220145-c87a8799e07d
315317
github.com/tufanbarisyildirim/gonginx => github.com/0xJacky/gonginx v0.0.0-20250420001451-d120448e89a4
316318
gorm.io/gorm => gorm.io/gorm v1.25.12
317319
gorm.io/plugin/dbresolver => gorm.io/plugin/dbresolver v1.5.3

go.sum

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -677,8 +677,8 @@ github.com/HdrHistogram/hdrhistogram-go v1.1.2/go.mod h1:yDgFjdqOqDEKOvasDdhWNXY
677677
github.com/JohnCGriffin/overflow v0.0.0-20211019200055-46fa312c352c/go.mod h1:X0CRv0ky0k6m906ixxpzmDRLvX58TFUKS2eePweuyxk=
678678
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0=
679679
github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs=
680-
github.com/Microsoft/go-winio v0.4.14 h1:+hMXMk01us9KgxGb7ftKQt2Xpf5hH/yky+TDA+qxleU=
681-
github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jBhyzoq1bpyYA=
680+
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
681+
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
682682
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
683683
github.com/OpenDNS/vegadns2client v0.0.0-20180418235048-a3fa4a771d87 h1:xPMsUicZ3iosVPSIP7bW5EcGUzjiiMl1OYTe14y/R24=
684684
github.com/OpenDNS/vegadns2client v0.0.0-20180418235048-a3fa4a771d87/go.mod h1:iGLljf5n9GjT6kc0HBvyI1nOKnGQbNB66VzSNbK5iks=
@@ -1423,8 +1423,6 @@ github.com/lyft/protoc-gen-star/v2 v2.0.1/go.mod h1:RcCdONR2ScXaYnQC5tUzxzlpA3WV
14231423
github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
14241424
github.com/magiconair/properties v1.8.4/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60=
14251425
github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
1426-
github.com/mark3labs/mcp-go v0.23.1 h1:RzTzZ5kJ+HxwnutKA4rll8N/pKV6Wh5dhCmiJUu5S9I=
1427-
github.com/mark3labs/mcp-go v0.23.1/go.mod h1:rXqOudj/djTORU/ThxYx8fqEVj/5pvTuuebQ2RC7uk4=
14281426
github.com/mark3labs/mcp-go v0.25.0 h1:UUpcMT3L5hIhuDy7aifj4Bphw4Pfx1Rf8mzMXDe8RQw=
14291427
github.com/mark3labs/mcp-go v0.25.0/go.mod h1:rXqOudj/djTORU/ThxYx8fqEVj/5pvTuuebQ2RC7uk4=
14301428
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
@@ -1524,6 +1522,8 @@ github.com/nats-io/nkeys v0.2.0/go.mod h1:XdZpAbhgyyODYqjTawOnIOI7VlbKSarI9Gfy1t
15241522
github.com/nats-io/nkeys v0.3.0/go.mod h1:gvUNGjVcM2IPr5rCsRsC6Wb3Hr2CQAm08dsxtV6A5y4=
15251523
github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
15261524
github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32/go.mod h1:9wM+0iRr9ahx58uYLpLIr5fm8diHn0JbqRycJi6w0Ms=
1525+
github.com/nginxui/risefront v0.0.0-20250428220145-c87a8799e07d h1:+crdPAj8T3MWH49O07e7SOjpvOa0l2R3M6KgfW8vG1s=
1526+
github.com/nginxui/risefront v0.0.0-20250428220145-c87a8799e07d/go.mod h1:QX3OyvazX3Mi/X2NZKl9ylDrFVUeaogwSMKyEsnRCHE=
15271527
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
15281528
github.com/nikoksr/notify v1.3.0 h1:UxzfxzAYGQD9a5JYLBTVx0lFMxeHCke3rPCkfWdPgLs=
15291529
github.com/nikoksr/notify v1.3.0/go.mod h1:Xor2hMmkvrCfkCKvXGbcrESez4brac2zQjhd6U2BbeM=
@@ -1694,12 +1694,8 @@ github.com/sacloud/packages-go v0.0.11/go.mod h1:XNF5MCTWcHo9NiqWnYctVbASSSZR3ZO
16941694
github.com/sagikazarmark/crypt v0.10.0/go.mod h1:gwTNHQVoOS3xp9Xvz5LLR+1AauC5M6880z5NWzdhOyQ=
16951695
github.com/sagikazarmark/locafero v0.9.0 h1:GbgQGNtTrEmddYDSAH9QLRyfAHY12md+8YFTqyMTC9k=
16961696
github.com/sagikazarmark/locafero v0.9.0/go.mod h1:UBUyz37V+EdMS3hDF3QWIiVr/2dPrx49OMO0Bn0hJqk=
1697-
github.com/samber/lo v1.49.1 h1:4BIFyVfuQSEpluc7Fua+j1NolZHiEHEpaSEKdsH0tew=
1698-
github.com/samber/lo v1.49.1/go.mod h1:dO6KHFzUKXgP8LDhU0oI8d2hekjXnGOu0DB8Jecxd6o=
16991697
github.com/samber/lo v1.50.0 h1:XrG0xOeHs+4FQ8gJR97zDz5uOFMW7OwFWiFVzqopKgY=
17001698
github.com/samber/lo v1.50.0/go.mod h1:RjZyNk6WSnUFRKK6EyOhsRJMqft3G+pg7dCWHQCWvsc=
1701-
github.com/sashabaranov/go-openai v1.38.2 h1:akrssjj+6DY3lWuDwHv6cBvJ8Z+FZDM9XEaaYFt0Auo=
1702-
github.com/sashabaranov/go-openai v1.38.2/go.mod h1:lj5b/K+zjTSFxVLijLSTDZuP7adOgerWeFyZLUhAKRg=
17031699
github.com/sashabaranov/go-openai v1.39.0 h1:7Ubg/9njZlBJ8qFs6q5gExpfkAhy3E9VN3pciG7H6pY=
17041700
github.com/sashabaranov/go-openai v1.39.0/go.mod h1:lj5b/K+zjTSFxVLijLSTDZuP7adOgerWeFyZLUhAKRg=
17051701
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
@@ -1710,8 +1706,6 @@ github.com/selectel/domains-go v1.1.0 h1:futG50J43ALLKQAnZk9H9yOtLGnSUh7c5hSvuC5
17101706
github.com/selectel/domains-go v1.1.0/go.mod h1:SugRKfq4sTpnOHquslCpzda72wV8u0cMBHx0C0l+bzA=
17111707
github.com/selectel/go-selvpcclient/v3 v3.2.1 h1:ny6WIAMiHzKxOgOEnwcWE79wIQij1AHHylzPA41MXCw=
17121708
github.com/selectel/go-selvpcclient/v3 v3.2.1/go.mod h1:3EfSf8aEWyhspOGbvZ6mvnFg7JN5uckxNyBFPGWsXNQ=
1713-
github.com/shirou/gopsutil/v4 v4.25.3 h1:SeA68lsu8gLggyMbmCn8cmp97V1TI9ld9sVzAUcKcKE=
1714-
github.com/shirou/gopsutil/v4 v4.25.3/go.mod h1:xbuxyoZj+UsgnZrENu3lQivsngRR5BdjbJwf2fv4szA=
17151709
github.com/shirou/gopsutil/v4 v4.25.4 h1:cdtFO363VEOOFrUCjZRh4XVJkb548lyF0q0uTeMqYPw=
17161710
github.com/shirou/gopsutil/v4 v4.25.4/go.mod h1:xbuxyoZj+UsgnZrENu3lQivsngRR5BdjbJwf2fv4szA=
17171711
github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24/go.mod h1:M+9NzErvs504Cn4c5DxATwIqPbtswREoFCre64PpcG4=
@@ -1843,8 +1837,6 @@ github.com/uozi-tech/cosy-driver-postgres v0.2.1/go.mod h1:eAy1A89yHbAEfjkhNAifa
18431837
github.com/uozi-tech/cosy-driver-sqlite v0.2.1 h1:W+Z4pY25PSJCeReqroG7LIBeffsqotbpHzgqSMqZDIM=
18441838
github.com/uozi-tech/cosy-driver-sqlite v0.2.1/go.mod h1:2ya7Z5P3HzFi1ktfL8gvwaAGx0DDV0bmWxNSNpaLlwo=
18451839
github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI=
1846-
github.com/urfave/cli/v3 v3.2.0 h1:m8WIXY0U9LCuUl5r+0fqLWDhNYWt6qvlW+GcF4EoXf8=
1847-
github.com/urfave/cli/v3 v3.2.0/go.mod h1:FJSKtM/9AiiTOJL4fJ6TbMUkxBXn7GO9guZqoZtpYpo=
18481840
github.com/urfave/cli/v3 v3.3.2 h1:BYFVnhhZ8RqT38DxEYVFPPmGFTEf7tJwySTXsVRrS/o=
18491841
github.com/urfave/cli/v3 v3.3.2/go.mod h1:FJSKtM/9AiiTOJL4fJ6TbMUkxBXn7GO9guZqoZtpYpo=
18501842
github.com/vinyldns/go-vinyldns v0.9.16 h1:GZJStDkcCk1F1AcRc64LuuMh+ENL8pHA0CVd4ulRMcQ=

install.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,8 @@ After=network.target
272272
[Service]
273273
Type=simple
274274
ExecStart=/usr/local/bin/nginx-ui -config /usr/local/etc/nginx-ui/app.ini
275+
RuntimeDirectory=nginx-ui
276+
WorkingDirectory=/var/run/nginx-ui
275277
Restart=on-failure
276278
TimeoutStopSec=5
277279
KillMode=mixed

internal/upgrader/upgrade.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ import (
1212
"strings"
1313
"sync/atomic"
1414

15+
"code.pfad.fr/risefront"
1516
_github "github.com/0xJacky/Nginx-UI/.github"
1617
"github.com/0xJacky/Nginx-UI/internal/helper"
1718
"github.com/0xJacky/Nginx-UI/internal/version"
1819
"github.com/0xJacky/Nginx-UI/settings"
19-
"github.com/jpillora/overseer"
2020
"github.com/minio/selfupdate"
2121
"github.com/pkg/errors"
2222
"github.com/uozi-tech/cosy/logger"
@@ -269,7 +269,6 @@ func (u *Upgrader) PerformCoreUpgrade(tarPath string) (err error) {
269269
}
270270

271271
// gracefully restart
272-
overseer.Restart()
273-
272+
risefront.Restart()
274273
return
275274
}

main.go

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,35 @@ package main
22

33
import (
44
"crypto/tls"
5-
"errors"
65
"fmt"
76
"net/http"
8-
"time"
7+
8+
"context"
9+
"net"
10+
"os/signal"
11+
"syscall"
912

1013
"github.com/0xJacky/Nginx-UI/internal/cert"
1114
"github.com/0xJacky/Nginx-UI/internal/cmd"
15+
16+
"code.pfad.fr/risefront"
1217
"github.com/0xJacky/Nginx-UI/internal/kernel"
1318
"github.com/0xJacky/Nginx-UI/internal/migrate"
1419
"github.com/0xJacky/Nginx-UI/model"
1520
"github.com/0xJacky/Nginx-UI/router"
1621
"github.com/0xJacky/Nginx-UI/settings"
1722
"github.com/gin-gonic/gin"
18-
"github.com/jpillora/overseer"
23+
"github.com/pkg/errors"
1924
"github.com/uozi-tech/cosy"
2025
cKernel "github.com/uozi-tech/cosy/kernel"
2126
"github.com/uozi-tech/cosy/logger"
2227
cRouter "github.com/uozi-tech/cosy/router"
2328
cSettings "github.com/uozi-tech/cosy/settings"
2429
)
2530

26-
//go:generate go generate ./cmd/...
27-
func Program(confPath string) func(state overseer.State) {
28-
return func(state overseer.State) {
31+
func Program(confPath string) func(l []net.Listener) error {
32+
return func(l []net.Listener) error {
33+
listener := l[0]
2934
defer logger.Sync()
3035
defer logger.Info("Server exited")
3136

@@ -47,27 +52,29 @@ func Program(confPath string) func(state overseer.State) {
4752
logger.Init(cSettings.ServerSettings.RunMode)
4853
defer logger.Sync()
4954

50-
if state.Listener == nil {
51-
return
52-
}
5355
// Gin router initialization
5456
cRouter.Init()
5557

5658
// Kernel boot
5759
cKernel.Boot()
5860

59-
addr := fmt.Sprintf("%s:%d", cSettings.ServerSettings.Host, cSettings.ServerSettings.Port)
6061
srv := &http.Server{
61-
Addr: addr,
6262
Handler: cRouter.GetEngine(),
6363
}
64+
// defer Shutdown to wait for ongoing requests to be served before returning
65+
defer func(srv *http.Server, ctx context.Context) {
66+
err := srv.Shutdown(ctx)
67+
if err != nil {
68+
logger.Fatal(err)
69+
}
70+
}(srv, context.Background())
6471
var err error
6572
if cSettings.ServerSettings.EnableHTTPS {
6673
// Load TLS certificate
6774
err = cert.LoadServerTLSCertificate()
6875
if err != nil {
6976
logger.Fatalf("Failed to load TLS certificate: %v", err)
70-
return
77+
return err
7178
}
7279

7380
tlsConfig := &tls.Config{
@@ -80,15 +87,16 @@ func Program(confPath string) func(state overseer.State) {
8087
srv.TLSConfig = tlsConfig
8188

8289
logger.Info("Starting HTTPS server")
83-
tlsListener := tls.NewListener(state.Listener, tlsConfig)
90+
tlsListener := tls.NewListener(listener, tlsConfig)
8491
err = srv.Serve(tlsListener)
8592
} else {
8693
logger.Info("Starting HTTP server")
87-
err = srv.Serve(state.Listener)
94+
err = srv.Serve(listener)
8895
}
8996
if err != nil && !errors.Is(err, http.ErrServerClosed) {
9097
logger.Fatalf("listen: %s\n", err)
9198
}
99+
return nil
92100
}
93101
}
94102

@@ -97,10 +105,24 @@ func main() {
97105

98106
confPath := appCmd.String("config")
99107
settings.Init(confPath)
100-
overseer.Run(overseer.Config{
101-
Program: Program(confPath),
102-
Address: fmt.Sprintf("%s:%d", cSettings.ServerSettings.Host, cSettings.ServerSettings.Port),
103-
TerminateTimeout: 5 * time.Second,
104-
Debug: cSettings.ServerSettings.RunMode == gin.DebugMode,
108+
109+
ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
110+
defer cancel()
111+
112+
err := risefront.New(ctx, risefront.Config{
113+
Run: Program(confPath),
114+
Name: "nginx-ui",
115+
Addresses: []string{fmt.Sprintf("%s:%d", cSettings.ServerSettings.Host, cSettings.ServerSettings.Port)},
116+
ErrorHandler: func(kind string, err error) {
117+
if errors.Is(err, net.ErrClosed) {
118+
return
119+
}
120+
logger.Error(kind, err)
121+
},
105122
})
123+
if err != nil && !errors.Is(err, context.DeadlineExceeded) &&
124+
!errors.Is(err, context.Canceled) &&
125+
!errors.Is(err, net.ErrClosed) {
126+
logger.Error(err)
127+
}
106128
}

nginx-ui.service

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@
22
Description=Yet another WebUI for Nginx
33
Documentation=https://github.com/0xJacky/nginx-ui
44
After=network.target
5+
56
[Service]
67
Type=simple
78
ExecStart=/usr/local/bin/nginx-ui --config /usr/local/etc/nginx-ui/app.ini
9+
RuntimeDirectory=nginx-ui
10+
WorkingDirectory=/var/run/nginx-ui
811
Restart=on-failure
912
TimeoutStopSec=5
1013
KillMode=mixed
14+
1115
[Install]
1216
WantedBy=multi-user.target

0 commit comments

Comments
 (0)