Fuegovic commited on
Commit
c92b350
·
1 Parent(s): 9521fff

Update restart.sh

Browse files
Files changed (1) hide show
  1. restart.sh +18 -17
restart.sh CHANGED
@@ -1,32 +1,33 @@
1
  #!/bin/bash
2
 
3
- # Copy the secret config.json in place
4
- if [ -f /run/secrets/CONFIG_JSON ]; then
5
- cp /run/secrets/CONFIG_JSON ./config.json
6
- else
7
- echo "CONFIG_JSON secret not found. Service might not start correctly."
8
- fi
9
-
10
- # Set appropriate permissions
11
- chmod 777 config.json
12
-
13
- # Execute the main command in the background
14
  ./PandoraNext &
15
  PANDORA_PID=$!
16
 
17
- # Function to restart the PandoraNext service
18
  restart_service() {
19
- echo "Restarting PandoraNext..."
20
- kill $PANDORA_PID
 
 
21
  wait $PANDORA_PID
 
22
  ./PandoraNext &
23
  PANDORA_PID=$!
24
  }
25
 
26
- # Trap SIGTERM to handle graceful shutdown
27
- trap "kill $PANDORA_PID; wait $PANDORA_PID; exit 0" SIGTERM
 
 
 
 
 
 
 
 
28
 
29
- # Main loop to wait for one hour before restarting
30
  while true; do
31
  sleep 3600
32
  restart_service
 
1
  #!/bin/bash
2
 
3
+ # Start the PandoraNext service in the background
 
 
 
 
 
 
 
 
 
 
4
  ./PandoraNext &
5
  PANDORA_PID=$!
6
 
7
+ # Restart service function
8
  restart_service() {
9
+ echo "Restarting PandoraNext service..."
10
+ # Gracefully stop the PandoraNext service
11
+ kill -SIGTERM $PANDORA_PID
12
+ # Wait for the process to end before restarting
13
  wait $PANDORA_PID
14
+ # Start the PandoraNext service again
15
  ./PandoraNext &
16
  PANDORA_PID=$!
17
  }
18
 
19
+ # SIGTERM-handler for script termination
20
+ term_handler() {
21
+ echo "Stopping PandoraNext service..."
22
+ kill -SIGTERM $PANDORA_PID
23
+ wait $PANDORA_PID
24
+ exit 0
25
+ }
26
+
27
+ # Trap SIGTERM signal for graceful shutdown
28
+ trap 'term_handler' SIGTERM
29
 
30
+ # Main loop to sleep for one hour then restart the service
31
  while true; do
32
  sleep 3600
33
  restart_service