mirror of
https://github.com/kopia/kopia.git
synced 2026-06-24 05:58:59 -04:00
feat(server): emit notifications as JSON to stderr when running under KopiaUI (#4322)
* feat(server): emit notifications as JSON to stderr when running under KopiaUI * added tests
This commit is contained in:
@@ -21,6 +21,8 @@
|
||||
|
||||
"github.com/kopia/kopia/internal/auth"
|
||||
"github.com/kopia/kopia/internal/server"
|
||||
"github.com/kopia/kopia/notification"
|
||||
"github.com/kopia/kopia/notification/sender/jsonsender"
|
||||
"github.com/kopia/kopia/repo"
|
||||
)
|
||||
|
||||
@@ -68,7 +70,8 @@ type commandServerStart struct {
|
||||
debugScheduler bool
|
||||
minMaintenanceInterval time.Duration
|
||||
|
||||
shutdownGracePeriod time.Duration
|
||||
shutdownGracePeriod time.Duration
|
||||
kopiauiNotifications bool
|
||||
|
||||
logServerRequests bool
|
||||
|
||||
@@ -123,6 +126,8 @@ func (c *commandServerStart) setup(svc advancedAppServices, parent commandParent
|
||||
|
||||
cmd.Flag("shutdown-grace-period", "Grace period for shutting down the server").Default("5s").DurationVar(&c.shutdownGracePeriod)
|
||||
|
||||
cmd.Flag("kopiaui-notifications", "Enable notifications to be printed to stdout for KopiaUI").BoolVar(&c.kopiauiNotifications)
|
||||
|
||||
c.sf.setup(svc, cmd)
|
||||
c.co.setup(svc, cmd)
|
||||
c.svc = svc
|
||||
@@ -271,6 +276,15 @@ func (c *commandServerStart) run(ctx context.Context) (reterr error) {
|
||||
|
||||
onExternalConfigReloadRequest(srv.Refresh)
|
||||
|
||||
// enable notification to be printed to stderr where KopiaUI will pick it up
|
||||
if c.kopiauiNotifications {
|
||||
notification.AdditionalSenders = append(notification.AdditionalSenders,
|
||||
jsonsender.NewJSONSender(
|
||||
"NOTIFICATION: ",
|
||||
c.out.stderr(),
|
||||
notification.SeverityVerbose))
|
||||
}
|
||||
|
||||
return c.startServerWithOptionalTLS(ctx, httpServer)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user