forked from HSLdevcom/OpenTripPlanner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.sh
executable file
·87 lines (69 loc) · 1.95 KB
/
run.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
81
82
83
84
85
86
87
#!/bin/bash
# Fail fast if graph building fails
set -e
JAR=`ls *-shaded*`
echo JAR=$JAR
SLEEP_TIME=5
function url {
echo $ROUTER_DATA_CONTAINER_URL/$1
}
function build_graph {
GRAPHNAME=$1
FILE=$2
echo "building graph..."
DIR="graphs"
rm -rf $DIR || true
mkdir -p $DIR
unzip -o -d $DIR $FILE && rm $FILE
mv $DIR/router-$GRAPHNAME $DIR/$GRAPHNAME
java $JAVA_OPTS -jar $JAR --build --save ./$DIR/$GRAPHNAME
}
function download_graph {
NAME=$1
VERSION=$2
GRAPH_FILE=graph-$NAME.zip
URL=$(url "graph-$NAME-$VERSION.zip")
echo "Downloading graph from $URL"
for i in {1..6}; do
HTTP_STATUS=$(curl --write-out %{http_code} --silent --output $GRAPH_FILE $URL)
if [ "$HTTP_STATUS" -eq 404 ]; then
rm $GRAPH_FILE > /dev/null
echo "Graph not found"
return 1
fi
if [ "$HTTP_STATUS" -eq 200 ]; then break
fi
rm $GRAPH_FILE > /dev/null
sleep $SLEEP_TIME
done
if [ -f graph-$NAME.zip ]; then
# if the graph already exists then overwrite it, otherwise we need to build a new one on every start
unzip -o $GRAPH_FILE -d ./graphs
SUCCESS=$?
rm $GRAPH_FILE
return $SUCCESS
else
return 1
fi
}
function version {
java -jar $JAR --version|grep -o -P '(?<=commit: ).*(?=,)'
}
function process {
NAME=$1
URL=$(url "router-$NAME.zip")
FILE="$NAME.zip"
echo "Retrieving graph source bundle from $URL"
until curl -f -s $URL -o $FILE
do
echo "Error retrieving graph source bundle $URL from otp-data-server... retrying in $SLEEP_TIME s..."
sleep $SLEEP_TIME
done
build_graph $NAME $FILE
}
VERSION=$(version)
echo VERSION $VERSION
echo ROUTER $ROUTER_NAME
download_graph $ROUTER_NAME $VERSION || process $ROUTER_NAME
echo "graphString is: $ROUTER_NAME"
java -Dsentry.release=$VERSION $JAVA_OPTS -Duser.timezone=Europe/Helsinki -Djava.awt.headless=true --add-exports java.desktop/sun.font=ALL-UNNAMED -jar $JAR --serve --port $PORT --load ./graphs/$ROUTER_NAME