installer: track real dashboard pid
This commit is contained in:
3 files changed
+40
-23
No files matched your search
@@ -47,13 +47,25 @@ cd /root
|
||||
# noisy installer stream is captured to the support log.
|
||||
dashboard_tty=$(tty)
|
||||
export OMARCHY_DASHBOARD_TTY="$dashboard_tty"
|
||||
rm -f /run/omarchy-install/dashboard.stop
|
||||
rm -f /run/omarchy-install/dashboard.stop /run/omarchy-install/dashboard.pid
|
||||
setsid /usr/local/bin/omarchy-install-dashboard "$OMARCHY_INSTALL_LOG_FILE" /run/omarchy-install/state.json <"$dashboard_tty" >"$dashboard_tty" 2>&1 &
|
||||
dashboard_pid=$!
|
||||
# setsid may fork/exec differently across environments. The dashboard writes
|
||||
# its own real PID as soon as it starts; prefer that for shutdown.
|
||||
for _ in {1..20}; do
|
||||
[[ -s /run/omarchy-install/dashboard.pid ]] && break
|
||||
sleep 0.05
|
||||
done
|
||||
if [[ -s /run/omarchy-install/dashboard.pid ]]; then
|
||||
dashboard_pid=$(cat /run/omarchy-install/dashboard.pid)
|
||||
fi
|
||||
export OMARCHY_INSTALL_DASHBOARD_PID="$dashboard_pid"
|
||||
|
||||
stop_install_dashboard() {
|
||||
touch /run/omarchy-install/dashboard.stop 2>/dev/null || true
|
||||
if [[ -s /run/omarchy-install/dashboard.pid ]]; then
|
||||
dashboard_pid=$(cat /run/omarchy-install/dashboard.pid)
|
||||
fi
|
||||
if [[ -n ${dashboard_pid:-} ]]; then
|
||||
if kill -0 "$dashboard_pid" 2>/dev/null; then
|
||||
# The dashboard runs under setsid, so $dashboard_pid is also its process
|
||||
|
||||
@@ -8,6 +8,7 @@ LOG_FILE="${1:-/var/log/omarchy-install.log}"
|
||||
STATE_FILE="${2:-/run/omarchy-install/state.json}"
|
||||
STATE_DIR="$(dirname "$STATE_FILE")"
|
||||
STOP_FILE="$STATE_DIR/dashboard.stop"
|
||||
PID_FILE="$STATE_DIR/dashboard.pid"
|
||||
LOGO_PATH="${OMARCHY_PATH:-/usr/share/omarchy}/logo.txt"
|
||||
TTY_PATH="${OMARCHY_DASHBOARD_TTY:-/dev/tty}"
|
||||
|
||||
@@ -45,6 +46,7 @@ whimsy=(
|
||||
|
||||
cleanup() {
|
||||
printf '%s%s' "$RESET" "$SHOW_CURSOR" >"$TTY_PATH" 2>/dev/null || true
|
||||
rm -f "$PID_FILE" 2>/dev/null || true
|
||||
}
|
||||
trap cleanup EXIT
|
||||
trap 'cleanup; exit 0' INT TERM
|
||||
@@ -237,6 +239,9 @@ if [[ ! -e $TTY_PATH ]]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
mkdir -p "$STATE_DIR"
|
||||
echo "$$" >"$PID_FILE"
|
||||
|
||||
printf '%s' "$HIDE_CURSOR" >"$TTY_PATH"
|
||||
render_static >"$TTY_PATH"
|
||||
frame=0
|
||||
|
||||
@@ -1071,34 +1071,34 @@ def _pid_is_dashboard(pid: int) -> bool:
|
||||
return b"omarchy-install-dashboard" in cmdline
|
||||
|
||||
|
||||
def _add_dashboard_pid(pids: list[int], pid_text: str | None) -> None:
|
||||
if not pid_text:
|
||||
return
|
||||
try:
|
||||
pid = int(pid_text.strip())
|
||||
except ValueError:
|
||||
return
|
||||
if pid not in pids and _pid_is_dashboard(pid):
|
||||
pids.append(pid)
|
||||
|
||||
|
||||
def _dashboard_pids() -> list[int]:
|
||||
pids: list[int] = []
|
||||
pid_text = os.environ.get("OMARCHY_INSTALL_DASHBOARD_PID")
|
||||
if pid_text:
|
||||
try:
|
||||
pid = int(pid_text)
|
||||
if _pid_is_dashboard(pid):
|
||||
pids.append(pid)
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
# Belt-and-suspenders fallback in case the env var was lost before finish.
|
||||
_add_dashboard_pid(pids, os.environ.get("OMARCHY_INSTALL_DASHBOARD_PID"))
|
||||
|
||||
pid_file = Path("/run/omarchy-install/dashboard.pid")
|
||||
try:
|
||||
proc = subprocess.run(
|
||||
["pgrep", "-f", "omarchy-install-dashboard"],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
check=False,
|
||||
)
|
||||
for line in proc.stdout.splitlines():
|
||||
try:
|
||||
pid = int(line)
|
||||
except ValueError:
|
||||
continue
|
||||
if pid not in pids and _pid_is_dashboard(pid):
|
||||
pids.append(pid)
|
||||
_add_dashboard_pid(pids, pid_file.read_text())
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
# Last-resort /proc scan. Do not rely on pgrep being present in the ISO.
|
||||
for proc_dir in Path("/proc").iterdir():
|
||||
if not proc_dir.name.isdigit():
|
||||
continue
|
||||
_add_dashboard_pid(pids, proc_dir.name)
|
||||
|
||||
return pids
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user