forked from hanrok/godebug
-
Notifications
You must be signed in to change notification settings - Fork 0
/
startScript.sh
80 lines (65 loc) · 1.6 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
77
78
79
80
#!/bin/bash
# create directory for Delve logs, we use it to know that Delve
# debugger is running
mkdir -p /tmp/dlv_log
runServer() {
echo Running server
# create directory and file to
touch /tmp/dlv_log/output.log
# run server with debug
dlv --listen=:40000 --headless=true --api-version=2 exec \
/server | tee -a /tmp/dlv_log/output.log &
# wait for Delve to modify log files - means /server is alreday run
inotifywait -e MODIFY /tmp/dlv_log/output.log &>/dev/null
echo Delve PID: $(pidof dlv), Server PID: $(pidof server)
pidof dlv > /tmp/dlv.pid
pidof server > /tmp/server.pid
}
killRunningServer() {
if [ -f /tmp/dlv.pid ]
then
echo killing old Delve, PID: $(cat /tmp/dlv.pid)
kill $(cat /tmp/dlv.pid)
rm -f /tmp/dlv.pid
fi
if [ -f /tmp/server.pid ]
then
echo killing old server, PID: $(cat /tmp/server.pid)
kill $(cat /tmp/server.pid)
rm -f /tmp/server.pid
fi
}
buildServer() {
echo Building server
go build -gcflags "all=-N -l" -o /server .playground/main.go
}
rerunServer () {
killRunningServer
buildServer
runServer
}
lockBuild() {
# check lock file existence
if [ -f /tmp/server.lock ]
then
# waiting for the file to delete
inotifywait -e DELETE /tmp/server.lock
fi
touch /tmp/server.lock
}
unlockBuild() {
# remove lock file
rm -f /tmp/server.lock
}
# run the server for the first time
runServer
inotifywait -e MODIFY -r -m /build |
while read path action file; do
lockBuild
ext=${file: -3}
if [[ "$ext" == ".go" ]]; then
echo File changed: $file
rerunServer
fi
unlockBuild
done