Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature(main): add pid file #5

Merged
merged 1 commit into from
Oct 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading