Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use sdnotify for systemd #768

Merged
merged 2 commits into from
Oct 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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