Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions experimental/base-tools/scripts/svc/configure-startup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,26 @@ set -euo pipefail
# Source some common functions and variables
BASE_TOOLS_DIR=${BASE_TOOLS_DIR:-/opt/base-tools}
ROOT_DIR=$BASE_TOOLS_DIR/scripts/svc
STARTUP_SCRIPTS_DIR=${STARTUP_SCRIPTS_DIR:-/usr/start}
source $ROOT_DIR/common.sh
# Setup s6 service for startup.sh
S6_DIR=/etc/s6-overlay/s6-rc.d
mkdir -p "$S6_DIR"
# startup oneshot referencing existing script
mkdir -p "$S6_DIR/startup" "$S6_DIR/startup/dependencies.d"
cp "$ROOT_DIR/handle-startup.sh" "$S6_DIR/startup/handle-startup.sh"
# copy default start up scripts to STARTUP_SCRIPTS_DIR
# these scripts should exit quickly to prevent delaying container startup
mkdir -p "$STARTUP_SCRIPTS_DIR"
chmod +x "$ROOT_DIR/startup/"*
cp -r $ROOT_DIR/startup/* "$STARTUP_SCRIPTS_DIR/"
# Create run first (idempotent overwrite)
cat >"$S6_DIR/startup/run" <<'STARTUP'
#!/usr/bin/env bash
#!/command/with-contenv bash
set -euo pipefail

if [ -n "${SEALOS_DEVBOX_NAME:-}" ]; then
echo "${SEALOS_DEVBOX_NAME}" > /etc/hostname
fi
mkdir -p /usr/start
if [ -n "${SEALOS_DEVBOX_POD_UID:-}" ]; then
echo "${SEALOS_DEVBOX_POD_UID}" > /usr/start/pod_id
fi
SOURCE_DIR=$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")
chmod +x "$SOURCE_DIR/handle-startup.sh"
"$SOURCE_DIR/handle-startup.sh"
STARTUP
echo oneshot >"$S6_DIR/startup/type"
echo '/etc/s6-overlay/s6-rc.d/startup/run' >"$S6_DIR/startup/up"
Expand Down
21 changes: 21 additions & 0 deletions experimental/base-tools/scripts/svc/handle-startup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash
set -euo pipefail

STARTUP_SCRIPTS_DIR=${STARTUP_SCRIPTS_DIR:-/usr/start}

# Exit quietly if the directory is missing or empty
if [ ! -d "$STARTUP_SCRIPTS_DIR" ]; then
exit 0
fi

mapfile -t STARTUP_SCRIPTS < <(find "$STARTUP_SCRIPTS_DIR" -type f -executable -print | sort)

if [ ${#STARTUP_SCRIPTS[@]} -eq 0 ]; then
exit 0
fi

# Run each startup program sequentially in lexical order for deterministic behavior
# IMPORTANT: These programs should exit quickly to avoid delaying container startup
for script in "${STARTUP_SCRIPTS[@]}"; do
"$script"
done
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash
set -euo pipefail
if [ -n "${SEALOS_DEVBOX_NAME:-}" ]; then
echo "${SEALOS_DEVBOX_NAME}" > /etc/hostname
chmod 644 /etc/hostname
fi
7 changes: 7 additions & 0 deletions experimental/base-tools/scripts/svc/startup/01-set-pod-id.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash
set -euo pipefail
mkdir -p /usr/start
if [ -n "${SEALOS_DEVBOX_POD_UID:-}" ]; then
echo "${SEALOS_DEVBOX_POD_UID}" > /usr/start/pod_id
chmod 644 /usr/start/pod_id
fi