MCPcopy
hub / github.com/opencloud-eu/opencloud / Start

Function Start

tests/ocwrapper/opencloud/opencloud.go:30–114  ·  view source on GitHub ↗
(envMap []string)

Source from the content-addressed store, hash-verified

28var EnvConfigs = []string{}
29
30func Start(envMap []string) {
31 // wait for the log scanner to finish
32 var wg sync.WaitGroup
33 wg.Add(2)
34
35 stopSignal = false
36 if retryCount == 0 {
37 defer common.Wg.Done()
38 }
39
40 cmd = exec.Command(config.Get("bin"), "server")
41 if envMap == nil {
42 cmd.Env = append(os.Environ(), EnvConfigs...)
43 } else {
44 cmd.Env = append(os.Environ(), envMap...)
45 }
46
47 logs, err := cmd.StderrPipe()
48 if err != nil {
49 log.Panic(err)
50 }
51 output, err := cmd.StdoutPipe()
52 if err != nil {
53 log.Panic(err)
54 }
55
56 err = cmd.Start()
57 if err != nil {
58 log.Panic(err)
59 }
60
61 logScanner := bufio.NewScanner(logs)
62 outputScanner := bufio.NewScanner(output)
63 outChan := make(chan string)
64
65 // Read the logs when the 'OpenCloud server' command is running
66 go func() {
67 defer wg.Done()
68 for logScanner.Scan() {
69 outChan <- logScanner.Text()
70 }
71 }()
72
73 go func() {
74 defer wg.Done()
75 for outputScanner.Scan() {
76 outChan <- outputScanner.Text()
77 }
78 }()
79
80 // Fetch logs from the channel and print them
81 go func() {
82 for s := range outChan {
83 fmt.Println(s)
84 }
85 }()
86
87 if err := cmd.Wait(); err != nil {

Callers 1

RestartFunction · 0.70

Calls 5

ScanMethod · 0.95
AddMethod · 0.65
GetMethod · 0.65
StartMethod · 0.45

Tested by

no test coverage detected