Server is the entry point for the server command.
(cfg *config.Config)
| 23 | |
| 24 | // Server is the entry point for the server command. |
| 25 | func Server(cfg *config.Config) *cobra.Command { |
| 26 | return &cobra.Command{ |
| 27 | Use: "server", |
| 28 | Short: fmt.Sprintf("start the %s service without runtime (unsupervised mode)", cfg.Service.Name), |
| 29 | PreRunE: func(cmd *cobra.Command, args []string) error { |
| 30 | return configlog.ReturnFatal(parser.ParseConfig(cfg)) |
| 31 | }, |
| 32 | RunE: func(cmd *cobra.Command, args []string) error { |
| 33 | logger := log.Configure(cfg.Service.Name, cfg.Commons, cfg.LogLevel) |
| 34 | traceProvider, err := tracing.GetTraceProvider(cmd.Context(), cfg.Commons.TracesExporter, cfg.Service.Name) |
| 35 | if err != nil { |
| 36 | return err |
| 37 | } |
| 38 | |
| 39 | // the reva runtime calls os.Exit in the case of a failure and there is no way for the OpenCloud |
| 40 | // runtime to catch it and restart a reva service. Therefore we need to ensure the service has |
| 41 | // everything it needs, before starting the service. |
| 42 | // In this case: CA certificates |
| 43 | if cfg.Driver == "ldap" { |
| 44 | ldapCfg := cfg.Drivers.LDAP |
| 45 | if err := ldap.WaitForCA(logger, ldapCfg.Insecure, ldapCfg.CACert); err != nil { |
| 46 | logger.Error().Err(err).Msg("The configured LDAP CA cert does not exist") |
| 47 | return err |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | var cancel context.CancelFunc |
| 52 | if cfg.Context == nil { |
| 53 | cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) |
| 54 | defer cancel() |
| 55 | } |
| 56 | ctx := cfg.Context |
| 57 | |
| 58 | gr := runner.NewGroup() |
| 59 | |
| 60 | { |
| 61 | // run the appropriate reva servers based on the config |
| 62 | rCfg := revaconfig.UsersConfigFromStruct(cfg) |
| 63 | if rServer := runtime.NewDrivenHTTPServerWithOptions(rCfg, |
| 64 | runtime.WithLogger(&logger.Logger), |
| 65 | runtime.WithRegistry(registry.GetRegistry()), |
| 66 | runtime.WithTraceProvider(traceProvider), |
| 67 | ); rServer != nil { |
| 68 | gr.Add(runner.NewRevaServiceRunner(cfg.Service.Name+".rhttp", rServer)) |
| 69 | } |
| 70 | if rServer := runtime.NewDrivenGRPCServerWithOptions(rCfg, |
| 71 | runtime.WithLogger(&logger.Logger), |
| 72 | runtime.WithRegistry(registry.GetRegistry()), |
| 73 | runtime.WithTraceProvider(traceProvider), |
| 74 | ); rServer != nil { |
| 75 | gr.Add(runner.NewRevaServiceRunner(cfg.Service.Name+".rgrpc", rServer)) |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | { |
| 80 | debugServer, err := debug.Server( |
| 81 | debug.Logger(logger), |
| 82 | debug.Context(ctx), |
no test coverage detected