Skip to content

Commit d45ee4f

Browse files
Add pid, namespace, age, health, restarts to services ls (#2782)
## Summary This PR adds additional output to the `devbox services ls` command to see specifically to see the status of the readiness checks. Without the HEALTH information in the output it's impossible to tell if a service is still booting up or if it is fully up and running based on the readiness check. Before: ``` NAME STATUS EXIT CODE failed-server Completed -1 good-server Launching 0 starting-server Launching 0 ``` After: ``` Services running in process-compose: PID NAME NAMESPACE STATUS AGE HEALTH RESTARTS EXIT CODE 19996 good-server default Launching 5s Ready 0 0 19995 starting-server default Launching 5s Not Ready 0 0 19997 failed-server default Completed 2s - 0 -1 ``` ## Additional consideration This PR brings the output of `devbox services ls` closer to that of `process-compose list -o wide`. The output of `process-compose list -o wide` for comparison: ``` PID NAME NAMESPACE STATUS AGE HEALTH RESTARTS EXITCODE 11518 failed-server default Completed 2s - 0 -1 11520 good-server default Launching 3s Ready 0 0 11519 starting-server default Launching 3s Not Ready 0 0 ``` (The only differences I see is the spacing between columns and no space in the title EXITCODE) ## How was it tested? With a sample process-compose.yaml file and running: ``` devbox run build dist/devbox shell devbox services start devbox services ls ``` The sample process-compose.yaml file used for testing. ``` processes: good-server: command: python -m http.server 8081 is_daemon: true readiness_probe: exec: command: curl -f http://localhost:8081 initial_delay_seconds: 1 period_seconds: 1 starting-server: command: python -m http.server 8082 is_daemon: true readiness_probe: exec: command: curl -f http://localhost:8082/wait initial_delay_seconds: 1 period_seconds: 100 failed-server: command: python -m http.server 8083 is_daemon: true readiness_probe: exec: command: curl -f http://localhost:8083/not_there initial_delay_seconds: 1 period_seconds: 1 ``` ## Community Contribution License All community contributions in this pull request are licensed to the project maintainers under the terms of the [Apache 2 License](https://www.apache.org/licenses/LICENSE-2.0). By creating this pull request, I represent that I have the right to license the contributions to the project maintainers under the Apache 2 License as stated in the [Community Contribution License](https://github.com/jetify-com/opensource/blob/main/CONTRIBUTING.md#community-contribution-license).
1 parent fe4678f commit d45ee4f

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

internal/devbox/services.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,9 @@ func (d *Devbox) ListServices(ctx context.Context, runInCurrentShell bool) error
124124
fmt.Fprintln(d.stderr, "Error listing services: ", err)
125125
} else {
126126
fmt.Fprintln(d.stderr, "Services running in process-compose:")
127-
fmt.Fprintln(tw, "NAME\tSTATUS\tEXIT CODE")
127+
fmt.Fprintln(tw, "PID\tNAME\tNAMESPACE\tSTATUS\tAGE\tHEALTH\tRESTARTS\tEXIT CODE")
128128
for _, s := range pcSvcs {
129-
fmt.Fprintf(tw, "%s\t%s\t%d\n", s.Name, s.Status, s.ExitCode)
129+
fmt.Fprintf(tw, "%d\t%s\t%s\t%s\t%s\t%s\t%d\t%d\n", s.PID, s.Name, s.Namespace, s.Status, s.Age, s.Health, s.Restarts, s.ExitCode)
130130
}
131131
tw.Flush()
132132
}

internal/services/client.go

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,22 @@ import (
1010
"fmt"
1111
"io"
1212
"net/http"
13+
"time"
1314

1415
"github.com/f1bonacc1/process-compose/src/types"
1516
)
1617

1718
type processStates = types.ProcessesState
1819

1920
type Process struct {
20-
Name string
21-
Status string
22-
ExitCode int
21+
PID int
22+
Name string
23+
Namespace string
24+
Status string
25+
Age time.Duration
26+
Health string
27+
Restarts int
28+
ExitCode int
2329
}
2430

2531
func StartServices(ctx context.Context, w io.Writer, serviceName, projectDir string) error {
@@ -91,9 +97,14 @@ func ListServices(ctx context.Context, projectDir string, w io.Writer) ([]Proces
9197
}
9298
for _, process := range processes.States {
9399
results = append(results, Process{
94-
Name: process.Name,
95-
Status: process.Status,
96-
ExitCode: process.ExitCode,
100+
PID: process.Pid,
101+
Name: process.Name,
102+
Namespace: process.Namespace,
103+
Status: process.Status,
104+
Age: process.Age.Round(time.Second),
105+
Health: process.Health,
106+
Restarts: process.Restarts,
107+
ExitCode: process.ExitCode,
97108
})
98109
}
99110
return results, nil

0 commit comments

Comments
 (0)