1
0
mirror of https://gitlab.alpinelinux.org/alpine/cloud/tiny-cloud.git synced 2026-02-04 12:32:45 +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}" : "${TINY_CLOUD_VAR:=$ROOT/var/lib/cloud}"
log() { log() {
local facility="kern" local facility="local7"
local stderr local stderr
local tag=$(basename "$0") local tag=$(basename "$0")
while [ "${1#-}" != "$1" ]; do while [ "${1#-}" != "$1" ]; do

View File

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

View File

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