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