File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -9,4 +9,5 @@ type Client interface {
99 Scale (string , int ) error
1010 List () error
1111 Status (string ) error
12+ Journal (string ) error
1213}
Original file line number Diff line number Diff line change 1+ package client
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 .getUnits (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 (jobName string ) (exit int ) {
22+
23+ j , err := cAPI .Job (jobName )
24+ if err != nil {
25+ fmt .Fprintf (os .Stderr , "Error retrieving Job %s: %v" , jobName , err )
26+ return 1
27+ }
28+ if j == nil {
29+ fmt .Fprintf (os .Stderr , "Job %s does not exist.\n " , jobName )
30+ return 1
31+ } else if j .UnitState == nil {
32+ fmt .Fprintf (os .Stderr , "Job %s does not appear to be running.\n " , jobName )
33+ return 1
34+ }
35+
36+ command := fmt .Sprintf ("journalctl --unit %s --no-pager -n 40 -f" , jobName )
37+ return runCommand (command , j .UnitState .MachineID )
38+ }
Original file line number Diff line number Diff line change @@ -2,11 +2,12 @@ package cmd
22
33import (
44 "fmt"
5- "github.com/deis/deisctl/client"
6- "github.com/deis/deisctl/utils"
75 "regexp"
86 "strconv"
97 "strings"
8+
9+ "github.com/deis/deisctl/client"
10+ "github.com/deis/deisctl/utils"
1011)
1112
1213func List (c client.Client ) error {
@@ -68,6 +69,16 @@ func Status(c client.Client, targets []string) error {
6869 return nil
6970}
7071
72+ func Journal (c client.Client , targets []string ) error {
73+ for _ , target := range targets {
74+ err := c .Journal (target )
75+ if err != nil {
76+ return err
77+ }
78+ }
79+ return nil
80+ }
81+
7182func Install (c client.Client , targets []string ) error {
7283 // if targets, install all services
7384 if len (targets ) == 0 {
Original file line number Diff line number Diff line change @@ -77,6 +77,7 @@ Example Commands:
7777 deisctl start router@2
7878 deisctl stop router builder
7979 deisctl status controller
80+ deisctl journal controller
8081
8182Options:
8283 --debug print debug information to stderr
@@ -112,6 +113,8 @@ Options:
112113 err = cmd .Stop (c , targets )
113114 case "status" :
114115 err = cmd .Status (c , targets )
116+ case "journal" :
117+ err = cmd .Journal (c , targets )
115118 case "install" :
116119 err = cmd .Install (c , targets )
117120 case "uninstall" :
You can’t perform that action at this time.
0 commit comments