MCPcopy Index your code
hub / github.com/bytebase/bytebase / NewServer

Function NewServer

backend/server/server.go:94–253  ·  view source on GitHub ↗

NewServer creates a server.

(ctx context.Context, profile *config.Profile)

Source from the content-addressed store, hash-verified

92
93// NewServer creates a server.
94func NewServer(ctx context.Context, profile *config.Profile) (*Server, error) {
95 s := &Server{
96 profile: profile,
97 startedTS: time.Now().Unix(),
98 }
99
100 // Display config
101 slog.Info("-----Config BEGIN-----")
102 slog.Info(fmt.Sprintf("mode=%s", profile.Mode))
103 slog.Info(fmt.Sprintf("dataDir=%s", profile.DataDir))
104 slog.Info(fmt.Sprintf("replicaID=%s", profile.ReplicaID))
105 slog.Info("-----Config END-------")
106
107 serverStarted := false
108 defer func() {
109 if !serverStarted {
110 _ = s.Shutdown(ctx)
111 }
112 }()
113
114 if profile.HA && profile.UseEmbedDB() {
115 return nil, errors.New("HA mode requires external PostgreSQL (set PG_URL environment variable)")
116 }
117
118 var pgURL string
119 if profile.UseEmbedDB() {
120 pgDataDir := path.Join(profile.DataDir, "pgdata")
121
122 stopper, err := postgres.StartMetadataInstance(ctx, pgDataDir, profile.DatastorePort, profile.Mode)
123 if err != nil {
124 return nil, err
125 }
126 s.stopper = append(s.stopper, stopper)
127 pgURL = fmt.Sprintf("host=%s port=%d user=bb database=bb", common.GetPostgresSocketDir(), profile.DatastorePort)
128 } else {
129 pgURL = profile.PgURL
130 }
131
132 // Connect to the instance that stores bytebase's own metadata.
133 stores, err := store.New(ctx, pgURL, !profile.HA)
134 if err != nil {
135 return nil, errors.Wrapf(err, "failed to new store")
136 }
137
138 if err := migrator.MigrateSchema(ctx, stores.GetDB()); err != nil {
139 stores.Close()
140 return nil, errors.Wrapf(err, "failed to migrate schema")
141 }
142 s.store = stores
143 sheetManager := sheet.NewManager()
144
145 s.licenseService, err = enterprise.NewLicenseService(profile.Mode, stores, profile.SaaS, profile.LicensePrivateKey)
146 if err != nil {
147 return nil, errors.Wrap(err, "failed to create license service")
148 }
149
150 logSetup := &storepb.WorkspaceProfileSetting{
151 EnableAuditLogStdout: false,

Callers 1

startFunction · 0.92

Calls 15

ShutdownMethod · 0.95
StartMetadataInstanceFunction · 0.92
GetPostgresSocketDirFunction · 0.92
NewFunction · 0.92
MigrateSchemaFunction · 0.92
NewManagerFunction · 0.92
NewLicenseServiceFunction · 0.92
NewManagerFunction · 0.92
BBErrorFunction · 0.92
InitGlobalReporterFunction · 0.92

Tested by

no test coverage detected