-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart.sh
executable file
·99 lines (76 loc) · 2.45 KB
/
start.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/bin/bash
mkdir -p ./logs
HELP="
Usage: ./start.sh [service] [service] ...
Where: [service] = the main python file for the service to start in the
form of a relative path from the root of the project to the src/*.py file.
If no services are specified, all services listed in services.cfg will be started.
Services will be started in the order they are listed in the file.
Example: ./start.sh src/central_hub.py src/strongarm.py
"
if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
echo "$HELP"
exit 0
fi
# user=`echo $USER`
# if [ "$user" != "root" ]; then
# echo "Script must be run as root. Try 'sudo ./start.sh'"
# exit 1
# fi
declare -a to_start=()
export LOG_ALL_MESSAGES=1
if [ "$STRONGARM_ENV" == "test" ]; then
export ARM_CONFIGS_DIR="./tests/fixtures/arm-configs"
export ARM_PARTS_DIR="./tests/fixtures/arm-parts"
fi
if [ $# -ne 0 ]; then
to_start=($@)
sleep=0
else
# TODO : # this is mostly needed for starting central hub which needs to start to
# the point of getting it's web socket server running before other services start
sleep=2
# read all lines from ./services.cfg into to_start without
# using readarray because it doesn't work on mac
while read line; do
#echo "read line: $line"
# skip comments
if [[ ${line:0:1} == "#" ]]; then
continue
fi
to_start+=("$line")
done < ./services.cfg
fi
# echo "to_start: ${to_start[@]}"
# source .env
arraylength=${#to_start[@]}
echo "starting $arraylength services"
for (( i=0; i<${arraylength}; i++ ));
do
sub_system=${to_start[i]}
echo "starting $sub_system"
base_name=$(basename $sub_system)
logfile="./logs/$base_name.log"
pid_file="./$base_name.pid"
if [ "$STRONGARM_ENV" == "test" ]; then
echo "running $sub_system in test mode"
append=$STRONGARM_FILE_APPEND
logfile="./logs/test_$base_name$append.log"
pid_file="./test_$base_name$append.pid"
fi
if [ -f "$logfile" ]; then
mv -f "$logfile" "$logfile".1
fi
if [ -f "./$pid_file" ]; then
echo "cowardly refusing to overwrite existing pid file for $sub_system ($pid_file)"
echo "please stop the service first"
continue
fi
echo "starting $sub_system at $(date)" >> "$logfile"
python3 $sub_system > $logfile 2>&1 &
echo $! > ./$pid_file
if [[ $sleep -gt 0 ]]; then
echo "sleeping for $sleep seconds"
sleep $sleep
fi
done