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 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 { 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 : * Lock runtime dir
entrypoint : * Merge given and default daemon.yml files 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 : * Merge daemon.yml config into bootstrap.json
entrypoint : * Create $_RUNTIME_DIR_PATH/dnsmasq.conf entrypoint : * Create $RUNTIME_DIRECTORY/dnsmasq.conf
entrypoint : * Create $_RUNTIME_DIR_PATH/nebula.yml entrypoint : * Create $RUNTIME_DIRECTORY/nebula.yml
entrypoint : * Create $_RUNTIME_DIR_PATH/garage-N.toml\n (one per storage allocation) entrypoint : * Create $RUNTIME_DIRECTORY/garage-N.toml\n (one per storage allocation)
entrypoint : * Run child processes entrypoint : * Spawn child processes
entrypoint : * (in the background) Updates garage cluster layout entrypoint : * Wait for nebula & garage to initialize
entrypoint : * (in the background) Stores host info in global bucket entrypoint : * Updates garage cluster layout
entrypoint : * Stores host info in global bucket, based on latest bootstrap.json
} }
init --> AppRun : exec init --> entrypoint : exec
AppRun --> 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 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 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) 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" "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. // bootstrap file is stored.
func DataDirPath(dataDirPath string) string { func StateDirPath(dataDirPath string) string {
return filepath.Join(dataDirPath, "bootstrap.json") return filepath.Join(dataDirPath, "bootstrap.json")
} }

View File

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

View File

@ -245,8 +245,8 @@ var subCmdDaemon = subCmd{
defer runtimeDirCleanup() defer runtimeDirCleanup()
var ( var (
bootstrapDataDirPath = bootstrap.DataDirPath(envDataDirPath) bootstrapStateDirPath = bootstrap.StateDirPath(envStateDirPath)
bootstrapAppDirPath = bootstrap.AppDirPath(envAppDirPath) bootstrapAppDirPath = bootstrap.AppDirPath(envAppDirPath)
hostBootstrapPath string hostBootstrapPath string
hostBootstrap bootstrap.Bootstrap hostBootstrap bootstrap.Bootstrap
@ -277,7 +277,7 @@ var subCmdDaemon = subCmd{
} }
switch { switch {
case tryLoadBootstrap(bootstrapDataDirPath): case tryLoadBootstrap(bootstrapStateDirPath):
case *bootstrapPath != "" && tryLoadBootstrap(*bootstrapPath): case *bootstrapPath != "" && tryLoadBootstrap(*bootstrapPath):
case tryLoadBootstrap(bootstrapAppDirPath): case tryLoadBootstrap(bootstrapAppDirPath):
case err != nil: 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") 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 // If the bootstrap file is not being stored in the data dir, copy
// it there, so it can be loaded from there next time. // 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. // order to prevent it from doing so.
func initMCConfigDir() (string, error) { func initMCConfigDir() (string, error) {
var ( var (
path = filepath.Join(envDataDirPath, "mc") path = filepath.Join(envStateDirPath, "mc")
sharePath = filepath.Join(path, "share") sharePath = filepath.Join(path, "share")
configJSONPath = filepath.Join(path, "config.json") configJSONPath = filepath.Join(path, "config.json")
) )

View File

@ -28,7 +28,7 @@ func getAppDirPath() string {
var ( var (
envAppDirPath = getAppDirPath() envAppDirPath = getAppDirPath()
envRuntimeDirPath = filepath.Join(xdg.RuntimeDir, "isle") envRuntimeDirPath = filepath.Join(xdg.RuntimeDir, "isle")
envDataDirPath = filepath.Join(xdg.DataHome, "isle") envStateDirPath = filepath.Join(xdg.StateHome, "isle")
) )
func binPath(name string) string { 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.Name')" = "testing" ]
[ "$(jq -r <admin.json '.CreationParams.Domain')" = "shared.test" ] [ "$(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" '.AdminCreationParams')" = "$(jq -rc <admin.json '.CreationParams')" ]
[ "$(jq -rc <"$bootstrap_file" '.CAPublicCredentials')" = "$(jq -rc <admin.json '.Nebula.CACredentials.Public')" ] [ "$(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 # shellcheck source=../../utils/with-1-data-1-empty-node-cluster.sh
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 bs="$secondus_bootstrap" # set in with-1-data-1-empty-node-cluster.sh
[ "$(jq -r <"$bs" '.AdminCreationParams')" = "$(jq -r <admin.json '.CreationParams')" ] [ "$(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 # Blackhole these directories so that tests don't accidentally use the host's
# real ones. # real ones.
export XDG_RUNTIME_DIR=/dev/null export XDG_RUNTIME_DIR=/dev/null
export XDG_DATA_HOME=/dev/null export XDG_STATE_HOME=/dev/null
test_files=$( test_files=$(
find ./cases -type f -name '*.sh' \ find ./cases -type f -name '*.sh' \

View File

@ -4,13 +4,13 @@ base="$1"
TMPDIR="$ROOT_TMPDIR/$base" TMPDIR="$ROOT_TMPDIR/$base"
XDG_RUNTIME_DIR="$TMPDIR/.run" 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 cat <<EOF
export TMPDIR="$TMPDIR" export TMPDIR="$TMPDIR"
export XDG_RUNTIME_DIR="$XDG_RUNTIME_DIR" export XDG_RUNTIME_DIR="$XDG_RUNTIME_DIR"
export XDG_DATA_HOME="$XDG_DATA_HOME" export XDG_STATE_HOME="$XDG_STATE_HOME"
cd "$TMPDIR" cd "$TMPDIR"
EOF EOF

View File

@ -2,8 +2,8 @@ set -e
TMPDIR="$TMPDIR/$TEST_CASE_FILE.tmp" TMPDIR="$TMPDIR/$TEST_CASE_FILE.tmp"
XDG_RUNTIME_DIR="$TMPDIR/.run" 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" cd "$TMPDIR"