From be890f7f169ba2f2c15c0bcaf7e3c57ac6be99ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jake=20Buchholz=20G=C3=B6kt=C3=BCrk?= Date: Sat, 30 Nov 2024 14:31:54 -0800 Subject: [PATCH] logging/comment updates --- lib/tiny-cloud/common | 50 +++++++++++++++++--------------- lib/tiny-cloud/init | 4 +-- lib/tiny-cloud/tiny-cloud.conf | 4 +-- lib/tiny-cloud/user-data/unknown | 2 +- sbin/tiny-cloud | 2 +- 5 files changed, 32 insertions(+), 30 deletions(-) diff --git a/lib/tiny-cloud/common b/lib/tiny-cloud/common index 305636b..d7689c0 100644 --- a/lib/tiny-cloud/common +++ b/lib/tiny-cloud/common @@ -12,6 +12,30 @@ mkdir -p "${TINY_CLOUD_LOGS:=$ROOT/var/log}" mkdir -p "${TINY_CLOUD_VAR:=$ROOT/var/lib/cloud}" +log() { + local facility="local7" + local stderr init + local tag=$(basename "$0") + while [ "${1#-}" != "$1" ]; do + case "$1" in + -i) init=1 ;; + -f) facility="$2"; shift ;; + -s) stderr=-s ;; + -t) tag="$tag/$2"; shift ;; + esac + shift + done + local level="$1" + [ -z "$DEBUG" ] && [ "$level" = debug ] && return + shift + + [ -n "$init" ] && echo "$@" >&2 + logger $stderr -p "$facility.$level" -t "${tag}[$$]" -- "$@" + case "$level" in + crit|alert|emerg) exit 1 ;; + esac +} + lower() { tr 'A-Z' 'a-z'; } line_has_k() { # [] - line(s) in stdin/ have defined? @@ -49,37 +73,15 @@ if [ "$CLOUD" = "auto" ]; then ) fi if [ -z "$CLOUD" ] || [ ! -d "$LIBDIR/tiny-cloud/cloud/$CLOUD" ]; then + log -s -t autodetect err "unable to determine cloud" CLOUD=unknown else + log -s -t autodetect notice "choosing '$CLOUD' cloud" printf "%s\n" "$CLOUD" > "$TINY_CLOUD_VAR"/.autodetect fi } fi -log() { - local facility="local7" - local stderr init - local tag=$(basename "$0") - while [ "${1#-}" != "$1" ]; do - case "$1" in - -i) init=1 ;; - -f) facility="$2"; shift ;; - -s) stderr=-s ;; - -t) tag="$tag/$2"; shift ;; - esac - shift - done - local level="$1" - [ -z "$DEBUG" ] && [ "$level" = debug ] && return - shift - - [ -n "$init" ] && echo "$@" >&2 - logger $stderr -p "$facility.$level" -t "${tag}[$$]" -- "$@" - case "$level" in - crit|alert|emerg) exit 1 ;; - esac -} - # usage: replace_word ... replace_word() { local search="$1" replace="$2" diff --git a/lib/tiny-cloud/init b/lib/tiny-cloud/init index 0590431..3d6eac6 100644 --- a/lib/tiny-cloud/init +++ b/lib/tiny-cloud/init @@ -224,7 +224,7 @@ init__set_hostname() { local host="${fqdn%%\.*}" if [ -z "$host" ]; then - log -i -t "$phase" warn "$ACTION: invalid hostname '$fqdn'" + log -i -t "$phase" warning "$ACTION: invalid hostname '$fqdn'" return 1 fi @@ -268,7 +268,7 @@ init__set_ssh_keys() { ### load cloud-specific init functions / vars (potentially overriding) if [ "$CLOUD" = "alpine" ]; then - log -i -t "$phase" warn "CLOUD provider alpine is deprecated. Use nocloud" + log -i -t "$phase" warning "CLOUD provider alpine is deprecated. Use nocloud" CLOUD="nocloud" fi diff --git a/lib/tiny-cloud/tiny-cloud.conf b/lib/tiny-cloud/tiny-cloud.conf index c1a5996..599c6d5 100644 --- a/lib/tiny-cloud/tiny-cloud.conf +++ b/lib/tiny-cloud/tiny-cloud.conf @@ -1,9 +1,9 @@ # Tiny Cloud configuration # /etc/tiny-cloud.conf -# REQUIRED: The instance's cloud provider +# The instance's cloud provider, defaults to "auto" # valid: aws, azure, gcp, hetzner, incus, nocloud, oci, scaleway -#CLOUD= +#CLOUD=auto # User account where instance SSH keys are installed #CLOUD_USER=alpine diff --git a/lib/tiny-cloud/user-data/unknown b/lib/tiny-cloud/user-data/unknown index f61cb17..c184d57 100644 --- a/lib/tiny-cloud/user-data/unknown +++ b/lib/tiny-cloud/user-data/unknown @@ -4,7 +4,7 @@ init__unknown_userdata() { local type="$(userdata_type)" - log -i -t "$phase" warn "$ACTION: unable to process '$type' user-data" + log -i -t "$phase" warning "$ACTION: unable to process '$type' user-data" } INIT_ACTIONS_MAIN="unknown_userdata ${INIT_ACTIONS_MAIN}" diff --git a/sbin/tiny-cloud b/sbin/tiny-cloud index 3f98afd..251f4b9 100755 --- a/sbin/tiny-cloud +++ b/sbin/tiny-cloud @@ -41,7 +41,7 @@ while true; do log -i notice 'bootstrap marked complete';; incomplete) # indicate bootstrap isn't done bootstrap_incomplete - log -i warn 'bootstrap marked incomplete';; + log -i warning 'bootstrap marked incomplete';; status) is_bootstrap_complete && echo 'complete' || echo 'incomplete' ;; *) usage >&2; exit 1;; esac