#!/bin/bash # restart.sh — safe bot restart with process tracking # Usage: bash restart.sh cd "$(dirname "$0")" # Kill any existing zcode process pkill -f "bin/zcode.js" 2>/dev/null sleep 1 # Ensure log directory exists mkdir -p logs # Start with auto-restart loop ( while true; do node bin/zcode.js --no-cli >> logs/zcode.log 2>&1 EXIT=$? echo "[$(date -Iseconds)] Process exited ($EXIT), restarting in 3s..." >> logs/zcode.log sleep 3 done ) & disown sleep 2 echo "=== Process ===" ps aux | grep "bin/zcode" | grep -v grep echo "=== Recent logs ===" tail -10 logs/zcode.log