|
80 | 80 |
|
81 | 81 | --with-systemd Install user-level systemd units (works via curl|bash; |
82 | 82 | units are embedded — no git checkout required). |
| 83 | + Needs a working systemd --user bus for this account. |
| 84 | + Headless/service users: linger + user@UID.service first |
| 85 | + (script fails fast with copy-paste if the bus is missing). |
83 | 86 | --fleet-policy=POLE silent | alert | auto (default auto). Seeds settings.json |
84 | 87 | fleetUpgradePolicy when unset. alert/silent are opt-outs. |
85 | 88 | --skip-upstream-seal Do not wire HAPI_UPSTREAM_SEAL_URL (foundry/break-glass). |
|
96 | 99 | log() { printf '==> %s\n' "$1"; } |
97 | 100 | fail() { printf 'ERROR: %s\n' "$1" >&2; exit 1; } |
98 | 101 |
|
| 102 | +# --with-systemd preflight (#294): talk to the user bus before writing units or |
| 103 | +# calling systemctl --user. Missing bus (service account, no linger, no login |
| 104 | +# session) used to die mid-install on a raw dbus error. Hard-fail with |
| 105 | +# copy-paste for a sudo-capable person; never silently fall back to nohup. |
| 106 | +hapi_pet_user_systemd_bus_ok() { |
| 107 | + command -v systemctl >/dev/null 2>&1 || return 1 |
| 108 | + # show-environment needs a live user bus; is-system-running can be |
| 109 | + # "degraded" while the bus is still usable. |
| 110 | + systemctl --user show-environment >/dev/null 2>&1 |
| 111 | +} |
| 112 | + |
| 113 | +hapi_pet_user_linger_enabled() { |
| 114 | + local user |
| 115 | + user="$(id -un)" |
| 116 | + [[ "$(loginctl show-user "$user" -p Linger --value 2>/dev/null || true)" == "yes" ]] |
| 117 | +} |
| 118 | + |
| 119 | +hapi_pet_require_user_systemd_bus() { |
| 120 | + local user uid |
| 121 | + user="$(id -un)" |
| 122 | + uid="$(id -u)" |
| 123 | + command -v systemctl >/dev/null 2>&1 \ |
| 124 | + || fail "systemctl not found — cannot install --with-systemd on this host" |
| 125 | + |
| 126 | + if hapi_pet_user_systemd_bus_ok; then |
| 127 | + if ! hapi_pet_user_linger_enabled; then |
| 128 | + log "WARN: systemd --user bus is up but linger is off for ${user}." |
| 129 | + log " Units stop when this login ends. For headless pets, a sudo-capable person should run:" |
| 130 | + log " sudo loginctl enable-linger ${user}" |
| 131 | + fi |
| 132 | + return 0 |
| 133 | + fi |
| 134 | + |
| 135 | + fail "$(cat <<EOF |
| 136 | +--with-systemd needs a working systemd --user bus for this account (${user}), |
| 137 | +but none is available (missing \$XDG_RUNTIME_DIR / \$DBUS_SESSION_BUS_ADDRESS, |
| 138 | +or user@${uid}.service is not running). |
| 139 | +
|
| 140 | +A sudo-capable person must prepare the account, then re-run this install |
| 141 | +(the script is idempotent — no need to undo the partial binary/settings work): |
| 142 | +
|
| 143 | + sudo loginctl enable-linger ${user} |
| 144 | + sudo systemctl start user@${uid}.service |
| 145 | +
|
| 146 | +Then re-run the same install command. Do not substitute nohup — you asked |
| 147 | +for systemd persistence (#294). |
| 148 | +EOF |
| 149 | +)" |
| 150 | +} |
| 151 | + |
99 | 152 | case "$HAPI_FLEET_UPGRADE_POLICY" in |
100 | 153 | silent|alert|auto) ;; |
101 | 154 | *) fail "HAPI_FLEET_UPGRADE_POLICY must be silent|alert|auto (got: $HAPI_FLEET_UPGRADE_POLICY)" ;; |
@@ -587,6 +640,9 @@ hapi_pet_migrate_legacy_oauth_if_needed() { |
587 | 640 | # repo checkout. Keep in sync with scripts/tooling/systemd/units/user-pet/*.in — |
588 | 641 | # the checkout path below prefers the companion installer when present. |
589 | 642 | install_user_pet_systemd() { |
| 643 | + # Fail before writing units / any systemctl --user (thinkpadt14 field fail #294). |
| 644 | + hapi_pet_require_user_systemd_bus |
| 645 | + |
590 | 646 | local companion="" |
591 | 647 | if [[ -n "${SCRIPT_DIR}" && -x "${SCRIPT_DIR}/tooling/install-hapi-systemd-units.sh" ]]; then |
592 | 648 | companion="${SCRIPT_DIR}/tooling/install-hapi-systemd-units.sh" |
|
0 commit comments