Skip to content
This repository was archived by the owner on Sep 26, 2025. It is now read-only.

Commit c8fdacd

Browse files
authored
Merge pull request #511 from nhost/fix/no-such-service-hasura
fix: No such service "hasura"
2 parents a68250e + 721fb63 commit c8fdacd

1 file changed

Lines changed: 21 additions & 22 deletions

File tree

nhost/service/manager.go

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package service
22

33
import (
44
"context"
5+
"encoding/json"
56
"fmt"
67
"net/http"
78
"os"
@@ -243,39 +244,37 @@ func (m *dockerComposeManager) Endpoints() *Endpoints {
243244
func (m *dockerComposeManager) Stop(ctx context.Context) error {
244245
m.l.Debug("Stopping docker compose")
245246

246-
// kill all services but postgres
247-
cmd, err := m.dcWrapper.Command(
248-
ctx,
249-
[]string{"kill",
250-
compose.SvcFunctions,
251-
compose.SvcGraphql,
252-
compose.SvcTraefik,
253-
compose.SvcAuth,
254-
compose.SvcMailhog,
255-
compose.SvcMinio,
256-
compose.SvcStorage,
257-
compose.SvcHasura,
258-
}, &compose.DataStreams{})
247+
// check if we have any containers running
248+
cmd, err := m.dcWrapper.Command(ctx, []string{"ps", "--format", "json"}, nil)
259249
if err != nil {
260-
m.l.WithError(err).Debug("Failed to stop functions service")
250+
m.l.WithError(err).Error("Failed to get containers")
261251
return err
262252
}
263253

264-
m.setProcessToStartInItsOwnProcessGroup(cmd)
265-
err = nhost.RunCmdAndCaptureStderrIfNotSetup(cmd)
254+
var containers []any
255+
out, err := cmd.CombinedOutput()
266256
if err != nil {
267-
m.l.WithError(err).Debug("Failed to stop functions service")
257+
m.l.WithError(err).Error("Failed to get containers")
268258
return err
269259
}
270260

271-
cmd, err = m.dcWrapper.Command(ctx, []string{"down", "--remove-orphans"}, nil)
272-
if err != nil {
273-
m.l.WithError(err).Debug("Failed to stop docker compose")
261+
if err := json.Unmarshal(out, &containers); err != nil {
262+
m.l.WithError(err).Error("Failed to get containers")
274263
return err
275264
}
276265

277-
m.setProcessToStartInItsOwnProcessGroup(cmd)
278-
return nhost.RunCmdAndCaptureStderrIfNotSetup(cmd)
266+
if len(containers) > 0 {
267+
cmd, err := m.dcWrapper.Command(ctx, []string{"down", "--remove-orphans"}, nil)
268+
if err != nil {
269+
m.l.WithError(err).Debug("Failed to stop docker compose")
270+
return err
271+
}
272+
273+
m.setProcessToStartInItsOwnProcessGroup(cmd)
274+
return nhost.RunCmdAndCaptureStderrIfNotSetup(cmd)
275+
}
276+
277+
return nil
279278
}
280279

281280
func (m *dockerComposeManager) waitForServicesToBeRunningHealthy(ctx context.Context, ds *compose.DataStreams) error {

0 commit comments

Comments
 (0)