summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrett Holman <bholman.devel@gmail.com>2022-03-14 15:52:16 +0100
committerGitHub <noreply@github.com>2022-03-14 09:52:16 -0500
commitee5e128a5c783d600f00ff4d1201ca898695ac02 (patch)
tree07191b93e8af0d85cf9475fbd5526ffb3bf760a2
parentf7a8880751b71a9f043aa8cd91e307334e0c11a6 (diff)
downloadcloud-init-git-ee5e128a5c783d600f00ff4d1201ca898695ac02.tar.gz
Remove redundant generator logs (#1318)
Summary: - currently we log redundant data, which at a glance looks like ds-identify runs twice - use return code for control flow rather than strings - group templated code and add demarcation comments around it - explicitly define generator log file
-rw-r--r--systemd/cloud-init-generator.tmpl39
1 files changed, 18 insertions, 21 deletions
diff --git a/systemd/cloud-init-generator.tmpl b/systemd/cloud-init-generator.tmpl
index 74d47428..db964825 100644
--- a/systemd/cloud-init-generator.tmpl
+++ b/systemd/cloud-init-generator.tmpl
@@ -5,28 +5,35 @@ set -f
LOG=""
DEBUG_LEVEL=1
LOG_D="/run/cloud-init"
+LOG_F="/run/cloud-init/cloud-init-generator.log"
ENABLE="enabled"
DISABLE="disabled"
-FOUND="found"
-NOTFOUND="notfound"
RUN_ENABLED_FILE="$LOG_D/$ENABLE"
+CLOUD_TARGET_NAME="cloud-init.target"
+# lxc sets 'container', but lets make that explicitly a global
+CONTAINER="${container}"
+
+# start: template section
{% if variant in ["suse"] %}
CLOUD_SYSTEM_TARGET="/usr/lib/systemd/system/cloud-init.target"
{% else %}
CLOUD_SYSTEM_TARGET="/lib/systemd/system/cloud-init.target"
{% endif %}
-CLOUD_TARGET_NAME="cloud-init.target"
-# lxc sets 'container', but lets make that explicitly a global
-CONTAINER="${container}"
+{% if variant in ["almalinux", "centos", "cloudlinux", "eurolinux", "fedora",
+ "miraclelinux", "openEuler", "rhel", "rocky", "virtuozzo"] %}
+ dsidentify="/usr/libexec/cloud-init/ds-identify"
+{% else %}
+ dsidentify="/usr/lib/cloud-init/ds-identify"
+{% endif %}
+# end: template section
debug() {
local lvl="$1"
shift
[ "$lvl" -gt "$DEBUG_LEVEL" ] && return
if [ -z "$LOG" ]; then
- local log="$LOG_D/${0##*/}.log"
{ [ -d "$LOG_D" ] || mkdir -p "$LOG_D"; } &&
- { : > "$log"; } >/dev/null 2>&1 && LOG="$log" ||
+ { : > "$LOG_F"; } >/dev/null 2>&1 && LOG="$LOG_F" ||
LOG="/dev/kmsg"
fi
echo "$@" >> "$LOG"
@@ -83,26 +90,16 @@ default() {
check_for_datasource() {
local ds_rc=""
-{% if variant in ["almalinux", "centos", "cloudlinux", "eurolinux", "fedora",
- "miraclelinux", "openEuler", "rhel", "rocky", "virtuozzo"] %}
- local dsidentify="/usr/libexec/cloud-init/ds-identify"
-{% else %}
- local dsidentify="/usr/lib/cloud-init/ds-identify"
-{% endif %}
if [ ! -x "$dsidentify" ]; then
- debug 1 "no ds-identify in $dsidentify. _RET=$FOUND"
+ debug 1 "no ds-identify in $dsidentify"
return 0
fi
$dsidentify
ds_rc=$?
debug 1 "ds-identify rc=$ds_rc"
if [ "$ds_rc" = "0" ]; then
- _RET="$FOUND"
- debug 1 "ds-identify _RET=$_RET"
return 0
fi
- _RET="$NOTFOUND"
- debug 1 "ds-identify _RET=$_RET"
return 1
}
@@ -110,7 +107,7 @@ main() {
local normal_d="$1" early_d="$2" late_d="$3"
local target_name="multi-user.target" gen_d="$early_d"
local link_path="$gen_d/${target_name}.wants/${CLOUD_TARGET_NAME}"
- local ds="$NOTFOUND"
+ local ds=""
debug 1 "$0 normal=$normal_d early=$early_d late=$late_d"
debug 2 "$0 $*"
@@ -133,8 +130,8 @@ main() {
if [ "$result" = "$ENABLE" ]; then
debug 1 "checking for datasource"
check_for_datasource
- ds=$_RET
- if [ "$ds" = "$NOTFOUND" ]; then
+ ds=$?
+ if [ "$ds" = "1" ]; then
debug 1 "cloud-init is enabled but no datasource found, disabling"
result="$DISABLE"
fi