mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-10 18:05:48 +02:00
feat: add pidfile
parameter to support OpenRC
This commit is contained in:
parent
c92b31e903
commit
6b40d02b93
7 changed files with 55 additions and 16 deletions
|
@ -8,10 +8,10 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"code.pfad.fr/risefront"
|
||||
"github.com/0xJacky/Nginx-UI/internal/backup"
|
||||
"github.com/0xJacky/Nginx-UI/internal/nginx"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/jpillora/overseer"
|
||||
"github.com/uozi-tech/cosy"
|
||||
)
|
||||
|
||||
|
@ -123,7 +123,7 @@ func RestoreBackup(c *gin.Context) {
|
|||
go func() {
|
||||
time.Sleep(2 * time.Second)
|
||||
// gracefully restart
|
||||
overseer.Restart()
|
||||
risefront.Restart()
|
||||
}()
|
||||
}
|
||||
|
||||
|
|
4
go.mod
4
go.mod
|
@ -26,7 +26,6 @@ require (
|
|||
github.com/golang-jwt/jwt/v5 v5.2.2
|
||||
github.com/google/uuid v1.6.0
|
||||
github.com/gorilla/websocket v1.5.3
|
||||
github.com/jpillora/overseer v1.1.6
|
||||
github.com/lib/pq v1.10.9
|
||||
github.com/mark3labs/mcp-go v0.26.0
|
||||
github.com/minio/selfupdate v0.6.0
|
||||
|
@ -80,7 +79,6 @@ require (
|
|||
github.com/AzureAD/microsoft-authentication-library-for-go v1.4.2 // indirect
|
||||
github.com/Microsoft/go-winio v0.6.2 // indirect
|
||||
github.com/OpenDNS/vegadns2client v0.0.0-20180418235048-a3fa4a771d87 // indirect
|
||||
github.com/StackExchange/wmi v1.2.1 // indirect
|
||||
github.com/akamai/AkamaiOPEN-edgegrid-golang v1.2.2 // indirect
|
||||
github.com/baidubce/bce-sdk-go v0.9.225 // indirect
|
||||
github.com/blinkbean/dingtalk v1.1.3 // indirect
|
||||
|
@ -147,7 +145,6 @@ require (
|
|||
github.com/jinzhu/inflection v1.0.0 // indirect
|
||||
github.com/jinzhu/now v1.1.5 // indirect
|
||||
github.com/jonboulle/clockwork v0.5.0 // indirect
|
||||
github.com/jpillora/s3 v1.1.4 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/k0kubun/go-ansi v0.0.0-20180517002512-3bf9e2903213 // indirect
|
||||
github.com/klauspost/cpuid/v2 v2.2.10 // indirect
|
||||
|
@ -210,6 +207,7 @@ require (
|
|||
github.com/shopspring/decimal v1.4.0 // indirect
|
||||
github.com/sirupsen/logrus v1.9.3 // indirect
|
||||
github.com/smartystreets/go-aws-auth v0.0.0-20180515143844-0c1422d1fdb9 // indirect
|
||||
github.com/smartystreets/gunit v1.1.3 // indirect
|
||||
github.com/softlayer/softlayer-go v1.1.7 // indirect
|
||||
github.com/softlayer/xmlrpc v0.0.0-20200409220501-5f089df7cb7e // indirect
|
||||
github.com/sony/sonyflake v1.2.1 // indirect
|
||||
|
|
9
go.sum
9
go.sum
|
@ -686,9 +686,6 @@ github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWX
|
|||
github.com/Shopify/sarama v1.30.1/go.mod h1:hGgx05L/DiW8XYBXeJdKIN6V2QUy2H6JqME5VT1NLRw=
|
||||
github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI=
|
||||
github.com/Shopify/toxiproxy/v2 v2.1.6-0.20210914104332-15ea381dcdae/go.mod h1:/cvHQkZ1fst0EmZnA5dFtiQdWCNCFYzb+uE2vqVgvx0=
|
||||
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg=
|
||||
github.com/StackExchange/wmi v1.2.1 h1:VIkavFPXSjcnS+O8yTq7NI32k0R5Aj+v39y29VYDOSA=
|
||||
github.com/StackExchange/wmi v1.2.1/go.mod h1:rcmrprowKIVzvc+NUiLncP2uuArMWLCbu9SBzvHz7e8=
|
||||
github.com/VividCortex/gohistogram v1.0.0/go.mod h1:Pf5mBqqDxYaXu3hDrrU+w6nw50o/4+TcAqDqk/vUH7g=
|
||||
github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia65gfNATL8TAiHDNxPzPdmEL5uirI2Uyuz6c=
|
||||
github.com/ajstarks/deck v0.0.0-20200831202436-30c9fc6549a9/go.mod h1:JynElWSGnm/4RlzPXRlREEwqTHAN3T56Bv2ITsFT3gY=
|
||||
|
@ -934,8 +931,6 @@ github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
|
|||
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
|
||||
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
|
||||
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
|
||||
github.com/go-ole/go-ole v1.2.4/go.mod h1:XCwSNxSkXRo4vlyPy93sltvi/qJq0jqQhjqQNIwKuxM=
|
||||
github.com/go-ole/go-ole v1.2.5/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
|
||||
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
|
||||
github.com/go-ole/go-ole v1.3.0 h1:Dt6ye7+vXGIKZ7Xtk4s6/xVdGDQynvom7xCFEdWr6uE=
|
||||
github.com/go-ole/go-ole v1.3.0/go.mod h1:5LS6F96DhAwUc7C+1HLexzMXY1xGRSryjyPPKW6zv78=
|
||||
|
@ -1286,10 +1281,6 @@ github.com/jonboulle/clockwork v0.5.0/go.mod h1:3mZlmanh0g2NDKO5TWZVJAfofYk64M7X
|
|||
github.com/jordan-wright/email v4.0.1-0.20210109023952-943e75fe5223+incompatible h1:jdpOPRN1zP63Td1hDQbZW73xKmzDvZHzVdNYxhnTMDA=
|
||||
github.com/jordan-wright/email v4.0.1-0.20210109023952-943e75fe5223+incompatible/go.mod h1:1c7szIrayyPPB/987hsnvNzLushdWf4o/79s3P08L8A=
|
||||
github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4=
|
||||
github.com/jpillora/overseer v1.1.6 h1:3ygYfNcR3FfOr22miu3vR1iQcXKMHbmULBh98rbkIyo=
|
||||
github.com/jpillora/overseer v1.1.6/go.mod h1:aPXQtxuVb9PVWRWTXpo+LdnC/YXQ0IBLNXqKMJmgk88=
|
||||
github.com/jpillora/s3 v1.1.4 h1:YCCKDWzb/Ye9EBNd83ATRF/8wPEy0xd43Rezb6u6fzc=
|
||||
github.com/jpillora/s3 v1.1.4/go.mod h1:yedE603V+crlFi1Kl/5vZJaBu9pUzE9wvKegU/lF2zs=
|
||||
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
|
||||
github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
||||
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
||||
|
|
|
@ -24,6 +24,22 @@ func NewAppCmd() *cli.Command {
|
|||
serve = true
|
||||
return nil
|
||||
},
|
||||
Flags: []cli.Flag{
|
||||
&cli.StringFlag{
|
||||
Name: "pidfile",
|
||||
Usage: "`PATH` to the PID file",
|
||||
Action: func(ctx context.Context, command *cli.Command, s string) error {
|
||||
// remove `pidfile` parameter from os.Args
|
||||
for i, arg := range os.Args {
|
||||
if arg == "--pidfile" || arg == "-p" {
|
||||
os.Args = append(os.Args[:i], os.Args[i+2:]...)
|
||||
break
|
||||
}
|
||||
}
|
||||
return nil
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "reset-password",
|
||||
|
|
25
internal/process/pid.go
Normal file
25
internal/process/pid.go
Normal file
|
@ -0,0 +1,25 @@
|
|||
package process
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func WritePIDFile(pidFile string) error {
|
||||
pid := os.Getpid()
|
||||
if pid == 0 {
|
||||
return fmt.Errorf("failed to get process ID")
|
||||
}
|
||||
|
||||
pidStr := strconv.Itoa(pid)
|
||||
if err := os.WriteFile(pidFile, []byte(pidStr), 0644); err != nil {
|
||||
return fmt.Errorf("failed to write PID file: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func RemovePIDFile(pidFile string) {
|
||||
_ = os.Remove(pidFile)
|
||||
}
|
9
main.go
9
main.go
|
@ -11,6 +11,7 @@ import (
|
|||
|
||||
"github.com/0xJacky/Nginx-UI/internal/cert"
|
||||
"github.com/0xJacky/Nginx-UI/internal/cmd"
|
||||
"github.com/0xJacky/Nginx-UI/internal/process"
|
||||
|
||||
"code.pfad.fr/risefront"
|
||||
"github.com/0xJacky/Nginx-UI/internal/kernel"
|
||||
|
@ -106,6 +107,14 @@ func main() {
|
|||
ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM)
|
||||
defer cancel()
|
||||
|
||||
pidPath := appCmd.String("pidfile")
|
||||
if pidPath != "" {
|
||||
if err := process.WritePIDFile(pidPath); err != nil {
|
||||
logger.Fatalf("Failed to write PID file: %v", err)
|
||||
}
|
||||
defer process.RemovePIDFile(pidPath)
|
||||
}
|
||||
|
||||
err := risefront.New(ctx, risefront.Config{
|
||||
Run: Program(ctx, confPath),
|
||||
Name: "nginx-ui",
|
||||
|
|
|
@ -3,9 +3,9 @@
|
|||
name="nginx-ui"
|
||||
description="Nginx UI - Yet another WebUI for Nginx"
|
||||
supervisor=supervise-daemon
|
||||
command="/usr/local/bin/nginx-ui"
|
||||
command_args="-config /usr/local/etc/nginx-ui/app.ini"
|
||||
pidfile="/run/${RC_SVCNAME}.pid"
|
||||
command="/usr/local/bin/nginx-ui"
|
||||
command_args="serve --config /usr/local/etc/nginx-ui/app.ini --pidfile ${pidfile}"
|
||||
command_user="root:root"
|
||||
|
||||
extra_commands="status"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue