@@ -45,9 +45,9 @@ const (
4545 ServiceStateSuccess = "success"
4646 // ServiceStateError is return when we a service exit with an error (exit code != 0)
4747 ServiceStateError = "error"
48- //ServiceStateFailure is set of zinit can not spawn a service in the first place
49- //due to a missing executable for example. Unlike `error` which is returned if the
50- //service itself exits with an error.
48+ // ServiceStateFailure is set of zinit can not spawn a service in the first place
49+ // due to a missing executable for example. Unlike `error` which is returned if the
50+ // service itself exits with an error.
5151 ServiceStateFailure = "failure"
5252)
5353
@@ -204,7 +204,6 @@ type ServiceStatus struct {
204204func (c * Client ) List () (out map [string ]ServiceState , err error ) {
205205 err = c .cmd ("list" , & out )
206206 return
207-
208207}
209208
210209// Status returns the status of a service
@@ -611,3 +610,36 @@ func (c *Client) Destroy(timeout time.Duration, services ...string) error {
611610
612611 return nil
613612}
613+
614+ // List returns all the service monitored and their status
615+ func (c * Client ) Log (n int ) (out []byte , err error ) {
616+ cmd1 := exec .Command ("zinit" , "log" , "-s" )
617+ cmd2 := exec .Command ("tail" , "-n" , fmt .Sprint (n ))
618+
619+ cmd2 .Stdin , err = cmd1 .StdoutPipe ()
620+ if err != nil {
621+ return
622+ }
623+
624+ err = cmd1 .Start ()
625+ if err != nil {
626+ return
627+ }
628+
629+ output , err := cmd2 .Output ()
630+ if err != nil {
631+ return
632+ }
633+
634+ err = cmd1 .Wait ()
635+ if err != nil {
636+ return
637+ }
638+
639+ return output , err
640+ }
641+
642+ // Restart restarts a service.
643+ func (c * Client ) Restart (service string ) error {
644+ return c .cmd (fmt .Sprintf ("restart %s" , service ), nil )
645+ }
0 commit comments