-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathstart-dashboard.sh
More file actions
executable file
·156 lines (139 loc) · 4.1 KB
/
start-dashboard.sh
File metadata and controls
executable file
·156 lines (139 loc) · 4.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/bin/bash
# MoltBoard Startup Script (legacy)
# Run on login or manually
# Prefer launchctl via scripts/manage-launchctl.sh for production restarts.
get_workspace_dir() {
python3 - <<'PY'
import json
import os
from pathlib import Path
default = str(Path.home() / 'workspace')
# Check environment variables first
workspace = os.environ.get('MOLTBOT_WORKSPACE') or os.environ.get('WORKSPACE_DIR')
if workspace and workspace.strip():
print(workspace.strip())
raise SystemExit(0)
# Check config files (current: clawdbot, future: moltbot)
config_paths = [
Path.home() / '.clawdbot' / 'clawdbot.json',
Path.home() / '.moltbot' / 'moltbot.json',
]
for config in config_paths:
try:
if config.exists():
data = json.loads(config.read_text())
workspace = data.get('agents', {}).get('defaults', {}).get('workspace')
if workspace and workspace.strip():
print(workspace.strip())
raise SystemExit(0)
except Exception:
continue
print(default)
PY
}
WORKSPACE_DIR="${WORKSPACE_DIR:-$(get_workspace_dir)}"
LOG_FILE="$WORKSPACE_DIR/logs/moltboard.log"
PID_FILE="$WORKSPACE_DIR/logs/moltboard.pid"
WORKER_LOG_FILE="$WORKSPACE_DIR/logs/moltboard-worker.log"
WORKER_PID_FILE="$WORKSPACE_DIR/logs/moltboard-worker.pid"
DB_PATH="${DB_PATH:-$HOME/clawdbot/data/tasks.db}"
export DATABASE_URL="$DB_PATH"
export MOLTBOT_DB_PATH="$DB_PATH"
start_dashboard() {
if [ -f "$PID_FILE" ]; then
OLD_PID=$(cat "$PID_FILE")
if kill -0 "$OLD_PID" 2>/dev/null; then
echo "MoltBoard already running (PID: $OLD_PID)"
return 0
else
rm -f "$PID_FILE"
fi
fi
cd "$WORKSPACE_DIR/moltboard"
bun run dev >> "$LOG_FILE" 2>&1 &
echo $! > "$PID_FILE"
echo "MoltBoard started (PID: $(cat $PID_FILE))"
# Start background worker
if [ -f "$WORKER_PID_FILE" ]; then
OLD_WORKER_PID=$(cat "$WORKER_PID_FILE")
if kill -0 "$OLD_WORKER_PID" 2>/dev/null; then
echo "MoltBoard worker already running (PID: $OLD_WORKER_PID)"
return 0
else
rm -f "$WORKER_PID_FILE"
fi
fi
bun "$WORKSPACE_DIR/moltboard/scripts/recurring-work.js" >> "$WORKER_LOG_FILE" 2>&1 &
echo $! > "$WORKER_PID_FILE"
echo "MoltBoard worker started (PID: $(cat $WORKER_PID_FILE))"
}
stop_dashboard() {
if [ -f "$PID_FILE" ]; then
PID=$(cat "$PID_FILE")
if kill -0 "$PID" 2>/dev/null; then
kill "$PID"
rm -f "$PID_FILE"
echo "MoltBoard stopped"
else
rm -f "$PID_FILE"
echo "MoltBoard was not running"
fi
else
echo "MoltBoard not running"
fi
if [ -f "$WORKER_PID_FILE" ]; then
WORKER_PID=$(cat "$WORKER_PID_FILE")
if kill -0 "$WORKER_PID" 2>/dev/null; then
kill "$WORKER_PID"
rm -f "$WORKER_PID_FILE"
echo "MoltBoard worker stopped"
else
rm -f "$WORKER_PID_FILE"
echo "MoltBoard worker was not running"
fi
else
echo "MoltBoard worker not running"
fi
}
status_dashboard() {
if [ -f "$PID_FILE" ]; then
PID=$(cat "$PID_FILE")
if kill -0 "$PID" 2>/dev/null; then
echo "MoltBoard is running (PID: $PID)"
else
echo "MoltBoard is not running (stale PID file)"
fi
else
echo "MoltBoard is not running"
fi
if [ -f "$WORKER_PID_FILE" ]; then
WORKER_PID=$(cat "$WORKER_PID_FILE")
if kill -0 "$WORKER_PID" 2>/dev/null; then
echo "MoltBoard worker is running (PID: $WORKER_PID)"
else
echo "MoltBoard worker is not running (stale PID file)"
fi
else
echo "MoltBoard worker is not running"
fi
}
case "$1" in
start)
start_dashboard
;;
stop)
stop_dashboard
;;
restart)
stop_dashboard
sleep 2
start_dashboard
;;
status)
status_dashboard
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
;;
esac