From 5280f1987b81d17f4f6967c68684b1cfc648640e Mon Sep 17 00:00:00 2001 From: mineseo-kim Date: Thu, 9 Apr 2026 09:56:46 +0900 Subject: [PATCH] chore(scripts): add systemd ExecStartPre for kord log directory When StandardOutput=append points under ~/kord/logs, systemd opens the file before ExecStart; a missing directory causes status 209/STDOUT. Inject mkdir -p via ExecStartPre so restarts survive a deleted logs folder. Made-with: Cursor --- scripts/setup-kord-user-log-file.sh | 46 +++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 scripts/setup-kord-user-log-file.sh diff --git a/scripts/setup-kord-user-log-file.sh b/scripts/setup-kord-user-log-file.sh new file mode 100644 index 0000000..bdc20b3 --- /dev/null +++ b/scripts/setup-kord-user-log-file.sh @@ -0,0 +1,46 @@ +#!/usr/bin/env bash +# Run ON THE SERVER as the same user that runs kord (e.g. psa), after: ssh psa@server +# Switches kord user service from journal-only to append logs under ~/kord/logs/kord.log + +set -euo pipefail + +UNIT="${XDG_CONFIG_HOME:-$HOME/.config}/systemd/user/kord.service" +LOG_DIR="$HOME/kord/logs" +LOG_FILE="$LOG_DIR/kord.log" + +mkdir -p "$LOG_DIR" + +if [[ ! -f "$UNIT" ]]; then + echo "Unit not found: $UNIT" >&2 + exit 1 +fi + +cp -a "$UNIT" "${UNIT}.bak.$(date +%Y%m%d%H%M%S)" + +# Replace journal with file append (idempotent if already set) +sed -i \ + -e 's|^StandardOutput=journal|StandardOutput=append:'"$LOG_FILE"'|' \ + -e 's|^StandardError=journal|StandardError=append:'"$LOG_FILE"'|' \ + "$UNIT" + +# systemd opens StandardOutput=append before ExecStart; if ~/kord/logs was deleted, +# the service fails with (code=exited, status=209/STDOUT). Ensure the dir exists first. +if ! grep -qE '^ExecStartPre=.*mkdir.*kord/logs' "$UNIT"; then + sed -i '/^ExecStart=/i ExecStartPre=-/usr/bin/mkdir -p %h/kord/logs' "$UNIT" +fi + +systemctl --user daemon-reload +systemctl --user restart kord + +sleep 2 +systemctl --user --no-pager status kord || true + +echo "--- Last lines of $LOG_FILE (if any) ---" +if [[ -f "$LOG_FILE" ]]; then + tail -n 20 "$LOG_FILE" +else + echo "(file not created yet; check status above)" +fi + +echo +echo "Follow logs: tail -f $LOG_FILE"