Skip to content

Commit 869a483

Browse files
author
lgdd
committed
feat: improved stop command feedback
1 parent 4edf2fe commit 869a483

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

internal/cmd/stop/stop.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
package stop
22

33
import (
4+
"fmt"
45
"os"
56
"os/exec"
67
"runtime"
8+
"time"
79

10+
"github.com/charmbracelet/huh/spinner"
11+
"github.com/lgdd/lfr-cli/internal/conf"
812
"github.com/lgdd/lfr-cli/pkg/util/fileutil"
913
"github.com/lgdd/lfr-cli/pkg/util/logger"
1014

1115
"github.com/lgdd/lfr-cli/pkg/util/procutil"
1216
"github.com/spf13/cobra"
17+
"github.com/spf13/viper"
1318
)
1419

1520
var (
@@ -48,4 +53,52 @@ func run(cmd *cobra.Command, args []string) {
4853
logger.Fatal(err.Error())
4954
}
5055

56+
isRunning, pid, err := procutil.IsCatalinaRunning()
57+
58+
if err != nil {
59+
logger.Fatal(err.Error())
60+
}
61+
62+
if !isRunning {
63+
logger.Print("Liferay is already stopped.")
64+
os.Exit(0)
65+
}
66+
67+
_ = spinner.New().
68+
Title(fmt.Sprintf("Stopping Liferay (pid=%v)", pid)).
69+
Action(checkLiferayStatus).
70+
Accessible(viper.GetBool(conf.OutputAccessible)).
71+
Run()
72+
73+
isRunning, pid, err = procutil.IsCatalinaRunning()
74+
75+
if err != nil {
76+
logger.Fatal(err.Error())
77+
}
78+
79+
if isRunning {
80+
logger.PrintlnWarn("Liferay is still running.")
81+
logger.PrintfWarn("Be patient, but you might need to kill the process (pid=%v).", pid)
82+
} else {
83+
logger.PrintSuccess("Liferay stopped successfully.")
84+
}
85+
}
86+
87+
func checkLiferayStatus() {
88+
isRunning, _, err := procutil.IsCatalinaRunning()
89+
90+
if err != nil {
91+
logger.Fatal(err.Error())
92+
}
93+
94+
maxIterations := 60
95+
iteration := 0
96+
for isRunning && iteration < maxIterations {
97+
iteration = iteration + 1
98+
isRunning, _, err = procutil.IsCatalinaRunning()
99+
if err != nil {
100+
logger.Fatal(err.Error())
101+
}
102+
time.Sleep(1 * time.Second)
103+
}
51104
}

0 commit comments

Comments
 (0)