#!/bin/bash # Alternative start script using tmux for persistence # This is useful when systemd user session is not available set -e USER_NAME="${USER_NAME:-$(whoami)}" SESSION_NAME="teamspeak-echoion" echo "TeamSpeak Echoion - Tmux Session Starter" echo "========================================" echo "" # Check if tmux is installed if ! command -v tmux &> /dev/null; then echo "Error: tmux is not installed" echo "Install it with: sudo pacman -S tmux" exit 1 fi # Check if session already exists if tmux has-session -t "$SESSION_NAME" 2>/dev/null; then echo "Session '$SESSION_NAME' already exists!" echo "" echo "Options:" echo " 1. Attach to existing session: tmux attach -t $SESSION_NAME" echo " 2. Kill existing session: tmux kill-session -t $SESSION_NAME" echo " 3. View logs: tmux capture-pane -t $SESSION_NAME -p | tail -50" echo "" read -p "Kill existing session and start new? (y/N) " -n 1 -r echo if [[ $REPLY =~ ^[Yy]$ ]]; then tmux kill-session -t "$SESSION_NAME" echo "Killed existing session" else echo "Exiting..." exit 0 fi fi echo "Starting new tmux session: $SESSION_NAME" echo "" # Create new detached session tmux new-session -d -s "$SESSION_NAME" -n "teamspeak" "bash -c 'cd ~ && echo \"Starting TeamSpeak Echoion...\" && ~/echoion/scripts/run-teamspeak-headless.sh'" # Optional: Create additional windows for monitoring tmux new-window -t "$SESSION_NAME" -n "logs" "bash -c 'echo \"Waiting for logs...\" && sleep 5 && journalctl --user -u teamspeak-echoion -f 2>/dev/null || tail -f /tmp/.ts3bot-display-$USER_NAME/*.log 2>/dev/null || echo \"No logs available\"'" echo -e "\033[0;32mTmux session started successfully!\033[0m" echo "" echo "To attach to the session:" echo " tmux attach -t $SESSION_NAME" echo "" echo "To view logs without attaching:" echo " tmux capture-pane -t $SESSION_NAME:0 -p" echo "" echo "To detach from session (when attached):" echo " Press Ctrl+B then D" echo "" echo "To kill the session:" echo " tmux kill-session -t $SESSION_NAME" echo "" echo "Switch between windows (when attached):" echo " Ctrl+B then 0 (for TeamSpeak)" echo " Ctrl+B then 1 (for logs)"