Use XDG_STATE_HOME rather than XDG_DATA_HOME for storing bootstrap

This commit is contained in:
Brian Picciano 2024-06-17 14:13:53 +02:00
parent c645a8c767
commit 8a1c8d2ed6
12 changed files with 35 additions and 39 deletions

View File

@ -7,34 +7,30 @@ state AppDir {
note "All relative paths are relative to the root of the AppDir" as N1
state "./AppRun" as AppRun {
AppRun : * Set PATH to APPDIR/bin
}
state "./bin/entrypoint daemon -c ./daemon.yml" as entrypoint {
entrypoint : * Create runtime dir at $_RUNTIME_DIR_PATH
entrypoint : * Create runtime dir
entrypoint : * Lock runtime dir
entrypoint : * Merge given and default daemon.yml files
entrypoint : * Copy bootstrap.json into $_DATA_DIR_PATH, if it's not there
entrypoint : * Copy bootstrap.json into state directory, if it's not there
entrypoint : * Merge daemon.yml config into bootstrap.json
entrypoint : * Create $_RUNTIME_DIR_PATH/dnsmasq.conf
entrypoint : * Create $_RUNTIME_DIR_PATH/nebula.yml
entrypoint : * Create $_RUNTIME_DIR_PATH/garage-N.toml\n (one per storage allocation)
entrypoint : * Run child processes
entrypoint : * (in the background) Updates garage cluster layout
entrypoint : * (in the background) Stores host info in global bucket
entrypoint : * Create $RUNTIME_DIRECTORY/dnsmasq.conf
entrypoint : * Create $RUNTIME_DIRECTORY/nebula.yml
entrypoint : * Create $RUNTIME_DIRECTORY/garage-N.toml\n (one per storage allocation)
entrypoint : * Spawn child processes
entrypoint : * Wait for nebula & garage to initialize
entrypoint : * Updates garage cluster layout
entrypoint : * Stores host info in global bucket, based on latest bootstrap.json
}
init --> AppRun : exec
AppRun --> entrypoint : exec
init --> entrypoint : exec
state "./bin/dnsmasq -d -C $_RUNTIME_DIR_PATH/dnsmasq.conf" as dnsmasq
state "./bin/dnsmasq -d -C $RUNTIME_DIRECTORY/dnsmasq.conf" as dnsmasq
entrypoint --> dnsmasq : child
state "./bin/nebula -config $_RUNTIME_DIR_PATH/nebula.yml" as nebula
state "./bin/nebula -config $RUNTIME_DIRECTORY/nebula.yml" as nebula
entrypoint --> nebula : child
state "./bin/garage -c $_RUNTIME_DIR_PATH/garage-N.toml server" as garage
state "./bin/garage -c $RUNTIME_DIRECTORY/garage-N.toml server" as garage
entrypoint --> garage : child (one per storage allocation)
}

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 9.7 KiB

After

Width:  |  Height:  |  Size: 8.9 KiB

View File

@ -16,9 +16,9 @@ import (
"sort"
)
// DataDirPath returns the path within the user's data directory where the
// StateDirPath returns the path within the user's state directory where the
// bootstrap file is stored.
func DataDirPath(dataDirPath string) string {
func StateDirPath(dataDirPath string) string {
return filepath.Join(dataDirPath, "bootstrap.json")
}

View File

@ -11,17 +11,17 @@ import (
func loadHostBootstrap() (bootstrap.Bootstrap, error) {
dataDirPath := bootstrap.DataDirPath(envDataDirPath)
stateDirPath := bootstrap.StateDirPath(envStateDirPath)
hostBootstrap, err := bootstrap.FromFile(dataDirPath)
hostBootstrap, err := bootstrap.FromFile(stateDirPath)
if errors.Is(err, fs.ErrNotExist) {
return bootstrap.Bootstrap{}, fmt.Errorf(
"%q not found, has the daemon ever been run?",
dataDirPath,
stateDirPath,
)
} else if err != nil {
return bootstrap.Bootstrap{}, fmt.Errorf("loading %q: %w", dataDirPath, err)
return bootstrap.Bootstrap{}, fmt.Errorf("loading %q: %w", stateDirPath, err)
}
return hostBootstrap, nil
@ -29,7 +29,7 @@ func loadHostBootstrap() (bootstrap.Bootstrap, error) {
func writeBootstrapToDataDir(hostBootstrap bootstrap.Bootstrap) error {
path := bootstrap.DataDirPath(envDataDirPath)
path := bootstrap.StateDirPath(envStateDirPath)
dirPath := filepath.Dir(path)
if err := os.MkdirAll(dirPath, 0700); err != nil {

View File

@ -245,7 +245,7 @@ var subCmdDaemon = subCmd{
defer runtimeDirCleanup()
var (
bootstrapDataDirPath = bootstrap.DataDirPath(envDataDirPath)
bootstrapStateDirPath = bootstrap.StateDirPath(envStateDirPath)
bootstrapAppDirPath = bootstrap.AppDirPath(envAppDirPath)
hostBootstrapPath string
@ -277,7 +277,7 @@ var subCmdDaemon = subCmd{
}
switch {
case tryLoadBootstrap(bootstrapDataDirPath):
case tryLoadBootstrap(bootstrapStateDirPath):
case *bootstrapPath != "" && tryLoadBootstrap(*bootstrapPath):
case tryLoadBootstrap(bootstrapAppDirPath):
case err != nil:
@ -286,7 +286,7 @@ var subCmdDaemon = subCmd{
return errors.New("No bootstrap.json file could be found, and one is not provided with --bootstrap-path")
}
if hostBootstrapPath != bootstrapDataDirPath {
if hostBootstrapPath != bootstrapStateDirPath {
// If the bootstrap file is not being stored in the data dir, copy
// it there, so it can be loaded from there next time.

View File

@ -13,7 +13,7 @@ import (
// order to prevent it from doing so.
func initMCConfigDir() (string, error) {
var (
path = filepath.Join(envDataDirPath, "mc")
path = filepath.Join(envStateDirPath, "mc")
sharePath = filepath.Join(path, "share")
configJSONPath = filepath.Join(path, "config.json")
)

View File

@ -28,7 +28,7 @@ func getAppDirPath() string {
var (
envAppDirPath = getAppDirPath()
envRuntimeDirPath = filepath.Join(xdg.RuntimeDir, "isle")
envDataDirPath = filepath.Join(xdg.DataHome, "isle")
envStateDirPath = filepath.Join(xdg.StateHome, "isle")
)
func binPath(name string) string {

View File

@ -9,7 +9,7 @@ source "$UTILS"/with-1-data-1-empty-node-cluster.sh
[ "$(jq -r <admin.json '.CreationParams.Name')" = "testing" ]
[ "$(jq -r <admin.json '.CreationParams.Domain')" = "shared.test" ]
bootstrap_file="$XDG_DATA_HOME/isle/bootstrap.json"
bootstrap_file="$XDG_STATE_HOME/isle/bootstrap.json"
[ "$(jq -rc <"$bootstrap_file" '.AdminCreationParams')" = "$(jq -rc <admin.json '.CreationParams')" ]
[ "$(jq -rc <"$bootstrap_file" '.CAPublicCredentials')" = "$(jq -rc <admin.json '.Nebula.CACredentials.Public')" ]

View File

@ -1,7 +1,7 @@
# shellcheck source=../../utils/with-1-data-1-empty-node-cluster.sh
source "$UTILS"/with-1-data-1-empty-node-cluster.sh
adminBS="$XDG_DATA_HOME"/isle/bootstrap.json
adminBS="$XDG_STATE_HOME"/isle/bootstrap.json
bs="$secondus_bootstrap" # set in with-1-data-1-empty-node-cluster.sh
[ "$(jq -r <"$bs" '.AdminCreationParams')" = "$(jq -r <admin.json '.CreationParams')" ]

View File

@ -48,7 +48,7 @@ echo "tmp dir is $ROOT_TMPDIR"
# Blackhole these directories so that tests don't accidentally use the host's
# real ones.
export XDG_RUNTIME_DIR=/dev/null
export XDG_DATA_HOME=/dev/null
export XDG_STATE_HOME=/dev/null
test_files=$(
find ./cases -type f -name '*.sh' \

View File

@ -4,13 +4,13 @@ base="$1"
TMPDIR="$ROOT_TMPDIR/$base"
XDG_RUNTIME_DIR="$TMPDIR/.run"
XDG_DATA_HOME="$TMPDIR/.data"
XDG_STATE_HOME="$TMPDIR/.state"
mkdir -p "$TMPDIR" "$XDG_RUNTIME_DIR" "$XDG_DATA_HOME"
mkdir -p "$TMPDIR" "$XDG_RUNTIME_DIR" "$XDG_STATE_HOME"
cat <<EOF
export TMPDIR="$TMPDIR"
export XDG_RUNTIME_DIR="$XDG_RUNTIME_DIR"
export XDG_DATA_HOME="$XDG_DATA_HOME"
export XDG_STATE_HOME="$XDG_STATE_HOME"
cd "$TMPDIR"
EOF

View File

@ -2,8 +2,8 @@ set -e
TMPDIR="$TMPDIR/$TEST_CASE_FILE.tmp"
XDG_RUNTIME_DIR="$TMPDIR/.run"
XDG_DATA_HOME="$TMPDIR/.data"
XDG_STATE_HOME="$TMPDIR/.state"
mkdir -p "$TMPDIR" "$XDG_RUNTIME_DIR" "$XDG_DATA_HOME"
mkdir -p "$TMPDIR" "$XDG_RUNTIME_DIR" "$XDG_STATE_HOME"
cd "$TMPDIR"