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
|
@ -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)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue