func journalAction(c *cli.Context) { if len(c.Args()) != 1 { fmt.Println("One unit file must be provided.") syscall.Exit(1) } jobName := c.Args()[0] js := registryCtl.GetJobState(jobName) if js == nil { fmt.Printf("%s does not appear to be running\n", jobName) syscall.Exit(1) } cmd := fmt.Sprintf("journalctl -u %s --no-pager -l -n %d", jobName, c.Int("lines")) if c.Bool("follow") { cmd += " -f" } // check if the job is running on this machine var channel *ssh.Channel var err error if machine.IsLocalMachineState(js.MachineState) { channel = runLocalCommand(cmd) } else { channel, err = runRemoteCommand(cmd, js.MachineState.PublicIP) if err != nil { log.Fatalf("Unable to run command over SSH: %v", err) } } readSSHChannel(channel) }
// runCommand will attempt to run a command on a given machine. It will attempt // to SSH to the machine if it is identified as being remote. func runCommand(cmd string, ms *machine.MachineState) (retcode int) { var err error if machine.IsLocalMachineState(ms) { err, retcode = runLocalCommand(cmd) if err != nil { fmt.Printf("Error running local command: %v\n", err) } } else { err, retcode = runRemoteCommand(cmd, ms.PublicIP) if err != nil { fmt.Printf("Error running remote command: %v\n", err) } } return }