Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // Command is the serve command. Command = &cobra.Command{ Use: "serve", Short: "Start the server", Args: cobra.NoArgs, PersistentPreRunE: cmd.InitBackendContext, PersistentPostRunE: cmd.CloseDBContext, RunE: func(c *cobra.Command, _ []string) error { ctx := c.Context() cfg := config.DefaultConfig() if cfg.Exist() { if err := cfg.ParseFile(); err != nil { return fmt.Errorf("parse config file: %w", err) } } else { if err := cfg.WriteConfig(); err != nil { return fmt.Errorf("write config file: %w", err) } } if err := cfg.ParseEnv(); err != nil { return fmt.Errorf("parse environment variables: %w", err) } customHooksPath := filepath.Join(cfg.DataPath, "hooks") if _, err := os.Stat(customHooksPath); err != nil && os.IsNotExist(err) { os.MkdirAll(customHooksPath, os.ModePerm) hookPath := filepath.Join(customHooksPath, "update.sample") if err := os.WriteFile(hookPath, []byte(updateHookExample), 0o744); err != nil { return fmt.Errorf("failed to generate update hook example: %w", err) } } logPath := filepath.Join(cfg.DataPath, "log") if _, err := os.Stat(logPath); err != nil && os.IsNotExist(err) { os.MkdirAll(logPath, os.ModePerm) } db := db.FromContext(ctx) if err := migrate.Migrate(ctx, db); err != nil { return fmt.Errorf("migration error: %w", err) } s, err := NewServer(ctx) if err != nil { return fmt.Errorf("start server: %w", err) } if syncHooks { be := backend.FromContext(ctx) if err := cmd.InitializeHooks(ctx, cfg, be); err != nil { return fmt.Errorf("initialize hooks: %w", err) } } done := make(chan os.Signal, 1) lch := make(chan error, 1) go func() { defer close(lch) defer close(done) lch <- s.Start() }() signal.Notify(done, os.Interrupt, syscall.SIGINT, syscall.SIGTERM) <-done ctx, cancel := context.WithTimeout(ctx, 30*time.Second) defer cancel() if err := s.Shutdown(ctx); err != nil { return err } return <-lch }, } )
Functions ¶
This section is empty.
Types ¶
type Server ¶
type Server struct { SSHServer *sshsrv.SSHServer GitDaemon *daemon.GitDaemon HTTPServer *web.HTTPServer StatsServer *stats.StatsServer Cron *cron.Scheduler Config *config.Config Backend *backend.Backend DB *db.DB // contains filtered or unexported fields }
Server is the Soft Serve server.
func NewServer ¶
NewServer returns a new *Server configured to serve Soft Serve. The SSH server key-pair will be created if none exists. It expects a context with *backend.Backend, *db.DB, *log.Logger, and *config.Config attached.
Click to show internal directories.
Click to hide internal directories.