Skip to content

Commit

Permalink
Add support for sd_notify for start / stop
Browse files Browse the repository at this point in the history
  • Loading branch information
afbjorklund committed Sep 22, 2021
1 parent 9ce92f8 commit 96fd1a7
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions dockershim/remote/docker_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,6 @@ func (s *DockerServer) Start() error {
os.Exit(1)
}
}()
handleNotify()
return nil
}
23 changes: 23 additions & 0 deletions dockershim/remote/docker_server_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ package remote

import (
"net"
"os"
"os/signal"
"syscall"

"github.com/coreos/go-systemd/v22/activation"
"github.com/coreos/go-systemd/v22/daemon"
"github.com/pkg/errors"
)

Expand All @@ -32,3 +36,22 @@ func listenFD(addr string) (net.Listener, error) {
//TODO: systemd fd selection (default is 3)
return nil, errors.New("not supported yet")
}

func sdNotify(state string) error {
_, err := daemon.SdNotify(false, state)
if err != nil {
//TODO: log the notification error
return err
}
return nil
}

func handleNotify() {
sdNotify(daemon.SdNotifyReady)
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
go func() {
<-sigs
sdNotify(daemon.SdNotifyStopping)
}()
}
3 changes: 3 additions & 0 deletions dockershim/remote/docker_server_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ import (
func listenFD(addr string) (net.Listener, error) {
return nil, errors.New("listening server on fd not supported on windows")
}

func handleNotify() {
}
2 changes: 1 addition & 1 deletion packaging/systemd/cri-docker.service
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Requires=cri-docker.socket

[Service]
Type=notify
ExecStart=/usr/bin/cri-dockerd --container-runtime-endpoint fd:// --network-plugin=""
ExecStart=/usr/bin/cri-dockerd --container-runtime-endpoint fd:// --network-plugin=
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutSec=0
RestartSec=2
Expand Down

0 comments on commit 96fd1a7

Please sign in to comment.