-
Notifications
You must be signed in to change notification settings - Fork 0
/
random.sh
executable file
·55 lines (45 loc) · 1.23 KB
/
random.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
47
48
49
50
51
52
53
54
55
#!/bin/bash
# Check if the number of arguments is correct
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <number_of_runners>"
exit 1
fi
# Check if the argument is a number and within the range
if ! [[ "$1" =~ ^[1-5]$ ]]; then
echo "Error: The argument must be a number between 1 and 5."
exit 1
fi
# Source the .env file if it exists
if [ -f .env ]; then
echo "Sourcing .env file..."
source .env
else
echo "Warning: .env file not found. Proceeding without it."
fi
# Unset the RUNNER_NAME environment variable
unset RUNNER_NAME
# Create logs directory
mkdir -p logs
# Create actions directory
mkdir -p actions
# Define cleanup function to handle interruptions
cleanup() {
echo "Interrupt received, stopping all runners..."
kill "$(jobs -p)" 2>/dev/null
wait
echo "All runners stopped."
exit 1
}
# Trap SIGINT (Ctrl+C) and call cleanup
trap cleanup SIGINT
# Loop to start the specified number of runners
for ((i = 1; i <= $1; i++)); do
log_file="logs/runner_${i}.log"
echo "Starting runner $i, logging to $log_file"
ACTIONS_DIR="$(pwd)/actions/runner-${i}"
export ACTIONS_DIR
./src/start.sh > "$log_file" 2>&1 &
done
# Wait for all background processes to finish
wait
echo "Started $1 runners."