diff --git a/pkg/kopia/command/const.go b/pkg/kopia/command/const.go index 366f569503..9e8f0e2eb3 100644 --- a/pkg/kopia/command/const.go +++ b/pkg/kopia/command/const.go @@ -76,6 +76,8 @@ const ( tlsGenerateCertFlag = "--tls-generate-cert" tlsKeyFilePath = "--tls-key-file" userPasswordFlag = "--user-password" + enablePprof = "--enable-pprof" + metricsListerAddress = "--metrics-listen-addr" // Repository specific repositorySubCommand = "repository" diff --git a/pkg/kopia/command/server.go b/pkg/kopia/command/server.go index 42a0f2e431..07be9dd5aa 100644 --- a/pkg/kopia/command/server.go +++ b/pkg/kopia/command/server.go @@ -16,13 +16,15 @@ package command type ServerStartCommandArgs struct { *CommandArgs - ServerAddress string - TLSCertFile string - TLSKeyFile string - ServerUsername string - ServerPassword string - AutoGenerateCert bool - Background bool + ServerAddress string + TLSCertFile string + TLSKeyFile string + ServerUsername string + ServerPassword string + AutoGenerateCert bool + Background bool + EnablePprof bool + MetricsListenAddress string } // ServerStart returns the kopia command for starting the Kopia API Server @@ -46,6 +48,14 @@ func ServerStart(cmdArgs ServerStartCommandArgs) []string { // TODO: Remove when GRPC support is added args = args.AppendLoggable(noGrpcFlag) + if cmdArgs.EnablePprof { + args = args.AppendLoggable(enablePprof) + } + + if cmdArgs.MetricsListenAddress != "" { + args = args.AppendLoggableKV(metricsListerAddress, cmdArgs.MetricsListenAddress) + } + if cmdArgs.Background { // To start the server and run in the background args = args.AppendLoggable(redirectToDevNull, runInBackground) diff --git a/pkg/kopia/command/server_test.go b/pkg/kopia/command/server_test.go index 429e4eef98..45025aa92b 100644 --- a/pkg/kopia/command/server_test.go +++ b/pkg/kopia/command/server_test.go @@ -35,6 +35,24 @@ func (kServer *KopiaServerTestSuite) TestServerCommands(c *C) { f func() []string expectedLog string }{ + { + f: func() []string { + args := ServerStartCommandArgs{ + CommandArgs: commandArgs, + ServerAddress: "a-server-address", + TLSCertFile: "/path/to/cert/tls.crt", + TLSKeyFile: "/path/to/key/tls.key", + ServerUsername: "a-username@a-hostname", + ServerPassword: "a-user-password", + AutoGenerateCert: true, + Background: true, + EnablePprof: true, + MetricsListenAddress: "a-server-address:51516", + } + return ServerStart(args) + }, + expectedLog: "bash -o errexit -c kopia --log-level=error --config-file=path/kopia.config --log-dir=cache/log server start --tls-generate-cert --address=a-server-address --tls-cert-file=/path/to/cert/tls.crt --tls-key-file=/path/to/key/tls.key --server-username=a-username@a-hostname --server-password=a-user-password --server-control-username=a-username@a-hostname --server-control-password=a-user-password --no-grpc --enable-pprof --metrics-listen-addr=a-server-address:51516 > /dev/null 2>&1 &", + }, { f: func() []string { args := ServerStartCommandArgs{