-
Notifications
You must be signed in to change notification settings - Fork 7
/
monit_restart.sh
executable file
·64 lines (54 loc) · 1.92 KB
/
monit_restart.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
#!/bin/sh
USAGE="<GIT REPO NAME> {start|stop} <PORT> [<JAVA OPTS>]"
if [ $# -lt 3 ]; then
echo "$USAGE
THIS SCRIPT SHOULD ONLY BE USED BY -MONIT-!
If you want to restart an instance, use ./restart.sh
First 3 parameters are mandatory.
Don't forget that the process is monitored by 'monit'.
It will restart automatically if you stop the API.
If you want to stop it permanently, do 'sudo /etc/ini.d/monit stop' first.
"
exit 65
fi
REPO=$1
ACTION=$2
PORT=$3
JAVA_OPTS="$4"
DO_ETL_UPDATE="$5"
HOME="/home/sol"
# it is important to set the proper locale
. $HOME/.locale
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64/
JAVA_OPTS=$(echo "$JAVA_OPTS" |sed 's#,#\ #g')
cd $HOME/git/$REPO
ETL_TOKEN=$(cat scripts/.secrets/ETL_TOKEN)
case $ACTION in
start)
cd ..; mvn clean install -DskipTests=true; cd -
if [ -f target/universal/stage/RUNNING_PID ]; then
kill $(cat target/universal/stage/RUNNING_PID)
rm target/universal/stage/RUNNING_PID
fi
JAVA_OPTS="$JAVA_OPTS -XX:+ExitOnOutOfMemoryError -XX:+HeapDumpOnOutOfMemoryError -DpreferIPv4Stack"
sbt clean
sbt --java-home $JAVA_HOME stage
./target/universal/stage/bin/lobid-resources-web -Dhttp.port=$PORT -no-version-check > monit_start.log &
if [ -n "$DO_ETL_UPDATE" -a $(tail -n100 logs/etl.log |grep -c "Finishing indexing of ES index 'resources-alma-fix") -eq 0 ]; then
echo "Automatical updates-ETL triggered and last entries were not ok, thus starting ETL. Sleep 100s before starting ETL ..." >> monit_start.log
sleep 100
curl http://localhost:$PORT/resources/webhook/update-alma?token=$ETL_TOKEN
fi
echo "Done starting!" >> monit_start.log
;;
stop)
kill $(cat target/universal/stage/RUNNING_PID)
sleep 14
kill -9 $(cat target/universal/stage/RUNNING_PID)
rm target/universal/stage/RUNNING_PID
;;
*)
echo "usage: $USAGE"
;;
esac
exit 0