Skip to content

Commit

Permalink
Use sdnotify for systemd (#768)
Browse files Browse the repository at this point in the history
* Use sdnotify for systemd

This is useful if a configuration is long to load.
Systemd will continue dependency chain only when server have finish to start.

https://www.freedesktop.org/software/systemd/man/systemd.service.html#Type=

* Extract the waiting behavior from Start()
  • Loading branch information
guilhem authored and vdemeester committed Oct 25, 2016
1 parent 870f378 commit 649cb54
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4 deletions.
1 change: 1 addition & 0 deletions contrib/systemd/traefik.service
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Description=Traefik

[Service]
Type=notify
ExecStart=/usr/bin/traefik --configFile=/etc/traefik.toml
Restart=on-failure

Expand Down
10 changes: 7 additions & 3 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,7 @@ import:
- package: github.com/docker/leadership
- package: github.com/satori/go.uuid
version: ^1.1.0
- package: github.com/coreos/go-systemd
version: v12
subpackages:
- daemon
6 changes: 5 additions & 1 deletion server.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func NewServer(globalConfiguration GlobalConfiguration) *Server {
return server
}

// Start starts the server and blocks until server is shutted down.
// Start starts the server.
func (server *Server) Start() {
server.startHTTPServers()
server.startLeadership()
Expand All @@ -104,6 +104,10 @@ func (server *Server) Start() {
server.configureProviders()
server.startProviders()
go server.listenSignals()
}

// Wait blocks until server is shutted down.
func (server *Server) Wait() {
<-server.stopChan
}

Expand Down
7 changes: 7 additions & 0 deletions traefik.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"github.com/containous/traefik/version"
"github.com/docker/libkv/store"
"github.com/satori/go.uuid"

"github.com/coreos/go-systemd/daemon"
)

var versionTemplate = `Version: {{.Version}}
Expand Down Expand Up @@ -268,6 +270,11 @@ func run(traefikConfiguration *TraefikConfiguration) {
server := NewServer(globalConfiguration)
server.Start()
defer server.Close()
sent, err := daemon.SdNotify("READY=1")
if !sent && err != nil {
log.Error("Fail to notify", err)
}
server.Wait()
log.Info("Shutting down")
}

Expand Down

0 comments on commit 649cb54

Please sign in to comment.