summaryrefslogtreecommitdiff
path: root/pkg/api/server/server.go
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2020-10-20 11:16:11 -0400
committerGitHub <noreply@github.com>2020-10-20 11:16:11 -0400
commit6c0b600e7d49d17db6eedd21b755b5d4f1a15b11 (patch)
treebacb719aef9c18e181d4014abb37d3a103f7a601 /pkg/api/server/server.go
parent35b4cb196545eee3b072083e716ad4588e0bb486 (diff)
parentf58d2f5e75b4982774509847c18b39f4a50fd5be (diff)
downloadpodman-6c0b600e7d49d17db6eedd21b755b5d4f1a15b11.tar.gz
podman-6c0b600e7d49d17db6eedd21b755b5d4f1a15b11.tar.bz2
podman-6c0b600e7d49d17db6eedd21b755b5d4f1a15b11.zip
Merge pull request #7999 from mheon/signal_handler
Add a shutdown signal handler
Diffstat (limited to 'pkg/api/server/server.go')
-rw-r--r--pkg/api/server/server.go24
1 files changed, 13 insertions, 11 deletions
diff --git a/pkg/api/server/server.go b/pkg/api/server/server.go
index 355a46fb7..64008767b 100644
--- a/pkg/api/server/server.go
+++ b/pkg/api/server/server.go
@@ -7,7 +7,6 @@ import (
"net"
"net/http"
"os"
- "os/signal"
goRuntime "runtime"
"strings"
"sync"
@@ -15,6 +14,7 @@ import (
"time"
"github.com/containers/podman/v2/libpod"
+ "github.com/containers/podman/v2/libpod/shutdown"
"github.com/containers/podman/v2/pkg/api/handlers"
"github.com/containers/podman/v2/pkg/api/server/idle"
"github.com/coreos/go-systemd/v22/activation"
@@ -180,8 +180,17 @@ func setupSystemd() {
// Serve starts responding to HTTP requests.
func (s *APIServer) Serve() error {
setupSystemd()
- sigChan := make(chan os.Signal, 1)
- signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)
+
+ // Start the shutdown signal handler.
+ if err := shutdown.Start(); err != nil {
+ return err
+ }
+ if err := shutdown.Register("server", func(sig os.Signal) error {
+ return s.Shutdown()
+ }); err != nil {
+ return err
+ }
+
errChan := make(chan error, 1)
go func() {
@@ -217,14 +226,7 @@ func (s *APIServer) Serve() error {
errChan <- nil
}()
- select {
- case err := <-errChan:
- return err
- case sig := <-sigChan:
- logrus.Infof("APIServer terminated by signal %v", sig)
- }
-
- return nil
+ return <-errChan
}
// Shutdown is a clean shutdown waiting on existing clients