mirror of
https://git.numenor-labs.us/dsfx.git
synced 2025-04-29 08:10:34 +00:00
refactor(internal/peer): change DSFX_STORAGE_DIR to DSFX_DATA_DIR
This commit is contained in:
parent
080f3d92d5
commit
c1df1ec84a
@ -46,18 +46,18 @@ go build -o <installation-target> ./cmd/dsfx
|
|||||||
|
|
||||||
DSFX uses the following environment variables to configure its behavior:
|
DSFX uses the following environment variables to configure its behavior:
|
||||||
|
|
||||||
| Variable | Description | Default Value |
|
| Variable | Description | Default Value |
|
||||||
| ---------------- | ----------------------------------------------------------- | ---------------- |
|
| --------------- | ----------------------------------------------------------- | ---------------- |
|
||||||
| DSFX_HOST | The host on which the DSFX server will run | 0.0.0.0 |
|
| DSFX_HOST | The host on which the DSFX server will run | 0.0.0.0 |
|
||||||
| DSFX_PORT | The port on which the DSFX server will listen | 8000 |
|
| DSFX_PORT | The port on which the DSFX server will listen | 8000 |
|
||||||
| DSFX_LOG_LEVEL | The log level to use. One of (error, warn, info, debug) | info |
|
| DSFX_LOG_LEVEL | The log level to use. One of (error, warn, info, debug) | info |
|
||||||
| DSFX_CONFIG_DIR | The directory where the DSFX configuration files are stored | /etc/dsfx/config |
|
| DSFX_DATA_DIR | The directory where the DSFX data files are stored | /etc/dsfx/data |
|
||||||
| DSFX_STORAGE_DIR | The directory where the DSFX storage files are stored | /etc/dsfx/data |
|
| DSFX_CONFIG_DIR | The directory where the DSFX configuration files are stored | /etc/dsfx/config |
|
||||||
|
|
||||||
## Local Files
|
## Local Files
|
||||||
|
|
||||||
The DSFX server uses local files for configuration and storage. The default directories for these
|
The DSFX server uses local files for configuration and storage. The default directories for these
|
||||||
files are specified in the `DSFX_CONFIG_DIR` and `DSFX_STORAGE_DIR` environment variables. You can
|
files are specified in the `DSFX_CONFIG_DIR` and `DSFX_DATA_DIR` environment variables. You can
|
||||||
change these directories by setting the corresponding environment variables before starting the server.
|
change these directories by setting the corresponding environment variables before starting the server.
|
||||||
|
|
||||||
For docker installations, it is recommended to mount the local directories to the container
|
For docker installations, it is recommended to mount the local directories to the container
|
||||||
|
@ -21,22 +21,35 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// DefaultConfigDir is the default directory for the dsfx configuration.
|
// EnvHost is the environment variable for the dsfx host.
|
||||||
DefaultConfigDir = "/etc/dsfx/config"
|
EnvHost = "DSFX_HOST"
|
||||||
// DefaultStorageDir is the default directory for the dsfx storage.
|
// EnvPort is the environment variable for the dsfx port.
|
||||||
DefaultStorageDir = "/etc/dsfx/data"
|
EnvPort = "DSFX_PORT"
|
||||||
|
// EnvLogLevel is the environment variable for the dsfx log level.
|
||||||
|
EnvLogLevel = "DSFX_LOG_LEVEL"
|
||||||
|
// EnvDataDir is the environment variable for the dsfx storage directory.
|
||||||
|
EnvDataDir = "DSFX_DATA_DIR"
|
||||||
|
// EnvConfigDir is the environment variable for the dsfx configuration directory.
|
||||||
|
EnvConfigDir = "DSFX_CONFIG_DIR"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
// DefaultHost is the default host for the dsfxctl application.
|
// DefaultHost is the default host for the dsfxctl application.
|
||||||
DefaultHost = "0.0.0.0"
|
DefaultHost = "0.0.0.0"
|
||||||
// DefaultPort is the default port for the dsfxctl application.
|
// DefaultPort is the default port for the dsfxctl application.
|
||||||
DefaultPort = "8000"
|
DefaultPort = "8000"
|
||||||
|
// DefaultDataDir is the default directory for the dsfx storage.
|
||||||
|
DefaultDataDir = "/etc/dsfx/data"
|
||||||
|
// DefaultConfigDir is the default directory for the dsfx configuration.
|
||||||
|
DefaultConfigDir = "/etc/dsfx/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Conf holds the configuration for the dsfxctl application.
|
// Conf holds the configuration for the dsfxctl application.
|
||||||
type Conf struct {
|
type Conf struct {
|
||||||
LogLevel string
|
LogLevel string
|
||||||
// Directories
|
// Directories
|
||||||
ConfigDir string
|
ConfigDir string
|
||||||
StorageDir string
|
DataDir string
|
||||||
// Networking
|
// Networking
|
||||||
Host string
|
Host string
|
||||||
Port string
|
Port string
|
||||||
@ -61,26 +74,26 @@ func (c Conf) SlogLevel() slog.Level {
|
|||||||
func loadConfigFromSystem(sys system.System) Conf {
|
func loadConfigFromSystem(sys system.System) Conf {
|
||||||
var c Conf
|
var c Conf
|
||||||
|
|
||||||
c.ConfigDir = sys.GetEnv("DSFX_CONFIG_DIR")
|
c.Host = sys.GetEnv(EnvHost)
|
||||||
if c.ConfigDir == "" {
|
if len(c.Host) == 0 {
|
||||||
c.ConfigDir = DefaultConfigDir
|
|
||||||
}
|
|
||||||
|
|
||||||
c.StorageDir = sys.GetEnv("DSFX_STORAGE_DIR")
|
|
||||||
if c.StorageDir == "" {
|
|
||||||
c.StorageDir = DefaultStorageDir
|
|
||||||
}
|
|
||||||
|
|
||||||
c.Host = sys.GetEnv("DSFX_HOST")
|
|
||||||
if c.Host == "" {
|
|
||||||
c.Host = DefaultHost
|
c.Host = DefaultHost
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Port = sys.GetEnv("DSFX_PORT")
|
c.Port = sys.GetEnv(EnvPort)
|
||||||
if c.Port == "" {
|
if len(c.Port) == 0 {
|
||||||
c.Port = DefaultPort
|
c.Port = DefaultPort
|
||||||
}
|
}
|
||||||
|
|
||||||
|
c.ConfigDir = sys.GetEnv(EnvConfigDir)
|
||||||
|
if len(c.ConfigDir) == 0 {
|
||||||
|
c.ConfigDir = DefaultConfigDir
|
||||||
|
}
|
||||||
|
|
||||||
|
c.DataDir = sys.GetEnv(EnvDataDir)
|
||||||
|
if len(c.DataDir) == 0 {
|
||||||
|
c.DataDir = DefaultDataDir
|
||||||
|
}
|
||||||
|
|
||||||
// defaults are handled by Conf.SlogLevel.
|
// defaults are handled by Conf.SlogLevel.
|
||||||
c.LogLevel = sys.GetEnv("DSFX_LOG_LEVEL")
|
c.LogLevel = sys.GetEnv("DSFX_LOG_LEVEL")
|
||||||
|
|
||||||
@ -101,7 +114,7 @@ func New(disk disk.Disk, system system.System) *Peer {
|
|||||||
conf := loadConfigFromSystem(system)
|
conf := loadConfigFromSystem(system)
|
||||||
|
|
||||||
config := scoped.New(disk, conf.ConfigDir)
|
config := scoped.New(disk, conf.ConfigDir)
|
||||||
storage := scoped.New(disk, conf.StorageDir)
|
storage := scoped.New(disk, conf.DataDir)
|
||||||
|
|
||||||
return &Peer{disk, system, config, storage, conf}
|
return &Peer{disk, system, config, storage, conf}
|
||||||
}
|
}
|
||||||
@ -123,7 +136,7 @@ func (p *Peer) Run(ctx context.Context) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = p.disk.MkdirAll(p.conf.StorageDir, 0755)
|
err = p.disk.MkdirAll(p.conf.DataDir, 0755)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.ErrorContext(ctx, "failed to create storage dir", slog.Any("error", err))
|
logger.ErrorContext(ctx, "failed to create storage dir", slog.Any("error", err))
|
||||||
return err
|
return err
|
||||||
|
Loading…
x
Reference in New Issue
Block a user