github.com/misfo/deis@v1.0.1-0.20141111224634-e0eee0392b8a/deisctl/backend/fleet/journal.go (about) 1 package fleet 2 3 import ( 4 "fmt" 5 "os" 6 ) 7 8 // Journal prints the systemd journal of target unit(s) 9 func (c *FleetClient) Journal(target string) (err error) { 10 units, err := c.Units(target) 11 if err != nil { 12 return 13 } 14 for _, unit := range units { 15 runJournal(unit) 16 } 17 return 18 } 19 20 // runJournal tails the systemd journal for a given unit 21 func runJournal(name string) (exit int) { 22 23 u, err := cAPI.Unit(name) 24 if err != nil { 25 fmt.Fprintf(os.Stderr, "Error retrieving Unit %s: %v", name, err) 26 return 1 27 } 28 if u == nil { 29 fmt.Fprintf(os.Stderr, "Unit %s does not exist.\n", name) 30 return 1 31 } else if u.CurrentState == "" { 32 fmt.Fprintf(os.Stderr, "Unit %s does not appear to be running.\n", name) 33 return 1 34 } 35 36 command := fmt.Sprintf("journalctl --unit %s --no-pager -n 40 -f", name) 37 return runCommand(command, u.MachineID) 38 }