summaryrefslogtreecommitdiff
path: root/cmd/podman/system/service_abi.go
diff options
context:
space:
mode:
authorJhon Honce <jhonce@redhat.com>2021-10-05 10:43:55 -0700
committerJhon Honce <jhonce@redhat.com>2021-10-08 13:57:20 -0700
commit8d3aec9d08bddf486dcb30e7113777b9d0cc27bd (patch)
treee47d47a39f50f7cadaaf0c8bd81f5ed689081b1a /cmd/podman/system/service_abi.go
parentbd4d9a09520b2329b1cf3dd8cdf8194b8bdeab67 (diff)
downloadpodman-8d3aec9d08bddf486dcb30e7113777b9d0cc27bd.tar.gz
podman-8d3aec9d08bddf486dcb30e7113777b9d0cc27bd.tar.bz2
podman-8d3aec9d08bddf486dcb30e7113777b9d0cc27bd.zip
Enable /debug/pprof API service endpoints
* Refactor sidecar HTTP service for /debug/pprof endpoints to use a TCP address given via new podman system service --pprof-address flag * Allow same URL parsing in "system service" as bindings/connection.go * Refactor NewServerWithSettings() to use entities.ServiceOptions in place of deleted server.Options * Updated godoc for impacted functions and types * Fixed API service Shutdown() to do an orderly shutdown when terminated and running with --time=0 Signed-off-by: Jhon Honce <jhonce@redhat.com>
Diffstat (limited to 'cmd/podman/system/service_abi.go')
-rw-r--r--cmd/podman/system/service_abi.go61
1 files changed, 37 insertions, 24 deletions
diff --git a/cmd/podman/system/service_abi.go b/cmd/podman/system/service_abi.go
index e484db339..0a4be6aea 100644
--- a/cmd/podman/system/service_abi.go
+++ b/cmd/podman/system/service_abi.go
@@ -5,9 +5,9 @@ package system
import (
"context"
"net"
+ "net/url"
"os"
"path/filepath"
- "strings"
api "github.com/containers/podman/v3/pkg/api/server"
"github.com/containers/podman/v3/pkg/domain/entities"
@@ -20,41 +20,54 @@ import (
"golang.org/x/sys/unix"
)
-func restService(opts entities.ServiceOptions, flags *pflag.FlagSet, cfg *entities.PodmanConfig) error {
+func restService(flags *pflag.FlagSet, cfg *entities.PodmanConfig, opts entities.ServiceOptions) error {
var (
listener *net.Listener
err error
)
if opts.URI != "" {
- fields := strings.Split(opts.URI, ":")
- if len(fields) == 1 {
+ uri, err := url.Parse(opts.URI)
+ if err != nil {
return errors.Errorf("%s is an invalid socket destination", opts.URI)
}
- path := opts.URI
- if fields[0] == "unix" {
- if path, err = filepath.Abs(fields[1]); err != nil {
- return err
- }
- }
- util.SetSocketPath(path)
- if os.Getenv("LISTEN_FDS") != "" {
- // If it is activated by systemd, use the first LISTEN_FD (3)
- // instead of opening the socket file.
- f := os.NewFile(uintptr(3), "podman.sock")
- l, err := net.FileListener(f)
+
+ switch uri.Scheme {
+ case "unix":
+ path, err := filepath.Abs(uri.Path)
if err != nil {
return err
}
- listener = &l
- } else {
- network := fields[0]
- address := strings.Join(fields[1:], ":")
- l, err := net.Listen(network, address)
+ util.SetSocketPath(path)
+ if os.Getenv("LISTEN_FDS") != "" {
+ // If it is activated by systemd, use the first LISTEN_FD (3)
+ // instead of opening the socket file.
+ f := os.NewFile(uintptr(3), "podman.sock")
+ l, err := net.FileListener(f)
+ if err != nil {
+ return err
+ }
+ listener = &l
+ } else {
+ l, err := net.Listen(uri.Scheme, path)
+ if err != nil {
+ return errors.Wrapf(err, "unable to create socket")
+ }
+ listener = &l
+ }
+ case "tcp":
+ host := uri.Host
+ if host == "" {
+ // For backward compatibility, support "tcp:<host>:<port>" and "tcp://<host>:<port>"
+ host = uri.Opaque
+ }
+ l, err := net.Listen(uri.Scheme, host)
if err != nil {
- return errors.Wrapf(err, "unable to create socket")
+ return errors.Wrapf(err, "unable to create socket %v", host)
}
listener = &l
+ default:
+ logrus.Debugf("Attempting API Service endpoint scheme %q", uri.Scheme)
}
}
@@ -75,12 +88,12 @@ func restService(opts entities.ServiceOptions, flags *pflag.FlagSet, cfg *entiti
servicereaper.Start()
infra.StartWatcher(rt)
- server, err := api.NewServerWithSettings(rt, listener, api.Options{Timeout: opts.Timeout, CorsHeaders: opts.CorsHeaders})
+ server, err := api.NewServerWithSettings(rt, listener, opts)
if err != nil {
return err
}
defer func() {
- if err := server.Shutdown(); err != nil {
+ if err := server.Shutdown(false); err != nil {
logrus.Warnf("Error when stopping API service: %s", err)
}
}()