|
|
@@ -18,10 +18,12 @@ var (
|
|
|
logger = slog.New(slog.NewJSONHandler(os.Stdout, nil))
|
|
|
)
|
|
|
|
|
|
+// receives events via docker.EventBus
|
|
|
+// compares actual state to desired state
|
|
|
func DockerSubscriptionHandler() {
|
|
|
for {
|
|
|
event := <-docker.EventBus
|
|
|
- dockerEvent, ok := event.Data.(events.Message) // assert the type
|
|
|
+ dockerEvent, ok := event.Data.(events.Message)
|
|
|
if !ok {
|
|
|
logger.Error("Failed to assert Docker event data type")
|
|
|
continue
|
|
|
@@ -35,6 +37,10 @@ func DockerSubscriptionHandler() {
|
|
|
if containerState, exists := config.GetContainerState()[contName]; exists {
|
|
|
containerState.ActualStatus = "stopped"
|
|
|
config.UpdateContainerState(contName, containerState)
|
|
|
+ // start it again if this isn't what the user wants
|
|
|
+ if containerState.DesiredStatus != "stopped" {
|
|
|
+ docker.StartContainer(contName, containerState.Type)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
case "start":
|
|
|
@@ -49,6 +55,7 @@ func DockerSubscriptionHandler() {
|
|
|
logger.Info(fmt.Sprintf("Docker: %s died!", contName))
|
|
|
if containerState, exists := config.GetContainerState()[contName]; exists {
|
|
|
containerState.ActualStatus = "died"
|
|
|
+ // we don't want infinite restart loop
|
|
|
containerState.DesiredStatus = "died"
|
|
|
config.UpdateContainerState(contName, containerState)
|
|
|
}
|