MCPcopy
hub / github.com/benbjohnson/litestream / Run

Method Run

cmd/litestream/replicate.go:178–390  ·  view source on GitHub ↗

Run loads all databases specified in the configuration.

(ctx context.Context)

Source from the content-addressed store, hash-verified

176
177// Run loads all databases specified in the configuration.
178func (c *ReplicateCommand) Run(ctx context.Context) (err error) {
179 // Display version information.
180 slog.Info("litestream", "version", Version, "level", c.Config.Logging.Level)
181
182 // Start MCP server if enabled
183 if c.Config.MCPAddr != "" {
184 c.MCP, err = NewMCP(ctx, c.Config.ConfigPath)
185 if err != nil {
186 return err
187 }
188 go c.MCP.Start(c.Config.MCPAddr)
189 }
190
191 // Setup databases.
192 if len(c.Config.DBs) == 0 {
193 slog.Error("no databases specified in configuration")
194 }
195
196 // Attempt restore for databases that need it (before creating DB objects)
197 for _, dbConfig := range c.Config.DBs {
198 if dbConfig.RestoreIfDBNotExists && dbConfig.Path != "" {
199 if err := c.restoreIfNeeded(ctx, dbConfig); err != nil {
200 return err
201 }
202 }
203 }
204
205 var dbs []*litestream.DB
206 var watchables []struct {
207 config *DBConfig
208 dbs []*litestream.DB
209 }
210 for _, dbConfig := range c.Config.DBs {
211 // Handle directory configuration
212 if dbConfig.Dir != "" {
213 dirDbs, err := NewDBsFromDirectoryConfig(dbConfig)
214 if err != nil {
215 return err
216 }
217 dbs = append(dbs, dirDbs...)
218 slog.Info("found databases in directory", "dir", dbConfig.Dir, "count", len(dirDbs), "watch", dbConfig.Watch)
219 if dbConfig.Watch {
220 watchables = append(watchables, struct {
221 config *DBConfig
222 dbs []*litestream.DB
223 }{config: dbConfig, dbs: dirDbs})
224 }
225 } else {
226 // Handle single database configuration
227 db, err := NewDBFromConfig(dbConfig)
228 if err != nil {
229 return err
230 }
231 dbs = append(dbs, db)
232 }
233 }
234
235 levels := c.Config.CompactionLevels()

Callers 2

ExecuteMethod · 0.95
RunMethod · 0.95

Calls 15

restoreIfNeededMethod · 0.95
runOnceMethod · 0.95
NewStoreFunction · 0.92
NewHeartbeatClientFunction · 0.92
NewServerFunction · 0.92
NewMCPFunction · 0.85
NewDBFromConfigFunction · 0.85
NewDirectoryMonitorFunction · 0.85
CompactionLevelsMethod · 0.80
SetL0RetentionMethod · 0.80

Tested by

no test coverage detected