1
0
mirror of https://gitlab.alpinelinux.org/alpine/cloud/tiny-cloud.git synced 2025-12-16 03:42:44 +03:00

testing adjustments

* add bootstrap_complete
* fix _imds_token
* scrap _enforce_ending_newline
* userdata 404s if none is set
* fix save_userdata
* fix is_userdata_script
* ensure existence of log/var dirs
This commit is contained in:
Jake Buchholz Göktürk 2022-01-03 18:12:07 -08:00
parent b5af450a8e
commit 852318c304
11 changed files with 48 additions and 42 deletions

0
etc/init.d/tiny-cloud Normal file → Executable file
View File

0
etc/init.d/tiny-cloud-early Normal file → Executable file
View File

4
etc/init.d/tiny-cloud-final Normal file → Executable file
View File

@ -22,4 +22,8 @@ start() {
run_userdata
eend $?
fi
ebegin "Marking Instance Bootstrap Complete"
bootstrap_complete
eend $?
}

View File

@ -11,8 +11,8 @@ IMDS_SSH_KEYS="meta-data/public-keys"
IMDS_USERDATA="user-data"
_imds_token() {
echo -ne "PUT /latest/api/token HTTP/1.0\r\n"\
"$IMDS_TOKEN_TTL_HEADER: $IMDS_TOKEN_TTL\r\n\r\n" |
echo -ne "PUT /latest/api/token" \
"HTTP/1.0\r\n$IMDS_TOKEN_TTL_HEADER: $IMDS_TOKEN_TTL\r\n\r\n" |
nc 169.254.169.254 80 | tail -n 1
}
@ -26,3 +26,8 @@ imds_ssh_keys() {
imds "$IMDS_SSH_KEYS/${key%=*}/openssh-key"
done | sort -u
}
# ignore 404s from IMDS, if no user-data is set
imds_userdata() {
_imds "$IMDS_USERDATA" || true
}

View File

@ -22,5 +22,5 @@ imds_ssh_keys() {
# decode userdata value
imds_userdata() {
imds "$IMDS_USERDATA" | base64 -d | _enforce_ending_newline
imds "$IMDS_USERDATA" | base64 -d
}

View File

@ -19,6 +19,6 @@ _imds_header() {
imds_ssh_keys() {
for ssh_keys in $IMDS_SSH_KEYS; do
# ignore errors and strip leading '<login>:'
_imds "$ssh_keys" | cut -d: -f2- | _enforce_ending_newline
_imds "$ssh_keys" | cut -d: -f2-
done | sort -u
}

View File

@ -27,19 +27,15 @@ unset -f \
_imds_header \
2>/dev/null || true
# without error reporting or ending newline enforcement
# without error reporting
_imds() {
wget --quiet --header "$(_imds_header)" --output-document - \
"$IMDS_URL/$1/$IMDS_QUERY"
"$IMDS_URL/$1$IMDS_QUERY"
}
_enforce_ending_newline() { sed '$a\'; }
imds() {
set -o pipefail
_imds "$1" | _enforce_ending_newline
_imds "$1"
RV=$?
set +o pipefail
[ $RV != 0 ] && echo "ERROR: $RV" >&2
return $RV
}
@ -48,14 +44,14 @@ imds_hostname() {
imds "$IMDS_HOSTNAME"
}
imds_userdata() {
imds "$IMDS_USERDATA"
}
imds_ssh_keys() {
imds "$IMDS_SSH_KEYS"
}
imds_userdata() {
imds "$IMDS_USERDATA"
}
### load cloud-specific things
if [ ! -d "$TINY_CLOUD_LIBS/$CLOUD" ]; then

View File

@ -7,9 +7,8 @@ CLOUD_USERDATA=${CLOUD_USERDATA:-user-data}
TINY_CLOUD_LOGS=${TINY_CLOUD_LOGS:-/var/log}
TINY_CLOUD_VAR=${TINY_CLOUD_VAR:-/var/lib/cloud}
# ensure existence of output directories
[ ! -d "$TINY_CLOUD_VAR" ] && mkdir -p "$TINY_CLOUD_VAR"
[ ! -d "$TINY_CLOUD_LOGS" ] && mkdir -p "$TINY_CLOUD_LOGS"
# is initial bootstrap already done?
is_bootstrapped() { [ -f "$TINY_CLOUD_VAR"/.bootstrap-complete ]; }
# indicate bootstrap is done
bootstrap_complete() { touch "$TINY_CLOUD_VAR"/.bootstrap-complete ]; }

View File

@ -17,12 +17,10 @@ expand_root() {
)
if [ "$mountpoint" != "$volume" ]; then
partition=$(echo "$volume" | sed -Ee "s/.*(\d+)$/\2/")
einfo "Expanding root partition to volume size..."
partition=$(echo "$mountpoint" | sed -Ee "s/.*(\d+)$/\1/")
echo ", +" | sfdisk -q --no-reread -N "$partition" "$volume"
einfo "Updating kernel with new partition table..."
partx -u "$volume"
fi
einfo "Resizing root filesystem..."
mount -orw,remount /
resize2fs "$mountpoint"
}

View File

@ -11,11 +11,11 @@ source "$TINY_CLOUD_LIBS"/init-common
source "$TINY_CLOUD_LIBS"/imds
save_userdata() {
imds_userdata > "$USERDATA"
imds_userdata > "$TINY_CLOUD_VAR/$CLOUD_USERDATA"
}
is_userdata_script() {
head -n1 "$TINY_CLOUD_VAR/$CLOUD_USERSDATA" | grep -q '%#!/'
head -n1 "$TINY_CLOUD_VAR/$CLOUD_USERDATA" | grep -q '#!/'
}
run_userdata() {

View File

@ -10,6 +10,10 @@ fi
source "$TINY_CLOUD_LIBS"/init-common
source "$TINY_CLOUD_LIBS"/imds
# ensure existence of output directories
[ ! -d "$TINY_CLOUD_LOGS" ] && mkdir -p "$TINY_CLOUD_LOGS"
[ ! -d "$TINY_CLOUD_VAR" ] && mkdir -p "$TINY_CLOUD_VAR"
set_hostname() {
local fqdn=$(imds_hostname)
local host="${fqdn%%\.*}"