Skip to content

Commit

Permalink
feature(main): add pid file
Browse files Browse the repository at this point in the history
Signed-off-by: cuisongliu <[email protected]>
  • Loading branch information
cuisongliu committed Oct 22, 2023
1 parent 47d17ed commit 548257a
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/registry/commands/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package commands
import (
"errors"
"fmt"
"github.com/labring/sreg/pkg/utils/file"
"net"
"net/http"
"os"
Expand All @@ -36,6 +37,7 @@ func newRegistryServeFilesystemCommand() *cobra.Command {
port int
disableLogging bool
logLevel string
pidFile string
)
cmd := &cobra.Command{
Use: "filesystem",
Expand All @@ -50,6 +52,12 @@ func newRegistryServeFilesystemCommand() *cobra.Command {
if !disableLogging {
logger.Info("serving on %s", config.HTTP.Addr)
}
if pidFile != "" {
err = file.WriteFile(pidFile, []byte(fmt.Sprintf("%d", os.Getpid())))
if err != nil {
return fmt.Errorf("failed to write pid file: %w", err)
}
}
config.Log.Level = configuration.Loglevel(logLevel)
config.Log.AccessLog.Disabled = disableLogging
errCh := handler.Run(cmd.Context(), config)
Expand All @@ -59,6 +67,7 @@ func newRegistryServeFilesystemCommand() *cobra.Command {
cmd.Flags().IntVarP(&port, "port", "p", 0, "listening port, default is random unused port")
cmd.Flags().BoolVar(&disableLogging, "disable-logging", false, "disable logging output")
cmd.Flags().StringVar(&logLevel, "log-level", "error", "configure logging level")
cmd.Flags().StringVar(&pidFile, "pid-file", "", "write the process ID to a file")
return cmd
}

Expand Down

0 comments on commit 548257a

Please sign in to comment.