forked from ApolloAuto/apollo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapollo_base.sh
executable file
·210 lines (181 loc) · 5.12 KB
/
apollo_base.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#!/usr/bin/env bash
###############################################################################
# Copyright 2017 The Apollo Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
###############################################################################
APOLLO_ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )"
START_TIME=$(($(date +%s%N)/1000000))
TIME=$(date +%Y%m%d_%H%M)
RED='\033[0;31m'
YELLOW='\e[33m'
NO_COLOR='\033[0m'
function info() {
(>&2 echo -e "[\e[34m\e[1mINFO\e[0m] $*")
}
function error() {
(>&2 echo -e "[${RED}ERROR${NO_COLOR}] $*")
}
function warning() {
(>&2 echo -e "[${YELLOW}WARNING${NO_COLOR}] $*")
}
function ok() {
(>&2 echo -e "[\e[32m\e[1m OK \e[0m] $*")
}
function print_delim() {
echo '============================'
}
print_time() {
END_TIME=$(($(date +%s%N)/1000000))
ELAPSED_TIME=$(echo "scale=3; ($END_TIME - $START_TIME) / 1000" | bc -l)
MESSAGE="Took ${ELAPSED_TIME} seconds"
info "${MESSAGE}"
}
function success() {
print_delim
ok "$1"
print_time
print_delim
}
function fail() {
print_delim
error "$1"
print_time
print_delim
exit -1
}
agreement_record="$HOME/.apollo_agreement.txt"
if [ ! -e "$agreement_record" ]; then
AGREEMENT_FILE="$APOLLO_ROOT_DIR/scripts/AGREEMENT.txt"
if [ ! -e "$AGREEMENT_FILE" ]; then
error "AGREEMENT $AGREEMENT_FILE does not exist."
exit 0
fi
cat $AGREEMENT_FILE
tip="Type 'y' or 'Y' to agree to the license agreement above, or type any other key to exit"
echo $tip
read -n 1 user_agreed
if [ "$user_agreed" == "y" ] || [ "$user_agreed" == "Y" ]; then
rm -rf $agreement_record
cat $AGREEMENT_FILE >> $agreement_record
echo "$tip" >> $agreement_record
echo "$user_agreed" >> $agreement_record
else
exit 0
fi
fi
if [ -f /.dockerenv ]; then
APOLLO_IN_DOCKER=true
else
APOLLO_IN_DOCKER=false
fi
if [ "$RELEASE_DOCKER" == 1 ];then
source /apollo/ros/setup.bash
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/apollo/lib
export PYTHONPATH=/apollo/lib:${PYTHONPATH}
else
if [ -e "${APOLLO_ROOT_DIR}/bazel-apollo/external/ros/setup.bash" ]; then
source "${APOLLO_ROOT_DIR}/bazel-apollo/external/ros/setup.bash"
fi
export PYTHONPATH=${APOLLO_ROOT_DIR}/bazel-genfiles:${PYTHONPATH}
fi
if [ ! -e "${APOLLO_ROOT_DIR}/data/log" ]; then
mkdir -p "${APOLLO_ROOT_DIR}/data/log"
fi
if [ ! -e "${APOLLO_ROOT_DIR}/data/bag" ]; then
mkdir -p "${APOLLO_ROOT_DIR}/data/bag"
fi
if [ ! -e "${APOLLO_ROOT_DIR}/data/core" ]; then
mkdir -p "${APOLLO_ROOT_DIR}/data/core"
fi
APOLLO_BIN_PREFIX=$APOLLO_ROOT_DIR
if [ -e "${APOLLO_ROOT_DIR}/bazel-bin" ]; then
APOLLO_BIN_PREFIX="${APOLLO_ROOT_DIR}/bazel-bin"
fi
export APOLLO_BIN_PREFIX
export APOLLO_IN_DOCKER
function is_stopped() {
MODULE=${1}
NUM_PROCESSES="$(pgrep -c -f "modules/${MODULE}/${MODULE}")"
if [ "${NUM_PROCESSES}" -eq 0 ]; then
return 1
else
return 0
fi
}
function start() {
MODULE=$1
LOG="${APOLLO_ROOT_DIR}/data/log/${MODULE}.out"
is_stopped "${MODULE}"
if [ $? -eq 1 ]; then
eval "nohup ${APOLLO_BIN_PREFIX}/modules/${MODULE}/${MODULE} \
--flagfile=modules/${MODULE}/conf/${MODULE}.conf \
--log_dir=${APOLLO_ROOT_DIR}/data/log </dev/null >${LOG} 2>&1 &"
is_stopped "${MODULE}"
if [ $? -eq 0 ]; then
echo "Launched module ${MODULE}."
return 0
else
echo "Could not launch module ${MODULE}. Is it already built?"
return 1
fi
else
echo "Module ${MODULE} is already running - skipping."
return 2
fi
}
function start_fe() {
MODULE=$1
eval "${APOLLO_BIN_PREFIX}/modules/${MODULE}/${MODULE} \
--flagfile=modules/${MODULE}/conf/${MODULE}.conf \
--log_dir=${APOLLO_ROOT_DIR}/data/log"
}
function stop() {
MODULE=$1
pkill -SIGINT -f "modules/${MODULE}/${MODULE}"
if [ $? -eq 0 ]; then
echo "Successfully stopped module ${MODULE}."
else
echo "Module ${MODULE} is not running - skipping."
fi
}
function print_usage() {
echo "Usage:
./$0 [COMMAND]"
echo "COMMAND:
help: this help message
start: start the module in background
start_fe: start the module without putting in background
stop: stop the module
"
}
# run command_name module_name
function run() {
case $1 in
start)
start "$2"
;;
start_fe)
start_fe "$2"
;;
stop)
stop "$2"
;;
help)
print_usage
;;
*)
start "$2"
;;
esac
}