-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.sh
47 lines (37 loc) · 1.07 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
#!/bin/bash
# Function to cleanly shut down processes
cleanup() {
echo "Caught Signal... terminating Apache ($APACHE_PID) and patchman ($PATCHMAN_PID) gracefully!"
# Kill the Apache process
kill -TERM $APACHE_PID
# Kill the patchman process
kill -TERM $PATCHMAN_PID
exit 0
}
# Trap SIGTERM, SIGINT and exit signals
trap cleanup SIGTERM SIGINT EXIT
echo "running migrations..."
patchman-manage migrate
echo "Starting Apache2..."
# Starts apache2ctl in the foreground
apache2ctl -D FOREGROUND &
# Apache process ID
APACHE_PID=$!
# Function to run patchman in the background periodically
run_patchman() {
while true; do
# Run patchman command
patchman -a
# Wait for 10min (600 seconds) before running again
sleep 600
done
}
echo "starting patchman processing loop..."
# Start the patchman function in the background
run_patchman &
# Capture the process ID of the background job
PATCHMAN_PID=$!
# Wait for Apache to exit
wait $APACHE_PID
# Once Apache exits, kill the background patchman job if still running
kill $PATCHMAN_PID