forked from carimura/cli
-
Notifications
You must be signed in to change notification settings - Fork 1
/
update.go
55 lines (50 loc) · 1.01 KB
/
update.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
45
46
47
48
49
50
51
52
53
54
55
package main
import (
"log"
"os"
"os/exec"
"os/signal"
"syscall"
"github.com/urfave/cli"
)
func updateCmd() cli.Command {
return cli.Command{
Name: "update",
Usage: "pulls latest functions server",
Action: update,
}
}
func update(c *cli.Context) error {
args := []string{"pull",
functionsDockerImage,
}
cmd := exec.Command("docker", args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err := cmd.Start()
if err != nil {
log.Fatalln("starting command failed:", err)
}
done := make(chan error, 1)
go func() {
done <- cmd.Wait()
}()
// catch ctrl-c and kill
sigC := make(chan os.Signal, 2)
signal.Notify(sigC, os.Interrupt, syscall.SIGTERM)
select {
case <-sigC:
log.Println("interrupt caught, exiting")
err = cmd.Process.Kill()
if err != nil {
log.Println("error: could not kill process")
}
case err := <-done:
if err != nil {
log.Println("processed finished with error:", err)
} else {
log.Println("process finished gracefully without error")
}
}
return nil
}