mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-01-08 21:30:07 -06:00
71 lines
1.7 KiB
Go
71 lines
1.7 KiB
Go
package command
|
|
|
|
import (
|
|
"context"
|
|
"syscall"
|
|
|
|
"github.com/owncloud/ocis-accounts/pkg/flagset"
|
|
|
|
"github.com/micro/cli/v2"
|
|
"github.com/oklog/run"
|
|
"github.com/owncloud/ocis-accounts/pkg/config"
|
|
"github.com/owncloud/ocis-accounts/pkg/server/grpc"
|
|
svc "github.com/owncloud/ocis-accounts/pkg/service/v0"
|
|
oclog "github.com/owncloud/ocis-pkg/v2/log"
|
|
)
|
|
|
|
var (
|
|
logger oclog.Logger
|
|
)
|
|
|
|
// Server is the entry point for the server command.
|
|
func Server(cfg *config.Config) *cli.Command {
|
|
return &cli.Command{
|
|
Name: "server",
|
|
Usage: "Start ocis accounts service",
|
|
Description: "uses an LDAP server as the storage backend",
|
|
Flags: flagset.ServerWithConfig(cfg),
|
|
Before: func(c *cli.Context) error {
|
|
logger = oclog.NewLogger(
|
|
oclog.Name(cfg.Server.Name),
|
|
oclog.Level("info"),
|
|
oclog.Color(true),
|
|
oclog.Pretty(true),
|
|
)
|
|
return ParseConfig(c, cfg)
|
|
},
|
|
Action: func(c *cli.Context) error {
|
|
gr := run.Group{}
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
service := grpc.NewService(
|
|
grpc.Logger(logger),
|
|
grpc.Context(ctx),
|
|
grpc.Config(cfg),
|
|
grpc.Name(cfg.Server.Name),
|
|
grpc.Namespace(cfg.Server.Namespace),
|
|
grpc.Address(cfg.Server.Address),
|
|
)
|
|
|
|
gr.Add(func() error {
|
|
logger.Info().Str("service", service.Name()).Msg("Reporting settings bundle to account service")
|
|
go svc.RegisterSettingsBundles(&logger)
|
|
return service.Run()
|
|
}, 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")
|
|
}
|
|
cancel()
|
|
})
|
|
|
|
run.SignalHandler(ctx, syscall.SIGKILL)
|
|
return gr.Run()
|
|
},
|
|
}
|
|
}
|