blob: 051e7a4fb688f63fe321c0e5676f22415d2273a8 (
plain)
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
|
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
process_pid=""
new_process_pid=""
function start {
GITALY_LISTEN_ADDR=:1828 go run cmd/gitaly/main.go &
process_pid=$!
}
function restart {
GITALY_LISTEN_ADDR=:1828 go run cmd/gitaly/main.go &
new_process_pid=$!
# Give the new process time to start listening before killing the old one
sleep 2
kill -s TERM ${process_pid} || true
process_pid=${new_process_pid}
new_process_pid=""
}
function finish {
# Last ditch attempt to cleanup before termination
kill -s TERM ${process_pid} || true
# If this is run while both the old and new processes are running
# we need to make sure we terminate both processes
if [[ -n "${new_process_pid}" ]]; then
kill -s TERM ${new_process_pid} || true
fi
}
function forward_signal {
kill -s ${1} ${process_pid}
}
function await_process {
set +e
wait -n
local wait_status=$?
set -e
if [[ ${wait_status} == 0 ]] || [[ ${wait_status} == 129 ]] ; then
return
else
exit ${wait_status}
fi
}
trap restart SIGHUP
trap finish EXIT
for sig in STOP CONT ALRM INT QUIT USR1 USR2 TERM; do
trap "forward_signal ${sig}" ${sig}
done
start
while true; do
await_process
sleep 1
if [[ -z $(jobs -r) ]]; then
exit
fi
done
|