Stop delay config

This commit is contained in:
Christopher LaPointe
2023-05-22 21:43:12 -04:00
parent 7d61ef019a
commit 86316b8ab3
3 changed files with 8 additions and 4 deletions

View File

@@ -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"`

View File

@@ -3,5 +3,7 @@ listen: :8080
stopatboot: false
splash: splash.html
stopdelay: 5m
labels:
prefix: lazyloader

View File

@@ -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