@@ -19,8 +19,9 @@ import (
1919 "context"
2020 "errors"
2121 "fmt"
22- "log/slog "
22+ "regexp "
2323 "slices"
24+ "strconv"
2425 "strings"
2526
2627 "github.com/arduino/go-paths-helper"
@@ -50,12 +51,11 @@ type containerState struct {
5051// For app that have at least 1 dependency, we calculate the overall state
5152// as follow:
5253//
53- // running: all running
54- // stopped: all stopped
55- // failed: at least one failed
56- // stopping: at least one stopping
57- // stopped: at least one stopped
58- // starting: at least one starting
54+ // running: all running
55+ // stopped: all stopped
56+ // failed: at least one failed
57+ // stopping: at least one stopping
58+ // starting: at least one starting
5959func parseAppStatus (containers []container.Summary ) []AppStatusInfo {
6060 apps := make ([]AppStatusInfo , 0 , len (containers ))
6161 appsStatusMap := make (map [string ][]containerState )
@@ -68,12 +68,6 @@ func parseAppStatus(containers []container.Summary) []AppStatusInfo {
6868 Status : StatusFromDockerState (c .State ),
6969 StatusMessage : c .Status ,
7070 })
71- slog .Debug ("Container status" ,
72- slog .String ("appPath" , appPath ),
73- slog .String ("containerID" , c .ID ),
74- slog .String ("state" , string (c .State )),
75- slog .String ("statusMessage" , c .Status ),
76- )
7771 }
7872
7973 appendResult := func (appPath * paths.Path , status Status ) {
@@ -106,7 +100,7 @@ func parseAppStatus(containers []container.Summary) []AppStatusInfo {
106100 continue
107101 }
108102 if slices .ContainsFunc (s , func (v containerState ) bool {
109- return v .Status == StatusStopped && strings . Contains (v .StatusMessage , "Exited (0)" )
103+ return v .Status == StatusStopped && checkExitCode (v .StatusMessage )
110104 }) {
111105 appendResult (appPath , StatusFailed )
112106 continue
@@ -272,3 +266,19 @@ func setStatusLeds(trigger LedTrigger) error {
272266 }
273267 return nil
274268}
269+
270+ func checkExitCode (statusMessage string ) bool {
271+ var exitCodeRegex = regexp .MustCompile (`Exited \((\d+)\)` )
272+
273+ matches := exitCodeRegex .FindStringSubmatch (statusMessage )
274+ if len (matches ) < 2 {
275+ return false
276+ }
277+
278+ exitCode , err := strconv .Atoi (matches [1 ])
279+ if err != nil {
280+ return false
281+ }
282+
283+ return exitCode >= 0 && exitCode < 128
284+ }
0 commit comments