Take an exclusive lock on DATA_DIR at startup (closes #201) (#220)
Some checks failed
check / check (push) Superseded by a newer commit; never tested
Some checks failed
check / check (push) Superseded by a newer commit; never tested
This commit was merged in pull request #220.
This commit is contained in:
@@ -26,6 +26,10 @@ const (
|
||||
// EnvironmentProd represents production environment.
|
||||
EnvironmentProd = "prod"
|
||||
|
||||
// DefaultDataDir is where all SQLite databases live when DATA_DIR
|
||||
// is unset. The same default applies in every environment.
|
||||
DefaultDataDir = "/var/lib/webhooker"
|
||||
|
||||
// defaultPort is the default HTTP listen port.
|
||||
defaultPort = 8080
|
||||
|
||||
@@ -159,6 +163,19 @@ func envString(key string) string {
|
||||
return os.Getenv(key)
|
||||
}
|
||||
|
||||
// DataDir resolves DATA_DIR, applying DefaultDataDir when it is unset
|
||||
// or empty. It is exported so that entry points which must act on the
|
||||
// data directory before the fx graph exists — taking the exclusive
|
||||
// directory lock, above all — resolve it exactly as Config does.
|
||||
func DataDir() string {
|
||||
dir := envString("DATA_DIR")
|
||||
if dir == "" {
|
||||
return DefaultDataDir
|
||||
}
|
||||
|
||||
return dir
|
||||
}
|
||||
|
||||
// envBool returns the value of the named environment variable
|
||||
// parsed as a boolean. Returns defaultValue if not set. If the
|
||||
// variable is set but cannot be parsed, it returns a wrapped error
|
||||
@@ -461,7 +478,7 @@ func loadFromEnv() (*Config, error) {
|
||||
}
|
||||
|
||||
return &Config{
|
||||
DataDir: envString("DATA_DIR"),
|
||||
DataDir: DataDir(),
|
||||
Debug: debug,
|
||||
MaintenanceMode: maintenanceMode,
|
||||
Environment: environment,
|
||||
@@ -539,14 +556,6 @@ func New(lc fx.Lifecycle, params ConfigParams) (*Config, error) {
|
||||
s.log = log
|
||||
s.params = ¶ms
|
||||
|
||||
// Set default DataDir. All SQLite databases (main application
|
||||
// DB and per-webhook event DBs) live here. The same default is
|
||||
// used regardless of environment; override with DATA_DIR if
|
||||
// needed.
|
||||
if s.DataDir == "" {
|
||||
s.DataDir = "/var/lib/webhooker"
|
||||
}
|
||||
|
||||
if s.Debug {
|
||||
params.Logger.EnableDebugLogging()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user