Skip to content

Commit

Permalink
fix(cmd/gpud): clean up "gpud down" logs (#41)
Browse files Browse the repository at this point in the history
Signed-off-by: Gyuho Lee <[email protected]>
  • Loading branch information
gyuho authored Aug 28, 2024
1 parent 6ae8377 commit 183b0fe
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions cmd/gpud/command/down.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import (
"fmt"
"os"

"github.com/urfave/cli"

"github.com/leptonai/gpud/pkg/systemd"
pkgupdate "github.com/leptonai/gpud/pkg/update"

"github.com/urfave/cli"
)

func cmdDown(cliContext *cli.Context) error {
Expand All @@ -16,16 +17,26 @@ func cmdDown(cliContext *cli.Context) error {
}
if err := pkgupdate.RequireRoot(); err != nil {
fmt.Printf("%s %q requires root to stop gpud (if not run by systemd, manually kill the process with 'pidof gpud')\n", warningSign, bin)
return err
os.Exit(1)
}
if err := pkgupdate.SystemctlExists(); err != nil {
fmt.Printf("%s requires systemd: %v (if not run by systemd, manually kill the process with 'pidof gpud')\n", warningSign, err)
return err
os.Exit(1)
}

active, err := systemd.IsActive("gpud.service")
if err != nil {
fmt.Printf("%s failed to check if gpud is running: %v\n", warningSign, err)
os.Exit(1)
}
if !active {
fmt.Printf("%s gpud is not running (no-op)\n", checkMark)
os.Exit(0)
}

if err := pkgupdate.StopSystemdUnit(); err != nil {
fmt.Printf("%s failed to stop systemd unit 'gpud.service': %v\n", warningSign, err)
return err
os.Exit(1)
}

fmt.Printf("%s successfully stopped gpud\n", checkMark)
Expand Down

0 comments on commit 183b0fe

Please sign in to comment.