Repository navigation
Expand file tree
/
Copy pathclaude-track-manager.sh
More file actions
executable file
·146 lines (126 loc) · 3.08 KB
/
Copy pathclaude-track-manager.sh
File metadata and controls
executable file
·146 lines (126 loc) · 3.08 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
#!/bin/bash
# Claude Track Manager - 管理スクリプト
# Usage: ./claude-track-manager.sh [start|stop|restart|status|logs|errors]
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
DAEMON_SCRIPT="$SCRIPT_DIR/claude-auto-track-daemon.js"
PID_FILE="$SCRIPT_DIR/.claude-track.pid"
LOG_FILE="$SCRIPT_DIR/.claude-track.log"
ERROR_LOG_FILE="$SCRIPT_DIR/.claude-track-error.log"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
NC='\033[0m' # No Color
# Check if daemon is running
is_running() {
if [ -f "$PID_FILE" ]; then
PID=$(cat "$PID_FILE")
if ps -p "$PID" > /dev/null 2>&1; then
return 0
else
# Stale PID file
rm -f "$PID_FILE"
return 1
fi
else
return 1
fi
}
# Start the daemon
start() {
echo -e "${YELLOW}Starting Claude Auto Track Daemon...${NC}"
if is_running; then
echo -e "${RED}Daemon is already running (PID: $(cat "$PID_FILE"))${NC}"
exit 1
fi
# Start daemon in background
nohup node "$DAEMON_SCRIPT" > /dev/null 2>&1 &
sleep 2
if is_running; then
echo -e "${GREEN}Daemon started successfully (PID: $(cat "$PID_FILE"))${NC}"
else
echo -e "${RED}Failed to start daemon${NC}"
exit 1
fi
}
# Stop the daemon
stop() {
echo -e "${YELLOW}Stopping Claude Auto Track Daemon...${NC}"
if ! is_running; then
echo -e "${RED}Daemon is not running${NC}"
exit 1
fi
PID=$(cat "$PID_FILE")
kill "$PID"
sleep 2
if is_running; then
echo -e "${YELLOW}Force stopping daemon...${NC}"
kill -9 "$PID"
rm -f "$PID_FILE"
fi
echo -e "${GREEN}Daemon stopped${NC}"
}
# Restart the daemon
restart() {
stop
sleep 1
start
}
# Check status
status() {
if is_running; then
PID=$(cat "$PID_FILE")
echo -e "${GREEN}Claude Auto Track Daemon is running (PID: $PID)${NC}"
# Show process info
echo -e "\nProcess info:"
ps -p "$PID" -o pid,ppid,user,%cpu,%mem,etime,cmd
# Show recent logs
echo -e "\nRecent activity:"
tail -n 5 "$LOG_FILE" 2>/dev/null || echo "No logs available"
else
echo -e "${RED}Claude Auto Track Daemon is not running${NC}"
fi
}
# Show logs
logs() {
if [ -f "$LOG_FILE" ]; then
echo -e "${YELLOW}=== Claude Auto Track Logs ===${NC}"
tail -f "$LOG_FILE"
else
echo -e "${RED}No log file found${NC}"
fi
}
# Show error logs
errors() {
if [ -f "$ERROR_LOG_FILE" ]; then
echo -e "${YELLOW}=== Claude Auto Track Error Logs ===${NC}"
tail -f "$ERROR_LOG_FILE"
else
echo -e "${GREEN}No errors logged${NC}"
fi
}
# Main
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
status)
status
;;
logs)
logs
;;
errors)
errors
;;
*)
echo "Usage: $0 {start|stop|restart|status|logs|errors}"
exit 1
;;
esac