-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfinaliser.go
More file actions
52 lines (41 loc) · 800 Bytes
/
finaliser.go
File metadata and controls
52 lines (41 loc) · 800 Bytes
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
package vc
import (
"os/exec"
"github.com/google/shlex"
)
var (
finaliserNothingCommand = "echo complete!"
finaliserRebootCommand = "vinitctl reboot"
finaliserShutdownCommand = "vinitctl shutdown"
)
func (c Config) Finalise() error {
var (
cmd string
binary string
binaryArgs []string
)
switch c.Finaliser {
case Finaliser_Nothing:
cmd = finaliserNothingCommand
case Finaliser_Reboot:
cmd = finaliserRebootCommand
case Finaliser_Shutdown:
cmd = finaliserShutdownCommand
}
args, err := shlex.Split(cmd)
if err != nil {
return err
}
switch len(args) {
case 0:
return nil
case 1:
binary = args[0]
default:
binary = args[0]
binaryArgs = args[1:]
}
// #nosec: G204
command := exec.Command(binary, binaryArgs...)
return command.Run()
}