-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathservices.sh
More file actions
executable file
·198 lines (173 loc) · 4.44 KB
/
Copy pathservices.sh
File metadata and controls
executable file
·198 lines (173 loc) · 4.44 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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#!/bin/bash
# BotAI Service Manager
# Start/Stop/Restart/Status for Frontend + Backend
set -e
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
# Configuration
BOTAI_DIR="$HOME/clawd/botai"
FRONTEND_DIR="$BOTAI_DIR/frontend"
BACKEND_DIR="$BOTAI_DIR/backend"
FRONTEND_PORT=3001
BACKEND_PORT=8000
LOG_DIR="/tmp/botai-logs"
# Create log directory
mkdir -p "$LOG_DIR"
# Functions
print_info() { echo -e "${GREEN}[INFO]${NC} $1"; }
print_error() { echo -e "${RED}[ERROR]${NC} $1"; }
print_warning() { echo -e "${YELLOW}[WARN]${NC} $1"; }
check_port() {
local port=$1
lsof -Pi :$port -sTCP:LISTEN -t >/dev/null 2>&1
}
get_pid() {
local port=$1
lsof -ti:$port 2>/dev/null
}
# Stop services
stop_services() {
print_info "Stopping BotAI services..."
# Stop Frontend
if check_port $FRONTEND_PORT; then
PID=$(get_pid $FRONTEND_PORT)
kill $PID 2>/dev/null && print_info "Frontend stopped (PID: $PID)" || print_warning "Frontend already stopped"
else
print_info "Frontend not running"
fi
# Stop Backend
if check_port $BACKEND_PORT; then
PID=$(get_pid $BACKEND_PORT)
kill $PID 2>/dev/null && print_info "Backend stopped (PID: $PID)" || print_warning "Backend already stopped"
else
print_info "Backend not running"
fi
sleep 1
print_info "All services stopped"
}
# Start services
start_services() {
print_info "Starting BotAI services..."
# Start Backend
if check_port $BACKEND_PORT; then
print_warning "Backend already running on port $BACKEND_PORT"
else
cd "$BACKEND_DIR"
source venv/bin/activate
nohup python main.py > "$LOG_DIR/backend.log" 2>&1 &
sleep 2
print_info "Backend started (Port: $BACKEND_PORT)"
fi
# Start Frontend
if check_port $FRONTEND_PORT; then
print_warning "Frontend already running on port $FRONTEND_PORT"
else
cd "$FRONTEND_DIR"
nohup npm run dev > "$LOG_DIR/frontend.log" 2>&1 &
sleep 2
print_info "Frontend started (Port: $FRONTEND_PORT)"
fi
echo ""
print_info "🤖 BotAI is running!"
echo -e " ${BLUE}Frontend:${NC} http://localhost:$FRONTEND_PORT"
echo -e " ${BLUE}Backend:${NC} http://localhost:$BACKEND_PORT"
}
# Restart services
restart_services() {
print_info "Restarting BotAI services..."
stop_services
sleep 2
start_services
}
# Status
status_services() {
echo ""
echo "=============================="
echo " BotAI Services Status"
echo "=============================="
echo ""
# Frontend
if check_port $FRONTEND_PORT; then
PID=$(get_pid $FRONTEND_PORT)
echo -e "Frontend: ${GREEN}●${NC} Running (PID: $PID, Port: $FRONTEND_PORT)"
else
echo -e "Frontend: ${RED}○${NC} Stopped"
fi
# Backend
if check_port $BACKEND_PORT; then
PID=$(get_pid $BACKEND_PORT)
echo -e "Backend: ${GREEN}●${NC} Running (PID: $PID, Port: $BACKEND_PORT)"
else
echo -e "Backend: ${RED}○${NC} Stopped"
fi
echo ""
}
# Logs
logs_services() {
local service=$1
case $service in
frontend|f)
tail -f "$LOG_DIR/frontend.log"
;;
backend|b)
tail -f "$LOG_DIR/backend.log"
;;
all|a)
tail -f "$LOG_DIR"/*.log
;;
*)
print_error "Usage: $0 logs {frontend|backend|all}"
exit 1
;;
esac
}
# Help
show_help() {
echo "BotAI Service Manager"
echo ""
echo "Usage: $0 {start|stop|restart|status|logs|help}"
echo ""
echo "Commands:"
echo " start Start all services"
echo " stop Stop all services"
echo " restart Restart all services"
echo " status Show service status"
echo " logs Show logs (frontend|backend|all)"
echo " help Show this help"
echo ""
echo "Examples:"
echo " $0 start"
echo " $0 logs backend"
echo " $0 status"
}
# Main
case "$1" in
start)
start_services
;;
stop)
stop_services
;;
restart)
restart_services
;;
status)
status_services
;;
logs)
logs_services "$2"
;;
help|--help|-h)
show_help
;;
*)
print_error "Invalid command: $1"
show_help
exit 1
;;
esac
exit 0