Andrey Smirnov 75b2ce7fd2
feat(init): implement services list API and osctl service CLI (#662)
This returns list of all the services registered, with their current
status, past events, health state, etc.

New CLI is `osctl service [<id>]`: without `<id>` it prints list of all
the services, with specific `<id>` it provides details for a service.

I decided to create "parallel" data structures in protobuf as Go
structures don't map nicely onto what protoc generates: pointers vs.
values, additional fields like mutexes, etc. Probably there's a better
approach, I'm open for it.

For CLI, I tried to keep CLI stuff in `cmd/` package, and I also created
simple wrapper to remove duplicated code which sets up client for each
command.

Examples:

```
$ osctl service
SERVICE      STATE     HEALTH   LAST CHANGE   LAST EVENT
containerd   Running   OK       21s ago       Health check successful
kubeadm      Running   ?        2s ago        Started task kubeadm (PID 280) for container kubeadm
kubelet      Running   ?        0s ago        Started task kubelet (PID 383) for container kubelet
ntpd         Running   ?        14s ago       Started task ntpd (PID 129) for container ntpd
osd          Running   ?        14s ago       Started task osd (PID 126) for container osd
proxyd       Waiting   ?        14s ago       Waiting for conditions
trustd       Running   ?        14s ago       Started task trustd (PID 125) for container trustd
udevd        Running   ?        14s ago       Started task udevd (PID 130) for container udevd
```

```
$ osctl service proxyd
ID       proxyd
STATE    Running
HEALTH   ?
EVENTS   [Preparing]: Running pre state (22s ago)
         [Waiting]: Waiting for conditions (22s ago)
         [Preparing]: Creating service runner (6s ago)
         [Running]: Started task proxyd (PID 461) for container proxyd (6s ago)
```

Signed-off-by: Andrey Smirnov <smirnov.andrey@gmail.com>
2019-05-17 18:01:12 +03:00

58 lines
1.1 KiB
Protocol Buffer

syntax = "proto3";
package proto;
import "google/protobuf/empty.proto";
import "google/protobuf/timestamp.proto";
// The Init service definition.
service Init {
rpc Reboot(google.protobuf.Empty) returns (RebootReply) {}
rpc Shutdown(google.protobuf.Empty) returns (ShutdownReply) {}
rpc Upgrade(UpgradeRequest) returns (UpgradeReply) {}
rpc ServiceList(google.protobuf.Empty) returns (ServiceListReply) {}
}
// The response message containing the reboot status.
message RebootReply {}
// The response message containing the shutdown status.
message ShutdownReply {}
message UpgradeRequest {
string url = 1;
}
message UpgradeReply { string ack = 1; }
message ServiceListReply {
repeated ServiceInfo services = 1;
}
message ServiceInfo {
string id = 1;
string state = 2;
ServiceEvents events = 3;
ServiceHealth health = 4;
}
message ServiceEvents {
repeated ServiceEvent events = 1;
}
message ServiceEvent {
string msg = 1;
string state = 2;
google.protobuf.Timestamp ts = 3;
}
message ServiceHealth {
bool unknown = 1;
bool healthy = 2;
string lastMessage = 3;
google.protobuf.Timestamp lastChange = 4;
}