mirror of
https://gitlab.alpinelinux.org/alpine/cloud/tiny-cloud.git
synced 2025-12-14 10:52:44 +03:00
logging/comment updates
This commit is contained in:
parent
85e9a3bacc
commit
be890f7f16
@ -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() {
|
||||
# <key> [<file>] - line(s) in stdin/<file> have <key> 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 <search> <replace> <list>...
|
||||
replace_word() {
|
||||
local search="$1" replace="$2"
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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}"
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user