86 lines
3.3 KiB
Bash
Executable File
86 lines
3.3 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
# "Something crashed" -> an agent already reading the core dump.
|
|
#
|
|
# Reached by clicking the crash notification panama-crash-watch sends, or run by
|
|
# hand against any PID in `coredumpctl list`. It gathers the four facts
|
|
# systemd-coredump recorded and points at the skill that says what to do with
|
|
# them; the method lives in the skill so it is edited in one place and works
|
|
# whichever agent is configured.
|
|
#
|
|
# panama-agent-crash <pid> [comm] [exe] [signal]
|
|
#
|
|
# The skill is named AND given as an absolute path. A harness with a skill
|
|
# mechanism follows the name; one without still has a file to read. That is the
|
|
# whole reason this ladder works for more than one agent.
|
|
#
|
|
# ---------------------------------------------------------------------------
|
|
# Adapted from Omarchy's bin/omarchy-agent-crash
|
|
# (https://github.com/basecamp/omarchy)
|
|
#
|
|
# Copyright (c) David Heinemeier Hansson
|
|
#
|
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
# of this software and associated documentation files (the "Software"), to deal
|
|
# in the Software without restriction, including without limitation the rights
|
|
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
# copies of the Software, and to permit persons to whom the Software is
|
|
# furnished to do so, subject to the following conditions:
|
|
#
|
|
# The above copyright notice and this permission notice shall be included in all
|
|
# copies or substantial portions of the Software.
|
|
#
|
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
# SOFTWARE.
|
|
# ---------------------------------------------------------------------------
|
|
|
|
set -euo pipefail
|
|
|
|
PANAMA_PATH="${PANAMA_PATH:-$(cd "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")/.." && pwd)}"
|
|
|
|
pid="${1:-}"
|
|
if [[ ! "$pid" =~ ^[0-9]+$ ]]; then
|
|
printf 'Not a PID: %s\n' "${pid:-<missing>}" >&2
|
|
printf 'Usage: panama-agent-crash <pid> [comm] [exe] [signal] (see: coredumpctl list)\n' >&2
|
|
exit 1
|
|
fi
|
|
|
|
comm="${2:-unknown}"
|
|
exe="${3:-unknown}"
|
|
signal="${4:-unknown}"
|
|
|
|
skill="$PANAMA_PATH/skills/diagnose-crash/SKILL.md"
|
|
|
|
# Looked up live so a PID typed by hand still gets a timestamp. A core that has
|
|
# already been rotated away costs only the timestamp, so this is allowed to
|
|
# fail: the other four facts are enough to start on.
|
|
when="$(coredumpctl list "$pid" --no-pager --no-legend 2>/dev/null | tail -1 | cut -d' ' -f1-4)" || true
|
|
when="${when:-unknown}"
|
|
[[ -n "${when// }" ]] || when="unknown"
|
|
|
|
prompt="$(
|
|
cat <<PROMPT
|
|
A process crashed on this Panama machine and I want to know why.
|
|
|
|
What systemd-coredump recorded:
|
|
process: $comm
|
|
PID: $pid
|
|
binary: $exe
|
|
signal: $signal
|
|
time: $when
|
|
|
|
Use the diagnose-crash skill. It covers how to investigate, what to rule out
|
|
first, and what to report. If your harness has no skill mechanism, read the
|
|
skill file directly and follow it instead:
|
|
|
|
$skill
|
|
PROMPT
|
|
)"
|
|
|
|
exec "$PANAMA_PATH/bin/panama-agent" --prompt "$prompt"
|