diff --git a/internal/docker/client.go b/internal/docker/client.go index a276f610..f502ec57 100644 --- a/internal/docker/client.go +++ b/internal/docker/client.go @@ -37,12 +37,14 @@ var ( clientMapMu sync.RWMutex ) +var initClientCleanerOnce sync.Once + const ( cleanInterval = 10 * time.Second clientTTLSecs = int64(10) ) -func init() { +func initClientCleaner() { cleaner := task.RootTask("docker_clients_cleaner") go func() { ticker := time.NewTicker(cleanInterval) @@ -115,6 +117,8 @@ func (c *SharedClient) Close() { // - Client: the Docker client connection. // - error: an error if the connection failed. func NewClient(host string) (*SharedClient, error) { + initClientCleanerOnce.Do(initClientCleaner) + clientMapMu.Lock() defer clientMapMu.Unlock() diff --git a/internal/docker/idlewatcher/container.go b/internal/docker/idlewatcher/container.go index a0245fe6..1d8fbd0c 100644 --- a/internal/docker/idlewatcher/container.go +++ b/internal/docker/idlewatcher/container.go @@ -18,33 +18,41 @@ type ( } ) +func (w *Watcher) ContainerID() string { + return w.route.ContainerInfo().ContainerID +} + +func (w *Watcher) ContainerName() string { + return w.route.ContainerInfo().ContainerName +} + func (w *Watcher) containerStop(ctx context.Context) error { - return w.client.ContainerStop(ctx, w.ContainerID, container.StopOptions{ - Signal: string(w.StopSignal), - Timeout: &w.StopTimeout, + return w.client.ContainerStop(ctx, w.ContainerID(), container.StopOptions{ + Signal: string(w.Config().StopSignal), + Timeout: &w.Config().StopTimeout, }) } func (w *Watcher) containerPause(ctx context.Context) error { - return w.client.ContainerPause(ctx, w.ContainerID) + return w.client.ContainerPause(ctx, w.ContainerID()) } func (w *Watcher) containerKill(ctx context.Context) error { - return w.client.ContainerKill(ctx, w.ContainerID, string(w.StopSignal)) + return w.client.ContainerKill(ctx, w.ContainerID(), string(w.Config().StopSignal)) } func (w *Watcher) containerUnpause(ctx context.Context) error { - return w.client.ContainerUnpause(ctx, w.ContainerID) + return w.client.ContainerUnpause(ctx, w.ContainerID()) } func (w *Watcher) containerStart(ctx context.Context) error { - return w.client.ContainerStart(ctx, w.ContainerID, container.StartOptions{}) + return w.client.ContainerStart(ctx, w.ContainerID(), container.StartOptions{}) } func (w *Watcher) containerStatus() (string, error) { ctx, cancel := context.WithTimeoutCause(w.task.Context(), dockerReqTimeout, errors.New("docker request timeout")) defer cancel() - json, err := w.client.ContainerInspect(ctx, w.ContainerID) + json, err := w.client.ContainerInspect(ctx, w.ContainerID()) if err != nil { return "", err } diff --git a/internal/docker/idlewatcher/html/loading_page.html b/internal/docker/idlewatcher/html/loading_page.html index 405d23b6..0d655677 100644 --- a/internal/docker/idlewatcher/html/loading_page.html +++ b/internal/docker/idlewatcher/html/loading_page.html @@ -1,88 +1,139 @@ - + -
- - -