feat: add pidfile parameter to support OpenRC

This commit is contained in:
Hintay 2025-05-08 23:08:51 +09:00
parent c92b31e903
commit 6b40d02b93
No known key found for this signature in database
GPG key ID: 120FC7FF121F2F2D
7 changed files with 55 additions and 16 deletions

View file

@ -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
View 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)
}