Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions bridge/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ type Config struct {
RefreshTtl int
RefreshInterval int
DeregisterCheck string
RetryAttempts int
RetryInterval int
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think these are needed any longer.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, you are right

}

type Service struct {
Expand Down
4 changes: 4 additions & 0 deletions docs/user/run.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ Option | Description
------ | -----------
`-internal` | Use exposed ports instead of published ports
`-ip <ip address>` | Force IP address used for registering services
`-retry-attempts` | Max retry attempts to establish a connection with the backend
`-retry-interval` | Interval (in millisecond) between retry-attempts
`-tags <tags>` | Force comma-separated tags on all registered services
`-deregister <mode>` | Deregister existed services "always" or "on-success". Default: always
`-ttl <seconds>` | TTL for services. Default: 0, no expiry (supported backends only)
Expand All @@ -52,6 +54,8 @@ argument.
For registry backends that support TTL expiry, Registrator can both set and
refresh service TTLs with `-ttl` and `-ttl-refresh`.

If you want unlimited retry-attempts use `-retry-attempts -1`.

The `-resync` options controls how often Registrator will query Docker for all
containers and reregister all services. This allows Registrator and the service
registry to get back in sync if they fall out of sync.
Expand Down
25 changes: 24 additions & 1 deletion registrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ var refreshTtl = flag.Int("ttl", 0, "TTL for services (default is no expiry)")
var forceTags = flag.String("tags", "", "Append tags for all registered services")
var resyncInterval = flag.Int("resync", 0, "Frequency with which services are resynchronized")
var deregister = flag.String("deregister", "always", "Deregister exited services \"always\" or \"on-success\"")
var retryAttempts = flag.Int("retry-attempts", 0, "Max retry attempts to establish a connection with the backend. Use -1 for infinite retries")
var retryInterval = flag.Int("retry-interval", 2000, "Interval (in millisecond) between retry-attempts.")

func getopt(name, def string) string {
if env := os.Getenv(name); env != "" {
Expand All @@ -49,12 +51,17 @@ func main() {
if *hostIp != "" {
log.Println("Forcing host IP to", *hostIp)
}

if (*refreshTtl == 0 && *refreshInterval > 0) || (*refreshTtl > 0 && *refreshInterval == 0) {
assert(errors.New("-ttl and -ttl-refresh must be specified together or not at all"))
} else if *refreshTtl > 0 && *refreshTtl <= *refreshInterval {
assert(errors.New("-ttl must be greater than -ttl-refresh"))
}

if *retryInterval <= 0 {
assert(errors.New("-retry-interval must be greater than 0"))
}

docker, err := dockerapi.NewClient(getopt("DOCKER_HOST", "unix:///tmp/docker.sock"))
assert(err)

Expand All @@ -72,7 +79,23 @@ func main() {
})

assert(err)
assert(b.Ping())

attempt := 0
for *retryAttempts == -1 || attempt <= *retryAttempts {
log.Printf("Connecting to backend (%v/%v)", attempt, *retryAttempts)

err = b.Ping()
if err == nil {
break
}

if err != nil && attempt == *retryAttempts {
assert(err)
}

time.Sleep(time.Duration(*retryInterval) * time.Millisecond)
attempt++
}

// Start event listener before listing containers to avoid missing anything
events := make(chan *dockerapi.APIEvents)
Expand Down