mirror of
https://gitlab.alpinelinux.org/alpine/cloud/tiny-cloud.git
synced 2025-12-16 11:52:43 +03:00
Install UserData Handlers
Also attempt to tweak some logging... Probably some more refinement with that.
This commit is contained in:
parent
13b0eef9fe
commit
9a00dd686d
6
Makefile
6
Makefile
@ -14,6 +14,10 @@ core:
|
|||||||
lib/tiny-cloud/init \
|
lib/tiny-cloud/init \
|
||||||
lib/tiny-cloud/mdev \
|
lib/tiny-cloud/mdev \
|
||||||
lib/tiny-cloud/tiny-cloud.conf
|
lib/tiny-cloud/tiny-cloud.conf
|
||||||
|
install -Dm644 -t "$(PREFIX)"/lib/tiny-cloud/user-data" \
|
||||||
|
lib/tiny-cloud/user-data/missing \
|
||||||
|
lib/tiny-cloud/user-data/script \
|
||||||
|
lib/tiny-cloud/user-data/unknown
|
||||||
install -Dm644 lib/tiny-cloud/tiny-cloud.conf \
|
install -Dm644 lib/tiny-cloud/tiny-cloud.conf \
|
||||||
"$(PREFIX)"/etc/tiny-cloud.conf
|
"$(PREFIX)"/etc/tiny-cloud.conf
|
||||||
install -Dm755 -t "$(PREFIX)"/sbin \
|
install -Dm755 -t "$(PREFIX)"/sbin \
|
||||||
@ -60,6 +64,8 @@ alpine:
|
|||||||
install -Dm644 -t $(PREFIX)/lib/tiny-cloud/cloud/alpine \
|
install -Dm644 -t $(PREFIX)/lib/tiny-cloud/cloud/alpine \
|
||||||
lib/tiny-cloud/cloud/alpine/init
|
lib/tiny-cloud/cloud/alpine/init
|
||||||
ln -s ../nocloud/imds $(PREFIX)/lib/tiny-cloud/cloud/alpine/imds
|
ln -s ../nocloud/imds $(PREFIX)/lib/tiny-cloud/cloud/alpine/imds
|
||||||
|
install -Dm644 -t "$(PREFIX)"/lib/tiny-cloud/user-data" \
|
||||||
|
lib/tiny-cloud/user-data/alpine-config
|
||||||
|
|
||||||
check: tests/Kyuafile Kyuafile
|
check: tests/Kyuafile Kyuafile
|
||||||
kyua test || (kyua report --verbose && exit 1)
|
kyua test || (kyua report --verbose && exit 1)
|
||||||
|
|||||||
@ -1,6 +1,9 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
# vim:set ts=2 et:
|
# vim:set ts=2 et:
|
||||||
|
|
||||||
|
# NOTE: The mdev-conf APK handles this now, but only for xvd or sd links (not
|
||||||
|
# both)
|
||||||
|
|
||||||
: "${LIBDIR:=$PREFIX/lib}"
|
: "${LIBDIR:=$PREFIX/lib}"
|
||||||
. "$LIBDIR/tiny-cloud/common"
|
. "$LIBDIR/tiny-cloud/common"
|
||||||
|
|
||||||
|
|||||||
@ -10,10 +10,11 @@
|
|||||||
|
|
||||||
log() {
|
log() {
|
||||||
local facility="local7"
|
local facility="local7"
|
||||||
local stderr
|
local stderr init
|
||||||
local tag=$(basename "$0")
|
local tag=$(basename "$0")
|
||||||
while [ "${1#-}" != "$1" ]; do
|
while [ "${1#-}" != "$1" ]; do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
|
-i) init=1 ;; # TODO: value = indent?
|
||||||
-f) facility="$2"; shift ;;
|
-f) facility="$2"; shift ;;
|
||||||
-s) stderr=-s ;;
|
-s) stderr=-s ;;
|
||||||
-t) tag="$tag/$2"; shift ;;
|
-t) tag="$tag/$2"; shift ;;
|
||||||
@ -24,6 +25,7 @@ log() {
|
|||||||
[ -z "$DEBUG" ] && [ "$level" = debug ] && return
|
[ -z "$DEBUG" ] && [ "$level" = debug ] && return
|
||||||
shift
|
shift
|
||||||
|
|
||||||
|
[ -n "$init" ] && echo "$0" >&2
|
||||||
logger $stderr -p "$facility.$level" -t "$tag[$$]" "$@"
|
logger $stderr -p "$facility.$level" -t "$tag[$$]" "$@"
|
||||||
case "$level" in
|
case "$level" in
|
||||||
crit|alert|emerg) exit 1 ;;
|
crit|alert|emerg) exit 1 ;;
|
||||||
|
|||||||
@ -70,21 +70,21 @@ init__install_hotplugs() {
|
|||||||
|
|
||||||
printf ': ' >&2
|
printf ': ' >&2
|
||||||
for module in $HOTPLUG_MODULES; do
|
for module in $HOTPLUG_MODULES; do
|
||||||
result='?'
|
result='unknown'
|
||||||
level='err'
|
level='err'
|
||||||
printf "$module" >&2
|
printf " >> " >&2
|
||||||
log info "$phase $ACTION $module"
|
log -i -t "$phase/$ACTION" info "$module: installing"
|
||||||
if type "mod__$module" | grep -q -w "function"; then
|
if type "mod__$module" | grep -q -w "function"; then
|
||||||
if "mod__$module"; then
|
if "mod__$module"; then
|
||||||
result='+'
|
result='installed'
|
||||||
level='info'
|
level='info'
|
||||||
else
|
else
|
||||||
result='!'
|
result='failed'
|
||||||
rc=1
|
rc=1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
printf '(%s) ' $result >&2
|
printf " >> " >&2
|
||||||
log "$level" "$phase $ACTION $module ($result)"
|
log -i -t "$phase/$ACTION" info "$module: $result"
|
||||||
done
|
done
|
||||||
return $rc
|
return $rc
|
||||||
}
|
}
|
||||||
@ -145,8 +145,7 @@ auto_detect_ethernet_interface() {
|
|||||||
|
|
||||||
init__set_default_interfaces() {
|
init__set_default_interfaces() {
|
||||||
if [ -f "$ROOT"/etc/network/interfaces ]; then
|
if [ -f "$ROOT"/etc/network/interfaces ]; then
|
||||||
echo "already set up" >&2
|
log -i -t "$phase" info "$ACTION: already set up"
|
||||||
log info "$phase $ACTION - already set up"
|
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -171,8 +170,7 @@ init__create_default_user() {
|
|||||||
local user="$CLOUD_USER"
|
local user="$CLOUD_USER"
|
||||||
# don't do anything if it already exists
|
# don't do anything if it already exists
|
||||||
if getent passwd "$user" >/dev/null; then
|
if getent passwd "$user" >/dev/null; then
|
||||||
echo "already exists" >&2
|
log -i -t "$phase" info "$ACTION: already exists"
|
||||||
log info "$phase $ACTION - already exists"
|
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -202,15 +200,13 @@ init__enable_sshd() {
|
|||||||
init__set_hostname() {
|
init__set_hostname() {
|
||||||
local fqdn=$(imds @hostname)
|
local fqdn=$(imds @hostname)
|
||||||
if [ -z "$fqdn" ]; then
|
if [ -z "$fqdn" ]; then
|
||||||
echo "no hostname set" >&2
|
log -i -t "$phase" info "$ACTION: no hostname set"
|
||||||
log info "No hostname set"
|
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local host="${fqdn%%\.*}"
|
local host="${fqdn%%\.*}"
|
||||||
if [ -z "$host" ]; then
|
if [ -z "$host" ]; then
|
||||||
echo "$hostname is not a valid FQDN" >&2
|
log -i -t "$phase" warn "$ACTION: invalid hostname '$fqdn'"
|
||||||
log err "$fqdn is not a valid FQDN"
|
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -224,8 +220,7 @@ init__set_ssh_keys() {
|
|||||||
local user="$CLOUD_USER"
|
local user="$CLOUD_USER"
|
||||||
local pwent="$(getent passwd "$user")"
|
local pwent="$(getent passwd "$user")"
|
||||||
if [ -z "$pwent" ]; then
|
if [ -z "$pwent" ]; then
|
||||||
echo "failed to find $user" >&2
|
log -i -t "$phase" err "$ACTION: failed to find user $user"
|
||||||
log err "Failed to find user $user"
|
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
local group=$(echo "$pwent" | cut -d: -f4)
|
local group=$(echo "$pwent" | cut -d: -f4)
|
||||||
@ -246,7 +241,7 @@ init__set_ssh_keys() {
|
|||||||
init__save_userdata() {
|
init__save_userdata() {
|
||||||
local userdata="$TINY_CLOUD_VAR/user-data"
|
local userdata="$TINY_CLOUD_VAR/user-data"
|
||||||
if [ -f "$userdata" ]; then
|
if [ -f "$userdata" ]; then
|
||||||
log info "user-data already saved"
|
log -i -t "$phase" info "$ACTION: user-data already saved"
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
local tmpfile=$(mktemp "$userdata.XXXXXX")
|
local tmpfile=$(mktemp "$userdata.XXXXXX")
|
||||||
@ -285,7 +280,6 @@ fi
|
|||||||
|
|
||||||
### load user-data type-specific init functions / vars (potentially overriding)
|
### load user-data type-specific init functions / vars (potentially overriding)
|
||||||
|
|
||||||
# this should be non-overrideable, but need this before we...
|
|
||||||
userdata_type() {
|
userdata_type() {
|
||||||
if [ ! -f "$TINY_CLOUD_VAR/user-data" ]; then
|
if [ ! -f "$TINY_CLOUD_VAR/user-data" ]; then
|
||||||
echo missing
|
echo missing
|
||||||
@ -302,5 +296,6 @@ userdata_type() {
|
|||||||
USERDATA_TYPE="$(userdata_type)"
|
USERDATA_TYPE="$(userdata_type)"
|
||||||
if [ -f "$LIBDIR/tiny-cloud/user-data/$USERDATA_TYPE" ]; then
|
if [ -f "$LIBDIR/tiny-cloud/user-data/$USERDATA_TYPE" ]; then
|
||||||
. "$LIBDIR/tiny-cloud/user-data/$USERDATA_TYPE"
|
. "$LIBDIR/tiny-cloud/user-data/$USERDATA_TYPE"
|
||||||
|
else
|
||||||
|
log -i warn "no user-data handler found for '$USERDATA_TYPE'"
|
||||||
fi
|
fi
|
||||||
# TODO: some indication that the user-data type is unsupported?
|
|
||||||
|
|||||||
@ -1,4 +1,8 @@
|
|||||||
# Missing UserData Functions
|
# Missing UserData Functions
|
||||||
# vim:set ts=4 et ft=sh:
|
# vim:set ts=4 et ft=sh:
|
||||||
|
|
||||||
# TODO: what to do if we have NO user-data yet
|
init__missing_userdata() {
|
||||||
|
log -i -t "$phase" notice "$ACTION: no user-data found"
|
||||||
|
}
|
||||||
|
|
||||||
|
INIT_ACTIONS_MAIN="missing_userdata ${INIT_ACTIONS_MAIN}"
|
||||||
|
|||||||
@ -1,4 +1,9 @@
|
|||||||
# Unknown UserData Functions
|
# Unknown UserData Functions
|
||||||
# vim:set ts=4 et ft=sh:
|
# vim:set ts=4 et ft=sh:
|
||||||
|
|
||||||
# TODO: this would probably be mostly NOOPs
|
init__unknown_userdata() {
|
||||||
|
local type="$(userdata_type)"
|
||||||
|
log -i -t "$phase" warn "$ACTION: unable to process '$type' user-data"
|
||||||
|
}
|
||||||
|
|
||||||
|
INIT_ACTIONS_MAIN="unknown_userdata ${INIT_ACTIONS_MAIN}"
|
||||||
|
|||||||
@ -34,13 +34,12 @@ while true; do
|
|||||||
case "$1" in
|
case "$1" in
|
||||||
complete) # indicate bootstrap is done
|
complete) # indicate bootstrap is done
|
||||||
init__bootstrap_complete
|
init__bootstrap_complete
|
||||||
log warn 'bootstrap marked complete';;
|
log -i notice 'bootstrap marked complete';;
|
||||||
incomplete) # indicate bootstrap isn't done
|
incomplete) # indicate bootstrap isn't done
|
||||||
bootstrap_incomplete
|
bootstrap_incomplete
|
||||||
log warn 'bootstrap marked incomplete';;
|
log -i warn 'bootstrap marked incomplete';;
|
||||||
*) usage >&2; exit 1;;
|
*) usage >&2; exit 1;;
|
||||||
esac
|
esac
|
||||||
printf ' bootstrap marked "%s"\n' "$1" >&2
|
|
||||||
exit 0;;
|
exit 0;;
|
||||||
-s|--setup) # just openrc for now
|
-s|--setup) # just openrc for now
|
||||||
for phase in -early -net '' -final; do
|
for phase in -early -net '' -final; do
|
||||||
@ -67,8 +66,7 @@ esac
|
|||||||
|
|
||||||
# is initial bootstrap already done?
|
# is initial bootstrap already done?
|
||||||
if [ -f "$TINY_CLOUD_VAR/.bootstrap-complete" ]; then
|
if [ -f "$TINY_CLOUD_VAR/.bootstrap-complete" ]; then
|
||||||
printf ' already bootstrapped\n' >&2
|
log -i -t "$phase" info "already bootstrapped"
|
||||||
log info "$phase - already bootstrapped"
|
|
||||||
exit 0;
|
exit 0;
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -101,23 +99,23 @@ esac
|
|||||||
|
|
||||||
for ACTION in $INIT_ACTIONS; do
|
for ACTION in $INIT_ACTIONS; do
|
||||||
if skip_action "$ACTION"; then
|
if skip_action "$ACTION"; then
|
||||||
printf '\n -- %s : [SKIP]' $ACTION >&2
|
printf '\n -- ' >&2
|
||||||
log warn "$phase - $ACTION - SKIPPED"
|
log -i -t "$phase" notice "$ACTION: skipped"
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
printf '\n ++ %s ' $ACTION >&2
|
printf '\n ++ ' >&2
|
||||||
log info "$phase - $ACTION - START"
|
log -i -t "$phase" info "$ACTION"
|
||||||
RESULT="UNKNOWN"
|
RESULT="unknown"
|
||||||
LEVEL="err"
|
LEVEL="err"
|
||||||
if type "init__$ACTION" | grep -q -w "function"; then
|
if type "init__$ACTION" | grep -q -w "function"; then
|
||||||
if "init__$ACTION" "$@"; then
|
if "init__$ACTION" "$@"; then
|
||||||
RESULT="DONE"
|
RESULT="done"
|
||||||
LEVEL="info"
|
LEVEL="info"
|
||||||
else
|
else
|
||||||
RESULT="FAIL"
|
RESULT="FAIL"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
printf ': [%s]' $RESULT >&2
|
printf ' ++ ' >&2
|
||||||
log "$LEVEL" "$phase - $ACTION - $RESULT"
|
log -i -t "$phase" "$LEVEL" "$ACTION: $RESULT"
|
||||||
done
|
done
|
||||||
echo >&2
|
echo >&2
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user