package command import ( "context" "fmt" "os" "path/filepath" "syscall" "github.com/micro/cli/v2" "github.com/oklog/run" "github.com/owncloud/ocis-accounts/pkg/config" "github.com/owncloud/ocis-accounts/pkg/micro/grpc" ) // Server is the entry point for the server command. func Server(cfg *config.Config) *cli.Command { baseDir, _ := filepath.Abs(filepath.Dir(os.Args[0])) return &cli.Command{ Name: "server", Usage: "Start accounts service", Flags: []cli.Flag{ &cli.StringFlag{ Name: "manager", DefaultText: "filesystem", Usage: "store controller driver. eg: filesystem", Value: "filesystem", EnvVars: []string{"OCIS_ACCOUNTS_MANAGER"}, Destination: &cfg.Manager, }, &cli.StringFlag{ Name: "mount-path", DefaultText: "binary default running location", Usage: "where to mount the ocis accounts store", Value: baseDir, EnvVars: []string{"OCIS_ACCOUNTS_MOUNT_PATH"}, Destination: &cfg.MountPath, }, }, Action: func(c *cli.Context) error { gr := run.Group{} ctx, cancel := context.WithCancel(context.Background()) defer cancel() service := grpc.NewService(ctx, cfg) gr.Add(func() error { return service.Run() }, func(_ error) { fmt.Println("shutting down grpc server") cancel() }) run.SignalHandler(ctx, syscall.SIGKILL) return gr.Run() }, } }