github.com/didip/deis@v1.4.1/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 suToGlobal(*u) { 29 fmt.Fprintf(os.Stderr, "Unable to get journal for global unit %s. Check the logs on the host using journalctl.\n", name) 30 return 1 31 } 32 if u == nil { 33 fmt.Fprintf(os.Stderr, "Unit %s does not exist.\n", name) 34 return 1 35 } else if u.CurrentState == "" { 36 fmt.Fprintf(os.Stderr, "Unit %s does not appear to be running.\n", name) 37 return 1 38 } 39 40 command := fmt.Sprintf("journalctl --unit %s --no-pager -n 40 -f", name) 41 return runCommand(command, u.MachineID) 42 }