cmd control status + expose DaemonStatus via control API

refs #10
This commit is contained in:
Christian Schwarz
2017-12-24 15:35:12 +01:00
parent 8c7e373049
commit 14b8d69a63
4 changed files with 137 additions and 2 deletions
+7
View File
@@ -39,6 +39,7 @@ func (j *ControlJob) JobStatus(ctx context.Context) (*JobStatus, error) {
const (
ControlJobEndpointProfile string = "/debug/pprof/profile"
ControlJobEndpointVersion string = "/version"
ControlJobEndpointStatus string = "/status"
)
func (j *ControlJob) JobStart(ctx context.Context) {
@@ -46,6 +47,8 @@ func (j *ControlJob) JobStart(ctx context.Context) {
log := ctx.Value(contextKeyLog).(Logger)
defer log.Info("control job finished")
daemon := ctx.Value(contextKeyDaemon).(*Daemon)
l, err := ListenUnixPrivate(j.sockaddr)
if err != nil {
log.WithError(err).Error("error listening")
@@ -58,6 +61,10 @@ func (j *ControlJob) JobStart(ctx context.Context) {
requestLogger{log: log, handler: jsonResponder{func() (interface{}, error) {
return NewZreplVersionInformation(), nil
}}})
mux.Handle(ControlJobEndpointStatus,
requestLogger{log: log, handler: jsonResponder{func() (interface{}, error) {
return daemon.Status(), nil
}}})
server := http.Server{Handler: mux}
outer: