1
0
mirror of https://gitlab.alpinelinux.org/alpine/cloud/tiny-cloud.git synced 2026-02-04 04:22:43 +03:00

* switch syslog to local7

* add logging here and there
* add --setup option
* bootstrap_incomplete() shouldn't be allowed as an init action
This commit is contained in:
Jake Buchholz Göktürk 2023-05-02 19:01:47 -07:00
parent c46b12ea04
commit 326e2652ea
3 changed files with 39 additions and 12 deletions

View File

@ -9,7 +9,7 @@
: "${TINY_CLOUD_VAR:=$ROOT/var/lib/cloud}"
log() {
local facility="kern"
local facility="local7"
local stderr
local tag=$(basename "$0")
while [ "${1#-}" != "$1" ]; do

View File

@ -45,7 +45,7 @@ init__expand_root() {
}
init__install_hotplugs() {
local result rc=0
local level result rc=0
[ ! -n "$HOTPLUG_MODULES" ] && return
if [ -f "$LIBDIR/tiny-cloud/$HOTPLUG_TYPE" ]; then
@ -55,11 +55,20 @@ init__install_hotplugs() {
printf ' :' >&2
for module in $HOTPLUG_MODULES; do
result='?'
level='err'
printf "$module" >&2
log info "$phase $ACTION $module"
if type "mod__$module" | grep -q -w "function"; then
"mod__$module" && result='+' || { result='!'; rc=1; }
if "mod__$module"; then
result='+'
level='info'
else
result='!'
rc=1
fi
fi
printf '(%s) ' $result >&2
log "$level" "$phase $ACTION $module ($result)"
done
return $rc
}
@ -128,6 +137,7 @@ init__run_userdata() {
if [ $(userdata_type) != "script" ]; then
printf '(Not Executable) ' >&2
log info "$phase $ACTION - not exectutable"
return
fi

View File

@ -10,18 +10,18 @@ set -e
usage() {
cat <<EOF
Usage: ${0##*/} [-h | --help] { early | main | final | --bootstrap {complete|incomplete} }
Usage: ${0##*/} [-h | --help] { early | main | final | --bootstrap {complete|incomplete} | --setup }
EOF
}
init__bootstrap_complete() {
touch "$TINY_CLOUD_VAR/.bootstrap-complete"
}
init__bootstrap_incomplete() {
bootstrap_incomplete() {
rm -f "$TINY_CLOUD_VAR/.bootstrap-complete"
}
args=$(getopt -o hb: --long help,bootstrap: -n ${0##*/} -- "$@")
args=$(getopt -o hsb: --long help,setup,bootstrap: -n ${0##*/} -- "$@")
if [ $? -ne 0 ] || [ $# -eq 0 ]; then
usage >&2
exit 1
@ -35,11 +35,20 @@ while true; do
complete) # indicate bootstrap is done
init__bootstrap_complete;;
incomplete) # indicate bootstrap isn't done
init__bootstrap_incomplete;;
bootstrap_incomplete
log warn 'bootstrap marked incomplete';;
*) usage >&2; exit 1;;
esac
printf ' bootstrap marked "%s"\n' "$1" >&2
exit 0;;
-s|--setup) # just openrc for now
for phase in -early '' -final; do
rc-update -a del "tiny-cloud$phase" || true
done
rc-update add tiny-cloud-early boot
rc-update add tiny-cloud default
rc-update add tiny-cloud-final default
exit 0;;
--) shift; break;;
*) usage >&2; exit 1;;
esac
@ -57,6 +66,7 @@ esac
# is initial bootstrap already done?
if [ -f "$TINY_CLOUD_VAR/.bootstrap-complete" ]; then
printf ' already bootstrapped\n' >&2
log info "$phase - already bootstrapped"
exit 0;
fi
@ -69,9 +79,7 @@ fi
skip_action() {
local action="$1"
for i in $SKIP_INIT_ACTIONS; do
if [ "$i" = "$action" ]; then
return 0
fi
[ "$i" = "$action" ] && return 0
done
return 1
}
@ -91,13 +99,22 @@ esac
for ACTION in $INIT_ACTIONS; do
if skip_action "$ACTION"; then
printf '\n -- %s : [SKIP]' $ACTION >&2
log warn "$phase - $ACTION - SKIPPED"
continue
fi
printf '\n ++ %s ' $ACTION >&2
log info "$phase - $ACTION - START"
RESULT="UNKNOWN"
LEVEL="err"
if type "init__$ACTION" | grep -q -w "function"; then
"init__$ACTION" "$@" && RESULT="DONE" || RESULT="FAIL"
if "init__$ACTION" "$@"; then
RESULT="DONE"
LEVEL="info"
else
RESULT="FAIL"
fi
fi
printf ': [%s]' $RESULT >&2
log "$LEVEL" "$phase - $ACTION - $RESULT"
done
echo >&2