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

Kai Reinhard
20.23.2021 314107f3a3a54921a448672d8066dea470ea60cc
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
#!/bin/bash
 
# https://stackoverflow.com/questions/41451159/how-to-execute-a-script-when-i-terminate-a-docker-container
 
JAVA_MAIN="de.micromata.borgbutler.server.BorgButlerApplication"
APP_NAME="BorgButler"
 
#Define cleanup procedure
cleanup() {
  echo "Container stopped, performing cleanup..."
 
  pid=$(pgrep -f $JAVA_MAIN)
  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 $JAVA_MAIN)
  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 $JAVA_MAIN)
  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}..."
 
ENVIRONMENT_FILE=/BorgButler/environment.sh
if [ -f "$ENVIRONMENT_FILE" ]; then
  echo "Sourcing $ENVIRONMENT_FILE..."
  . $ENVIRONMENT_FILE
fi
 
if [ -n "$JAVA_OPTS" ]; then
  echo "JAVA_OPTS=${JAVA_OPTS}"
fi
 
if [ -n "$JAVA_ARGS" ]; then
  echo "JAVA_ARGS=${JAVA_ARGS}"
fi
 
#Trap SIGTERM
trap cleanup INT SIGTERM
 
START="${JAVA_OPTS} -cp app/web/*:app/lib/* -DBorgButlerHome=/BorgButler/ -Dserver.address=0.0.0.0 -Ddocker=true ${JAVA_MAIN} ${JAVA_ARGS}"
 
echo "Starting: java ${START}"
 
java $START &
 
CHILD=$!
wait $CHILD
 
echo "$APP_NAME terminated."
#wait $!
 
#Cleanup
#cleanup Not needed, Java process already terminated.