diff --git a/main.go b/main.go index b110a81..3678c0b 100644 --- a/main.go +++ b/main.go @@ -38,6 +38,10 @@ func main() { } defer core.Close() + if config.Model.StopAtBoot { + core.StopAll() + } + // Set up http server subFs, _ := fs.Sub(httpAssets, "assets") http.Handle(httpAssetPrefix, http.StripPrefix(httpAssetPrefix, http.FileServer(http.FS(subFs)))) diff --git a/pkg/service/service.go b/pkg/service/service.go index 98bb8ec..20b70cd 100644 --- a/pkg/service/service.go +++ b/pkg/service/service.go @@ -94,6 +94,20 @@ func (s *Core) StartHost(hostname string) (*StartResult, error) { }, nil } +func (s *Core) StopAll() { + s.mux.Lock() + defer s.mux.Unlock() + + ctx := context.Background() + + logrus.Info("Stopping all containers...") + for cid, ct := range s.active { + logrus.Infof("Stopping %s...", ct.name) + s.client.ContainerStop(ctx, cid, container.StopOptions{}) + delete(s.active, cid) + } +} + func (s *Core) startContainer(ctx context.Context, ct *types.Container) { s.mux.Lock() defer s.mux.Unlock()