// Run triggered commands first
for _, path := range s.triggers {
for _, x := range s.req.Files[path].TriggerCommands {
- err := s.syncCommand(x, path)
+ err := s.syncCommand(x, "", path)
if err != nil {
return err
}
// Regular commands afterwards so they can react on triggers if
// necessary
for _, x := range s.req.Commands {
- err := s.syncCommand(x.Cmd, "")
+ err := s.syncCommand(x.Cmd, x.OrigGroup, "")
if err != nil {
return err
}
return nil
}
-func (s *Sync) syncCommand(command string, trigger string) error {
+func (s *Sync) syncCommand(command, group, trigger string) error {
s.resp.CommandChanges = append(s.resp.CommandChanges,
safcm.CommandChange{
Command: command,
}
change := &s.resp.CommandChanges[len(s.resp.CommandChanges)-1]
+ var info string
+ if trigger != "" {
+ info = fmt.Sprintf("%q", trigger)
+ } else if group != "" {
+ info = group
+ }
+
cmd := exec.Command("/bin/sh", "-c", command)
cmd.Env = safcmEnviroment(s.req.Groups)
// Cannot use cmd.CombinedOutputCmd() because we need another log
// level (here the command is the actual change and not a side effect)
// and different error handling.
- s.log.Verbosef("commands: running %s", run.QuoteForDebug(cmd))
+ s.log.Verbosef("commands: running %s (%s)",
+ run.QuoteForDebug(cmd), info)
out, err := s.cmd.Runner.CombinedOutput(cmd)
if len(out) > 0 {
s.log.Debug2f("commands: command output:\n%s", out)
},
Commands: []*safcm.Command{
{
+ OrigGroup: "group",
Cmd: "echo; env | grep SAFCM_",
},
},
Env: env,
}},
[]string{
- `3: sync remote: commands: running "/bin/sh" "-c" "echo; env | grep SAFCM_"`,
+ `3: sync remote: commands: running "/bin/sh" "-c" "echo; env | grep SAFCM_" (group)`,
"5: sync remote: commands: command output:\nfake stdout/stderr",
},
safcm.MsgSyncResp{
},
Commands: []*safcm.Command{
{
+ OrigGroup: "group",
Cmd: "echo; env | grep SAFCM_",
},
},
},
Commands: []*safcm.Command{
{
+ OrigGroup: "group",
Cmd: "echo hi; false",
},
},
Env: env,
}},
[]string{
- `3: sync remote: commands: running "/bin/sh" "-c" "echo hi; false"`,
+ `3: sync remote: commands: running "/bin/sh" "-c" "echo hi; false" (group)`,
"5: sync remote: commands: command output:\nfake stdout/stderr",
},
safcm.MsgSyncResp{
},
Commands: []*safcm.Command{
{
+ OrigGroup: "group",
Cmd: "echo hi; false",
},
},
},
Commands: []*safcm.Command{
{
+ OrigGroup: "group1",
Cmd: "echo first",
}, {
+ OrigGroup: "group2",
Cmd: "echo second",
}, {
+ OrigGroup: "group3",
Cmd: "false",
}, {
+ OrigGroup: "group4",
Cmd: "echo third",
},
},
Env: env,
}},
[]string{
- `3: sync remote: commands: running "/bin/sh" "-c" "echo first"`,
+ `3: sync remote: commands: running "/bin/sh" "-c" "echo first" (group1)`,
"5: sync remote: commands: command output:\nfake stdout/stderr first",
- `3: sync remote: commands: running "/bin/sh" "-c" "echo second"`,
+ `3: sync remote: commands: running "/bin/sh" "-c" "echo second" (group2)`,
"5: sync remote: commands: command output:\nfake stdout/stderr second",
- `3: sync remote: commands: running "/bin/sh" "-c" "false"`,
+ `3: sync remote: commands: running "/bin/sh" "-c" "false" (group3)`,
},
safcm.MsgSyncResp{
CommandChanges: []safcm.CommandChange{
},
Commands: []*safcm.Command{
{
+ OrigGroup: "group",
Cmd: "echo; env | grep SAFCM_",
},
},
Env: env,
}},
[]string{
- `3: sync remote: commands: running "/bin/sh" "-c" "echo trigger ."`,
+ `3: sync remote: commands: running "/bin/sh" "-c" "echo trigger ." (".")`,
"5: sync remote: commands: command output:\nfake stdout/stderr .",
- `3: sync remote: commands: running "/bin/sh" "-c" "echo trigger dir"`,
+ `3: sync remote: commands: running "/bin/sh" "-c" "echo trigger dir" ("dir")`,
"5: sync remote: commands: command output:\nfake stdout/stderr dir",
- `3: sync remote: commands: running "/bin/sh" "-c" "echo; env | grep SAFCM_"`,
+ `3: sync remote: commands: running "/bin/sh" "-c" "echo; env | grep SAFCM_" (group)`,
"5: sync remote: commands: command output:\nfake stdout/stderr",
},
safcm.MsgSyncResp{
},
Commands: []*safcm.Command{
{
+ OrigGroup: "group",
Cmd: "echo; env | grep SAFCM_",
},
},
Env: env,
}},
[]string{
- `3: sync remote: commands: running "/bin/sh" "-c" "echo trigger ."`,
+ `3: sync remote: commands: running "/bin/sh" "-c" "echo trigger ." (".")`,
"5: sync remote: commands: command output:\nfake stdout/stderr .",
- `3: sync remote: commands: running "/bin/sh" "-c" "false"`,
+ `3: sync remote: commands: running "/bin/sh" "-c" "false" ("dir")`,
"5: sync remote: commands: command output:\nfake stdout/stderr dir",
},
safcm.MsgSyncResp{