diff --git a/lib/tiny-cloud/common b/lib/tiny-cloud/common index cb15325..b0500a7 100644 --- a/lib/tiny-cloud/common +++ b/lib/tiny-cloud/common @@ -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 diff --git a/lib/tiny-cloud/init b/lib/tiny-cloud/init index 170e14a..cf51e98 100644 --- a/lib/tiny-cloud/init +++ b/lib/tiny-cloud/init @@ -45,21 +45,30 @@ 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 . "$LIBDIR/tiny-cloud/$HOTPLUG_TYPE" fi - printf ':' >&2 + 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 diff --git a/sbin/tiny-cloud b/sbin/tiny-cloud index 6c0c01f..31cf2bc 100755 --- a/sbin/tiny-cloud +++ b/sbin/tiny-cloud @@ -10,18 +10,18 @@ set -e usage() { cat <&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