startup

package
v0.5.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 27, 2026 License: MIT Imports: 14 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package startup encapsulates the pre-server initialisation sequence that is shared between the serve and init commands.

The three-phase design keeps concerns separate:

  • Init is lightweight: directory creation, encryption keyring, root filesystem, and DataConfig load-or-default. Both commands call it.

  • Starter.MigrateMinIO detects and imports existing MinIO data. It is a no-op when no .minio.sys directory is present. Both serve and init call it so that init can report the import to the operator and so that subsequent serve runs see a consistent, authoritative DataConfig.

  • Starter.Prepare is serve-only: it delegates to MigrateMinIO, then persists a freshly-generated DataConfig when no existing or imported config was found, and finally registers the global instance ID. After Prepare returns the Starter's components are ready to hand to server.New.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Starter

type Starter struct {
	// DataDir is the resolved data directory path.
	DataDir string

	// DataConfig is the data configuration.
	// After Init it reflects whatever was on disk, or a fresh in-memory default.
	// After MigrateMinIO (or Prepare) it is authoritative.
	DataConfig *data.ConfigData
	// contains filtered or unexported fields
}

Starter holds the pre-server initialisation state.

func Init

func Init(dataDir string) (*Starter, error)

Init creates a Starter by:

  1. Ensuring the data directory exists (MkdirAll).
  2. Initializing the encryption keyring.
  3. Creating the root filesystem.
  4. Loading DataConfig from .dirio/config.json, or generating a fresh in-memory default (not yet persisted to disk).

Shared between the serve and init commands.

func (*Starter) Close

func (s *Starter) Close() error

Close releases resources acquired by MigrateMinIO or Prepare (specifically the metadata bolt DB). Safe to call when metaMgr is nil. Should be called by the init command after it finishes, or via defer in the serve command for the error paths before server.New takes ownership via TakeMetadataManager.

func (*Starter) HasPendingAsyncImport

func (s *Starter) HasPendingAsyncImport() bool

HasPendingAsyncImport reports whether a Phase 2 MinIO import (groups, service accounts) is waiting to be run.

func (*Starter) IsNew

func (s *Starter) IsNew() bool

IsNew reports whether the DataConfig was freshly created rather than loaded from an existing config.json.

func (*Starter) MetadataManager

func (s *Starter) MetadataManager() *metadata.Manager

MetadataManager returns the metadata manager, or nil if MigrateMinIO found no MinIO data and Prepare has not been called yet.

func (*Starter) MigrateMinIO

func (s *Starter) MigrateMinIO(ctx context.Context) error

MigrateMinIO detects and imports existing MinIO data from .minio.sys.

It is a fast no-op when no .minio.sys directory is present — no metadata manager is created in that case. When MinIO data is found, it:

  1. Creates the metadata manager (stored in the Starter for later use).
  2. Runs CheckAndImportMinIO.
  3. If the import wrote a new .dirio/config.json, reloads DataConfig so the in-memory state reflects the real imported InstanceID and settings.

This is safe to call regardless of whether Init loaded an existing config or created a fresh default — the reload always happens when the import ran, not just when the config was previously absent. This fixes the edge case where "dirio init" creates a config.json before "dirio serve" runs the import, which would otherwise leave DataConfig pointing at the init-created config rather than the MinIO-sourced one.

Both serve (via Prepare) and init call this method.

func (*Starter) Prepare

func (s *Starter) Prepare(ctx context.Context, region, accessKey, secretKey string, credentialsExplicit bool) error

Prepare finalises the Starter for the serve command by:

  1. Running MigrateMinIO (no-op if no .minio.sys is present).
  2. Ensuring the metadata manager exists (creates it if MigrateMinIO skipped because there was no MinIO data).
  3. Persisting a freshly-generated DataConfig (with CLI region/credentials) when neither an existing config nor a MinIO import was found.
  4. Setting the global instance ID.

After Prepare returns, DataConfig is authoritative, MetadataManager is ready to hand to server.New, and the global InstanceID has been set.

func (*Starter) RootFS

func (s *Starter) RootFS() billy.Filesystem

RootFS returns the initialised root filesystem (available after Init).

func (*Starter) RunAsyncImport

func (s *Starter) RunAsyncImport(ctx context.Context)

RunAsyncImport launches Phase 2 of the MinIO import (groups, service accounts) in a background goroutine. It is a no-op when no async work is pending. Must be called after the server is constructed so that the metadata manager is ready to handle writes.

func (*Starter) TakeMetadataManager

func (s *Starter) TakeMetadataManager() *metadata.Manager

TakeMetadataManager transfers ownership of the metadata manager to the caller, leaving the Starter without a reference. After this call Close is a no-op for the metadata manager — the caller is responsible for closing it. Used by the serve command so that server.New can own and close the manager during graceful shutdown without a double-close from defer starter.Close().

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL