-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheink_control.sh
More file actions
222 lines (194 loc) · 6.2 KB
/
eink_control.sh
File metadata and controls
222 lines (194 loc) · 6.2 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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
#!/bin/bash
# E-ink Display System Control Script
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
VENV_PATH="$HOME/eink_env"
DISPLAY_PID_FILE="/tmp/eink_display.pid"
SERVER_PID_FILE="/tmp/eink_server.pid"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
print_status() {
echo -e "${BLUE}📟 E-ink Display System Control${NC}"
echo "=================================="
}
start_services() {
print_status
echo -e "${GREEN}🚀 Starting E-ink Display System...${NC}"
# Check if services are already running and restart if needed
ALREADY_RUNNING=false
# Check display monitor
if [ -f $DISPLAY_PID_FILE ]; then
DISPLAY_PID=$(cat $DISPLAY_PID_FILE)
if kill -0 $DISPLAY_PID 2>/dev/null; then
ALREADY_RUNNING=true
fi
fi
# Check upload server
if [ -f $SERVER_PID_FILE ]; then
SERVER_PID=$(cat $SERVER_PID_FILE)
if kill -0 $SERVER_PID 2>/dev/null; then
ALREADY_RUNNING=true
fi
fi
# If already running, restart instead
if [ "$ALREADY_RUNNING" = true ]; then
echo -e "${YELLOW}⚡ Services already running - restarting...${NC}"
stop_services
sleep 2
echo -e "${GREEN}🚀 Starting fresh services...${NC}"
fi
# Check if virtual environment exists
if [ ! -d "$VENV_PATH" ]; then
echo -e "${RED}❌ Virtual environment not found at $VENV_PATH${NC}"
echo "Please run the installation first."
exit 1
fi
# Activate virtual environment
source "$VENV_PATH/bin/activate"
# Start display monitor
echo -e "${YELLOW}🖥️ Starting display monitor...${NC}"
python "$SCRIPT_DIR/display_latest.py" &
DISPLAY_PID=$!
echo $DISPLAY_PID > $DISPLAY_PID_FILE
# Start upload server
echo -e "${YELLOW}🌐 Starting upload server...${NC}"
python "$SCRIPT_DIR/upload_server.py" &
SERVER_PID=$!
echo $SERVER_PID > $SERVER_PID_FILE
sleep 2
# Check if processes are running
if kill -0 $DISPLAY_PID 2>/dev/null && kill -0 $SERVER_PID 2>/dev/null; then
echo -e "${GREEN}✅ E-ink Display System is running!${NC}"
echo " Display Monitor PID: $DISPLAY_PID"
echo " Upload Server PID: $SERVER_PID"
echo " Use './eink_control.sh stop' to stop services"
else
echo -e "${RED}❌ Failed to start services${NC}"
stop_services
exit 1
fi
}
stop_services() {
print_status
echo -e "${YELLOW}🛑 Stopping E-ink Display System...${NC}"
# Stop display monitor
if [ -f $DISPLAY_PID_FILE ]; then
DISPLAY_PID=$(cat $DISPLAY_PID_FILE)
if kill -0 $DISPLAY_PID 2>/dev/null; then
echo "🖥️ Stopping display monitor (PID: $DISPLAY_PID)"
kill $DISPLAY_PID
fi
rm -f $DISPLAY_PID_FILE
fi
# Stop upload server
if [ -f $SERVER_PID_FILE ]; then
SERVER_PID=$(cat $SERVER_PID_FILE)
if kill -0 $SERVER_PID 2>/dev/null; then
echo "🌐 Stopping upload server (PID: $SERVER_PID)"
kill $SERVER_PID
fi
rm -f $SERVER_PID_FILE
fi
echo -e "${GREEN}✅ E-ink Display System stopped${NC}"
}
check_status() {
print_status
echo -e "${BLUE}📊 Service Status:${NC}"
# Check display monitor
if [ -f $DISPLAY_PID_FILE ]; then
DISPLAY_PID=$(cat $DISPLAY_PID_FILE)
if kill -0 $DISPLAY_PID 2>/dev/null; then
echo -e "🖥️ Display Monitor: ${GREEN}RUNNING${NC} (PID: $DISPLAY_PID)"
else
echo -e "🖥️ Display Monitor: ${RED}STOPPED${NC}"
fi
else
echo -e "🖥️ Display Monitor: ${RED}STOPPED${NC}"
fi
# Check upload server
if [ -f $SERVER_PID_FILE ]; then
SERVER_PID=$(cat $SERVER_PID_FILE)
if kill -0 $SERVER_PID 2>/dev/null; then
echo -e "🌐 Upload Server: ${GREEN}RUNNING${NC} (PID: $SERVER_PID)"
else
echo -e "🌐 Upload Server: ${RED}STOPPED${NC}"
fi
else
echo -e "🌐 Upload Server: ${RED}STOPPED${NC}"
fi
}
show_logs() {
echo -e "${BLUE}📋 Recent Logs:${NC}"
echo "=================================="
# Show display monitor logs
if [ -f $DISPLAY_PID_FILE ]; then
DISPLAY_PID=$(cat $DISPLAY_PID_FILE)
if kill -0 $DISPLAY_PID 2>/dev/null; then
echo -e "${YELLOW}🖥️ Display Monitor Logs:${NC}"
# Since we're running in background, logs go to stdout
# In a real implementation, you'd redirect to log files
echo "Display monitor is running..."
fi
fi
# Show upload server logs
if [ -f $SERVER_PID_FILE ]; then
SERVER_PID=$(cat $SERVER_PID_FILE)
if kill -0 $SERVER_PID 2>/dev/null; then
echo -e "${YELLOW}🌐 Upload Server Logs:${NC}"
echo "Upload server is running..."
fi
fi
}
restart_services() {
stop_services
sleep 2
start_services
}
show_help() {
print_status
echo "Usage: $0 [command]"
echo ""
echo "Commands:"
echo " (no args) - Start both services (default action)"
echo " start - Start both services (automatically restarts if already running)"
echo " stop - Stop both services"
echo " restart - Restart both services (same as start when running)"
echo " status - Show service status"
echo " logs - Show recent logs"
echo " help - Show this help message"
echo ""
echo "Examples:"
echo " $0 # Start the system (default)"
echo " $0 start # Start the system (or restart if running)"
echo " $0 status # Check if services are running"
echo " $0 stop # Stop the system"
}
# Main script logic
case "${1:-start}" in
start)
start_services
;;
stop)
stop_services
;;
restart)
restart_services
;;
status)
check_status
;;
logs)
show_logs
;;
help|--help|-h)
show_help
;;
*)
echo -e "${RED}❌ Unknown command: $1${NC}"
show_help
exit 1
;;
esac