-
Notifications
You must be signed in to change notification settings - Fork 8
/
startScript.sh
76 lines (67 loc) · 1.42 KB
/
startScript.sh
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
#!/usr/bin/env bash
log() {
echo "STARTSCRIPT: $1"
}
buildServer() {
log "Building server binary"
go build -gcflags "all=-N -l" -o /server main.go
}
runServer() {
log "Run server"
log "Killing old server"
killall dlv
killall server
log "Run in debug mode"
dlv --listen=:40000 --headless=true --api-version=2 --accept-multiclient exec /server &
}
rerunServer() {
log "Rerun server"
buildServer
runServer
}
liveReloading() {
log "Run liveReloading"
inotifywait -e "MODIFY,DELETE,MOVED_TO,MOVED_FROM" -m -r --include '.go$' /build | (
# read changes from inotify, batch results to a second (read -t 1)
while true; do
read path action file
ext=${file: -3}
if [[ "$ext" == ".go" ]]; then
echo "$file"
fi
done
) | (
WAITING=""
while true; do
file=""
read -t 1 file
if test -z "$file"; then
if test ! -z "$WAITING"; then
echo "CHANGED"
WAITING=""
fi
else
log "File ${file} changed" >>/tmp/filechanges.log
WAITING=1
fi
done
) | (
# read statement release when some file has been changed
while true; do
read TMP
log "File Changed. Reloading..."
rerunServer
done
)
}
initializeFileChangeLogger() {
echo "" > /tmp/filechanges.log
tail -f /tmp/filechanges.log &
}
main() {
initializeFileChangeLogger
buildServer
runServer
liveReloading
}
main