mirror of
https://github.com/zix99/traefik-lazyload.git
synced 2025-12-21 13:23:04 +01:00
Stop delay config
This commit is contained in:
@@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
_ "embed"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
@@ -14,6 +15,8 @@ type ConfigModel struct {
|
||||
StopAtBoot bool // Stop existing containers at start of app
|
||||
Splash string // Which splash page to serve
|
||||
|
||||
StopDelay time.Duration // Amount of time to wait before stopping a container
|
||||
|
||||
Labels struct {
|
||||
Prefix string `mapstructure:"prefix"`
|
||||
} `mapstructure:"labels"`
|
||||
|
||||
@@ -3,5 +3,7 @@ listen: :8080
|
||||
stopatboot: false
|
||||
splash: splash.html
|
||||
|
||||
stopdelay: 5m
|
||||
|
||||
labels:
|
||||
prefix: lazyloader
|
||||
7
main.go
7
main.go
@@ -3,7 +3,6 @@ package main
|
||||
import (
|
||||
"context"
|
||||
"embed"
|
||||
_ "embed"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"html/template"
|
||||
@@ -169,7 +168,7 @@ func ContainerHandler(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
ct, _ := findContainerByHostname(r.Context(), host)
|
||||
if ct != nil || true {
|
||||
if ct != nil {
|
||||
// Look to start the container
|
||||
state := getOrCreateState(ct.ID)
|
||||
logrus.Infof("Found container %s for host %s, checking state...", containerShort(ct), host)
|
||||
@@ -214,9 +213,9 @@ func getOrCreateState(cid string) (ret *containerState) {
|
||||
|
||||
func parseContainerSettings(target *containerState, ct *types.Container) {
|
||||
{ // Parse stop delay
|
||||
stopDelay, _ := labelOrDefault(ct, "stopdelay", "10s")
|
||||
stopDelay, _ := labelOrDefault(ct, "stopdelay", Config.StopDelay.String())
|
||||
if dur, stopErr := time.ParseDuration(stopDelay); stopErr != nil {
|
||||
target.StopDelay = 30 * time.Second // TODO: Use config for default
|
||||
target.StopDelay = Config.StopDelay
|
||||
logrus.Warnf("Unable to parse stopdelay of %s, defaulting to %s", stopDelay, target.StopDelay.String())
|
||||
} else {
|
||||
target.StopDelay = dur
|
||||
|
||||
Reference in New Issue
Block a user