mirror of https://github.com/micromata/borgbackup-butler.git

Kai Reinhard
17.24.2021 1c9178997dd15d65b5f84b4870b3e54caa30ff61
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
#!/bin/bash
 
# https://stackoverflow.com/questions/41451159/how-to-execute-a-script-when-i-terminate-a-docker-container
 
PROCESS_IDENTIFIER="de.micromata.borgbutler.server.Main"
APP_NAME="BorgButler"
 
#Define cleanup procedure
cleanup() {
  echo "Container stopped, performing cleanup..."
 
  pid=$(pgrep -f $PROCESS_IDENTIFIER)
  if [[ -z $pid ]]; then
    echo "${APP_NAME} process not found."
    exit 0
  else
    echo "Sending shutdown signal to $APP_NAME..."
    kill $pid
  fi
 
  echo "waiting 5 sec for termination of pid $pid..."
  sleep 5
 
  pid=$(pgrep -f $PROCESS_IDENTIFIER)
  if [[ -z $pid ]]; then
    echo "${APP_NAME} stopped"
    exit 0
  else
    echo "${APP_NAME} not stopped, now sending sigkill"
    kill -9 $pid
  fi
 
  sleep 0.5
 
  pid=$(pgrep -f $PROCESS_IDENTIFIER)
  if [[ -z $pid ]]; then
    echo "${APP_NAME} killed"
    exit 0
  else
    echo "${APP_NAME} could not be killed"
    exit 1
  fi
}
 
echo "Starting ${APP_NAME}..."
 
#Trap SIGTERM
trap cleanup INT SIGTERM
 
echo "Starting java ${JAVA_OPTS} -cp app/web/*:app/lib/* -DBorgButlerHome=/BorgButler/ -DapplicationHome=/app -DbindAddress=0.0.0.0 -DallowedClientIps=172.17. de.micromata.borgbutler.server.Main -q ${JAVA_ARGS}"
 
java $JAVA_OPTS -cp app/web/*:app/lib/* -DborgbutlerHome=/BorgButler/ -DapplicationHome=/app -DbindAddress=0.0.0.0 -DallowedClientIps=172.17. de.micromata.borgbutler.server.Main -q $JAVA_ARGS &
 
CHILD=$!
wait $CHILD
 
echo "$APP_NAME terminated."
#wait $!
 
#Cleanup
#cleanup Not needed, Java process already terminated.