-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrestart_plan.sh
More file actions
executable file
·53 lines (45 loc) · 1.32 KB
/
restart_plan.sh
File metadata and controls
executable file
·53 lines (45 loc) · 1.32 KB
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
#!/bin/bash
# Usage: ./restart_plan.sh
PID=$(pgrep -f "python.*restart_plan\.py$")
if [ -n "$PID" ]; then
echo "ERROR: restart_plan.py is already running"
exit 1
fi
CONFIG_FILE="plans/migration.yml"
if [ ! -f "$CONFIG_FILE" ]; then
echo "ERROR: Migration plan YAML file ($CONFIG_FILE) not found"
exit 1
fi
RESTART_GRACE=$(grep 'restartGrace:' "$CONFIG_FILE" | awk -F': ' '{print $2}')
if [ -z "$RESTART_GRACE" ]; then
echo "ERROR: Could not find ups.restartGrace value in $CONFIG_FILE"
exit 1
fi
echo "Waiting $RESTART_GRACE seconds before restarting..."
sleep "$RESTART_GRACE"
PID=$(pgrep -f "python.*migration_plan\.py$")
if [ -n "$PID" ]; then
echo "Killing migration_plan.py (PID $PID)..."
kill "$PID"
sleep 2
if kill -0 "$PID" 2>/dev/null; then
echo "Process $PID still running, forcing termination..."
kill -9 "$PID"
fi
fi
if [ ! -f .venv/bin/activate ]; then
echo "ERROR: Virtual environment not found at .venv/bin/activate"
exit 1
fi
source .venv/bin/activate || {
echo "ERROR: Failed to activate virtual environment"
exit 1
}
if [[ "$VIRTUAL_ENV" != "$(pwd)/.venv"* ]]; then
echo "ERROR: Activated an unexpected virtual environment ($VIRTUAL_ENV)"
exit 1
fi
if ! python restart_plan.py; then
echo "ERROR: Failed to start restart_plan.py"
exit 1
fi