-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdev-watch.sh
More file actions
executable file
·69 lines (58 loc) · 2.06 KB
/
dev-watch.sh
File metadata and controls
executable file
·69 lines (58 loc) · 2.06 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
#!/bin/bash
# Configuration
MIN_REBUILD_INTERVAL=10 # Minimum seconds between rebuilds
CONTAINER_NAME="sift-grafana-datasource"
RESTART_DELAY=2 # Seconds to wait after rebuild before restarting Grafana
# Variables
last_rebuild_time=0
# Function to rebuild the plugin and restart Grafana
rebuild_and_restart() {
current_time=$(date +%s)
time_since_last_rebuild=$((current_time - last_rebuild_time))
if [ $time_since_last_rebuild -lt $MIN_REBUILD_INTERVAL ]; then
echo "Skipping rebuild - last rebuild was $time_since_last_rebuild seconds ago (minimum interval: $MIN_REBUILD_INTERVAL seconds)"
return
fi
echo "Rebuilding plugin using mage..."
mage -v
build_result=$?
last_rebuild_time=$(date +%s)
if [ $build_result -eq 0 ]; then
echo "Build successful at $(date)"
echo "Waiting $RESTART_DELAY seconds before restarting Grafana..."
sleep $RESTART_DELAY
echo "Restarting Grafana container..."
docker restart $CONTAINER_NAME
echo "Grafana container restarted"
else
echo "Build failed with exit code $build_result"
fi
}
# Initial build and restart
echo "Performing initial build..."
rebuild_and_restart
# Watch for changes
echo "Watching for changes in pkg directory..."
echo "Minimum rebuild interval: $MIN_REBUILD_INTERVAL seconds"
echo "Press Ctrl+C to stop watching"
# Use fswatch if available, otherwise fallback to a simple polling approach
if command -v fswatch > /dev/null; then
echo "Using fswatch for file monitoring"
fswatch -o ./pkg | while read f; do
echo "Change detected in $f"
rebuild_and_restart
done
else
# Fallback to a simple polling approach
echo "fswatch not found, using simple polling (install fswatch for better performance)"
last_hash=$(find ./pkg -type f -name "*.go" -exec md5 {} \; | sort | md5)
while true; do
sleep 2 # Check every 2 seconds
current_hash=$(find ./pkg -type f -name "*.go" -exec md5 {} \; | sort | md5)
if [ "$last_hash" != "$current_hash" ]; then
echo "Change detected"
rebuild_and_restart
last_hash=$current_hash
fi
done
fi