Use sdnotify for systemd (#768)
* 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()
This commit is contained in:
parent
870f378782
commit
649cb548d0
5 changed files with 24 additions and 4 deletions
|
@ -2,6 +2,7 @@
|
|||
Description=Traefik
|
||||
|
||||
[Service]
|
||||
Type=notify
|
||||
ExecStart=/usr/bin/traefik --configFile=/etc/traefik.toml
|
||||
Restart=on-failure
|
||||
|
||||
|
|
10
glide.lock
generated
10
glide.lock
generated
|
@ -1,5 +1,5 @@
|
|||
hash: 39ff28cc1d13d5915a870b14491ece1849c4eaf5a56cecd50a7676ecee6c6143
|
||||
updated: 2016-10-06T14:06:39.455848971+02:00
|
||||
hash: 61a63d2dd37e5a9bf32c83fa520f54458c3fe6b520f89b9615d8b26f5d3f317f
|
||||
updated: 2016-10-24T15:09:49.3944218+02:00
|
||||
imports:
|
||||
- name: github.com/abbot/go-http-auth
|
||||
version: cb4372376e1e00e9f6ab9ec142e029302c9e7140
|
||||
|
@ -31,6 +31,10 @@ imports:
|
|||
- client
|
||||
- pkg/pathutil
|
||||
- pkg/types
|
||||
- name: github.com/coreos/go-systemd
|
||||
version: 43e4800a6165b4e02bb2a36673c54b230d6f7b26
|
||||
subpackages:
|
||||
- daemon
|
||||
- name: github.com/davecgh/go-spew
|
||||
version: 6d212800a42e8ab5c146b8ace3490ee17e5225f9
|
||||
subpackages:
|
||||
|
@ -340,7 +344,7 @@ testImports:
|
|||
- name: github.com/libkermit/docker-check
|
||||
version: cbe0ef03b3d23070eac4d00ba8828f2cc7f7e5a3
|
||||
- name: github.com/spf13/pflag
|
||||
version: 08b1a584251b5b62f458943640fc8ebd4d50aaa5
|
||||
version: 5644820622454e71517561946e3d94b9f9db6842
|
||||
- name: github.com/vbatts/tar-split
|
||||
version: bd4c5d64c3e9297f410025a3b1bd0c58f659e721
|
||||
subpackages:
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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}}
|
||||
|
@ -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")
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue