47 lines
1.3 KiB
Bash
47 lines
1.3 KiB
Bash
#!/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"
|