-
Notifications
You must be signed in to change notification settings - Fork 5
/
stop.go
44 lines (41 loc) · 950 Bytes
/
stop.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package merry
import (
"fmt"
"os"
"path/filepath"
)
func (m *Merry) Stop(isDelete bool) error {
composePath, err := defaultComposePath()
if err != nil {
return err
}
bashCmd := runDockerCompose(composePath, "stop")
if isDelete {
bashCmd = runDockerCompose(composePath, "down", "--volumes")
}
bashCmd.Stdout = os.Stdout
bashCmd.Stderr = os.Stderr
if err := bashCmd.Run(); err != nil {
return err
}
home, err := os.UserHomeDir()
if err != nil {
return fmt.Errorf("failed to get user's home directory: %v", err)
}
if isDelete {
fmt.Println("Removing data from volumes...")
if err := os.RemoveAll(filepath.Join(home, ".merry")); err != nil {
return err
}
if err := m.provisionResourcesToDatadir(filepath.Join(home, ".merry")); err != nil {
return err
}
fmt.Println("Merry has been cleaned up successfully.")
} else {
m.Running = false
m.IsBare = false
m.IsHeadless = false
m.Save()
}
return nil
}