-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathserver_runner
executable file
·28 lines (27 loc) · 989 Bytes
/
server_runner
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
#!/bin/bash
asRoot=""
notAsRoot="sudo -u ais"
cd "/home/ais/go/src/github.com/tormol/AIS/"
binPath='./ais_server'
go='GOPATH=/usr/local/go/src:/home/ais/go /usr/local/go/bin/go'
git='HOME=/home/ais git'
while true; do # restart after crashes
$notAsRoot $git pull origin master # try with old code if failed
filesInMain=`find server -maxdepth 1 -name '*.go' -not -name '*_test.go'`
$notAsRoot $go build -o "$binPath" $filesInMain # try with old binary if failed
# allow binary to listen on any port without being root
$asRoot setcap CAP_NET_BIND_SERVICE=+eip "$binPath" || break
#$asRoot ufw allow 80/tcp
#$asRoot ufw allow 23
started_u=`date '+%s'` # %s is UNIX timestamp
started=`date '+%Y-%m-%d %H:%M'` # 2017-03-31 18:39
echo -e "\n\nStarted on $started" >&2
$notAsRoot "$binPath" $@ >/dev/null
crashed_u=`date '+%s'`
#$asRoot ufw deny 23
#$asRoot ufw deny 80/tcp
if [[ $(($crashed_u-$started_u)) -le 60 ]]; then # avoid crash loop
break
fi
done
echo 'Stopping!' >&2