Files
ocis/pkg/command/server.go
T

61 lines
1.6 KiB
Go
Raw Normal View History

2020-01-30 15:55:40 +01:00
package command
import (
"context"
"syscall"
2020-05-08 19:08:39 +02:00
"github.com/owncloud/ocis-accounts/pkg/flagset"
2020-02-04 10:09:38 +01:00
"github.com/micro/cli/v2"
2020-01-30 15:55:40 +01:00
"github.com/oklog/run"
2020-02-04 10:16:12 +01:00
"github.com/owncloud/ocis-accounts/pkg/config"
2020-04-14 19:37:57 +02:00
"github.com/owncloud/ocis-accounts/pkg/server/grpc"
svc "github.com/owncloud/ocis-accounts/pkg/service/v0"
2020-01-30 15:55:40 +01:00
)
// Server is the entry point for the server command.
2020-02-04 10:16:12 +01:00
func Server(cfg *config.Config) *cli.Command {
2020-02-04 10:09:38 +01:00
return &cli.Command{
2020-02-07 09:54:43 +01:00
Name: "server",
Usage: "Start ocis accounts service",
2020-05-08 19:08:39 +02:00
Description: "uses an LDAP server as the storage backend",
2020-04-22 15:48:09 +02:00
Flags: flagset.ServerWithConfig(cfg),
2020-02-12 14:11:25 +01:00
Before: func(c *cli.Context) error {
return ParseConfig(c, cfg)
2020-02-12 14:11:25 +01:00
},
2020-01-30 15:55:40 +01:00
Action: func(c *cli.Context) error {
logger := NewLogger(cfg)
2020-01-30 15:55:40 +01:00
gr := run.Group{}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
2020-02-04 12:37:23 +01:00
service := grpc.NewService(
2020-02-12 14:11:25 +01:00
grpc.Logger(logger),
2020-02-04 12:37:23 +01:00
grpc.Context(ctx),
grpc.Config(cfg),
2020-02-04 12:42:16 +01:00
grpc.Name(cfg.Server.Name),
grpc.Namespace(cfg.Server.Namespace),
grpc.Address(cfg.Server.Address),
grpc.Flags(flagset.RootWithConfig(config.New())),
2020-02-04 12:37:23 +01:00
)
2020-01-30 15:55:40 +01:00
gr.Add(func() error {
logger.Info().Str("service", service.Name()).Msg("Reporting settings bundle to account service")
2020-04-22 15:51:24 +02:00
go svc.RegisterSettingsBundles(&logger)
2020-01-30 15:55:40 +01:00
return service.Run()
2020-06-18 14:08:41 +02:00
}, func(err error) {
if err != nil {
logger.Error().Err(err).Msg("account service died")
} else {
logger.Info().
Str("service", service.Name()).
Msg("Shutting down server")
}
2020-01-30 15:55:40 +01:00
cancel()
})
run.SignalHandler(ctx, syscall.SIGKILL)
return gr.Run()
},
}
}