fix(swarm-worker): isolate session to /tmp/tmux-muse.sock and filter terminal slots in poller
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
set -euo pipefail
|
||||
|
||||
SESSION="swarm-worker"
|
||||
SOCKET_PATH="/tmp/tmux-muse.sock"
|
||||
LOG_DIR="/home/super/Projects/NetVM/logs"
|
||||
LOG_FILE="${LOG_DIR}/swarm-worker.log"
|
||||
|
||||
@@ -24,7 +25,7 @@ WORKER_CMD="python3 /home/super/Projects/NetVM/bin/swarm_worker/daemon.py"
|
||||
WORKER_MATCH='swarm_worker/daemon.[p]y'
|
||||
|
||||
session_exists() {
|
||||
tmux has-session -t "$SESSION" 2>/dev/null
|
||||
tmux -S "$SOCKET_PATH" has-session -t "$SESSION" 2>/dev/null
|
||||
}
|
||||
|
||||
worker_alive() {
|
||||
@@ -34,21 +35,30 @@ worker_alive() {
|
||||
do_start() {
|
||||
mkdir -p "$LOG_DIR"
|
||||
if session_exists; then
|
||||
echo "already running (tmux session $SESSION exists)"
|
||||
echo "already running (tmux session $SESSION exists on $SOCKET_PATH)"
|
||||
return 0
|
||||
fi
|
||||
tmux new-session -d -s "$SESSION" "$WORKER_CMD >>\"$LOG_FILE\" 2>&1"
|
||||
tmux -S "$SOCKET_PATH" new-session -d -s "$SESSION" "$WORKER_CMD >>\"$LOG_FILE\" 2>&1"
|
||||
sleep 1
|
||||
if worker_alive; then
|
||||
echo "started tmux session $SESSION (logging to $LOG_FILE)"
|
||||
echo "started tmux session $SESSION on $SOCKET_PATH (logging to $LOG_FILE)"
|
||||
else
|
||||
echo "WARNING: session $SESSION created but worker process not detected yet"
|
||||
echo "WARNING: session $SESSION created on $SOCKET_PATH but worker process not detected yet"
|
||||
fi
|
||||
}
|
||||
|
||||
do_stop() {
|
||||
local stopped=0
|
||||
if session_exists; then
|
||||
tmux kill-session -t "$SESSION"
|
||||
tmux -S "$SOCKET_PATH" kill-session -t "$SESSION" 2>/dev/null || true
|
||||
stopped=1
|
||||
fi
|
||||
# Also clean up accidental session on default socket if present
|
||||
if tmux has-session -t "$SESSION" 2>/dev/null; then
|
||||
tmux kill-session -t "$SESSION" 2>/dev/null || true
|
||||
stopped=1
|
||||
fi
|
||||
if [ "$stopped" -eq 1 ]; then
|
||||
echo "stopped tmux session $SESSION"
|
||||
else
|
||||
echo "not running (no tmux session $SESSION)"
|
||||
|
||||
Reference in New Issue
Block a user