Render valid self-heal working directory and verify units before install
This commit is contained in:
parent
4241954fe1
commit
4850c31335
|
|
@ -10,6 +10,9 @@ The installer records the selected profile, explicit kubeconfig, and current
|
|||
checkout path in the systemd unit. It restarts the webhook so new source and
|
||||
environment settings take effect. Without `--apply`, installation defaults to
|
||||
dry-run mode unless `LAB_SELF_HEAL_APPLY=true` is explicitly supplied.
|
||||
The rendered file is staged with its `.service` filename and checked using
|
||||
`systemd-analyze verify --man=no` on Debian before replacing the installed unit.
|
||||
An invalid rendered unit therefore leaves the existing unit file untouched.
|
||||
|
||||
`HomelabStaleResidualPods`, `KubePodEvicted`, and
|
||||
`KubePodContainerStatusUnknown` select the guarded stale-pod cleanup directly.
|
||||
|
|
|
|||
|
|
@ -3615,6 +3615,7 @@ self_heal() {
|
|||
if [ "${2:-}" = "install-service" ]; then
|
||||
local apply_mode
|
||||
local service_file
|
||||
local service_stage
|
||||
|
||||
apply_mode="${LAB_SELF_HEAL_APPLY:-false}"
|
||||
if [ "${3:-}" = "--apply" ]; then
|
||||
|
|
@ -3628,7 +3629,8 @@ self_heal() {
|
|||
echo "Self-heal kubeconfig is not readable: ${KUBECONFIG}" >&2
|
||||
return 1
|
||||
fi
|
||||
service_file="$(mktemp)"
|
||||
service_stage="$(mktemp -d "${TMPDIR:-/tmp}/jeannie-eventd-unit.XXXXXXXX")"
|
||||
service_file="${service_stage}/jeannie-eventd.service"
|
||||
if ! python3 - "${REPO_ROOT}/infra/jeannie-eventd/jeannie-eventd.service" \
|
||||
"${REPO_ROOT}" "${LAB_CLUSTER_PROFILE}" "${KUBECONFIG}" "${apply_mode}" >"${service_file}" <<'PY'
|
||||
from pathlib import Path
|
||||
|
|
@ -3642,7 +3644,9 @@ def quote_unit(value):
|
|||
return '"' + value.replace("\\", "\\\\").replace('"', '\\"').replace("%", "%%") + '"'
|
||||
|
||||
replacements = {
|
||||
"WorkingDirectory": quote_unit(repo),
|
||||
# WorkingDirectory takes a literal absolute path, unlike the shell-word
|
||||
# parsing used by ExecStart and Environment. Quotes become path characters.
|
||||
"WorkingDirectory": repo.replace("%", "%%"),
|
||||
"ExecStart": quote_unit(repo + "/scripts/jeannie-eventd") + " serve",
|
||||
"Environment=LAB_CLUSTER_PROFILE": quote_unit("LAB_CLUSTER_PROFILE=" + profile),
|
||||
"Environment=KUBECONFIG": quote_unit("KUBECONFIG=" + kubeconfig),
|
||||
|
|
@ -3659,11 +3663,19 @@ for line in Path(template).read_text().splitlines():
|
|||
PY
|
||||
then
|
||||
rm -f "${service_file}"
|
||||
rmdir "${service_stage}"
|
||||
echo "Self-heal service rendering failed; existing service preserved." >&2
|
||||
return 1
|
||||
fi
|
||||
if ! sudo systemd-analyze verify --man=no "${service_file}"; then
|
||||
rm -f "${service_file}"
|
||||
rmdir "${service_stage}"
|
||||
echo "Self-heal unit validation failed; existing service preserved." >&2
|
||||
return 1
|
||||
fi
|
||||
sudo install -m 0644 "${service_file}" /etc/systemd/system/jeannie-eventd.service
|
||||
rm -f "${service_file}"
|
||||
rmdir "${service_stage}"
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl enable jeannie-eventd
|
||||
sudo systemctl restart jeannie-eventd
|
||||
|
|
|
|||
Loading…
Reference in New Issue