-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_sensors.sh
More file actions
executable file
·134 lines (120 loc) · 3.76 KB
/
run_sensors.sh
File metadata and controls
executable file
·134 lines (120 loc) · 3.76 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
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
#!/bin/bash
help() {
echo "Usage: run_sensors.sh [options] [sensor_list]
Options:
--local Use the 'local_sensors_compose.yaml' file
--build Build Docker images for the specified sensors
--no-cache Build Docker images with no cache
--ros-time Use internal ROS timestamps for lidar msgs (i.e. not GPS/PPS)
Only activated if --local is defined
-h, --help Show this help message and exit
"
exit 0
}
# Function to handle termination
stop_sensors() {
echo "Caught signal, stopping Docker Compose..."
docker compose -f "$compose_file" kill
docker compose -f "$compose_file" down
exit 0
}
# Trap SIGINT and SIGTERM
trap 'stop_sensors' SIGINT SIGTERM
# Default values
compose_file="./sensors_compose.yaml"
services=""
build_docker=""
run_action_count=0 # Counter to track --local and --build
build_no_cache=""
ros_time="False"
run_local="False"
while [[ $# -gt 0 ]]; do
case $1 in
--local)
run_local="True"
((run_action_count++)) # Increment counter for --local
shift
;;
--build)
build_docker="True"
((run_action_count++)) # Increment counter for --build
shift
;;
--no-cache)
build_no_cache="--no-cache"
shift
;;
--ros-time)
ros_time="True"
shift
;;
-h|--help)
help
;;
*)
services="$services $1"
shift
;;
esac
done
# Create logs directory
SCRIPT_DIR=$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")
mkdir -p "$SCRIPT_DIR/logs"
# Restart license checking service as it sometimes gets stuck
sudo /bin/systemctl restart codemeter.service
build_docker_images() {
original_dir=$(pwd) # Save the original directory
for service in $services; do
found=0
# Search recursively for directories matching the service name
for dir in $(find . -type d -name "$service"); do
# Check for Dockerfile in the directory
if [[ -f "$dir/Dockerfile" ]]; then
echo "Building Docker image for $service..."
pushd "$dir" > /dev/null # Change to the directory containing the Dockerfile
docker build $build_no_cache -t "$service:latest" --target runtime .
popd > /dev/null # Return to the original directory
found=1
break
fi
done
# If no matching Dockerfile or directory is found
if [[ $found -eq 0 ]]; then
echo "No directory or Dockerfile found for $service."
fi
done
}
if [ "$run_local" == "True" ]; then
compose_file="./local_sensors_compose.yaml"
# Edit compose_file name if needed for ros_time version
if [ "$ros_time" == "True" ]; then
compose_file=${compose_file::-5}"_ros_time.yaml"
fi
fi
# If both --local and --build are provided, first build, then run Docker Compose
if [ "$run_action_count" -eq 2 ]; then
if [ -n "$services" ]; then
build_docker_images
docker compose -f "$compose_file" up $services &
else
echo "No services specified for building."
exit 1
fi
# If only --build is provided, build the Docker images but don't run services
elif [ -n "$build_docker" ]; then
if [ -n "$services" ]; then
build_docker_images
else
echo "No services specified for building."
exit 1
fi
# Default case: run Docker Compose with the defined compose file
else
if [ -n "$services" ]; then
docker compose -f "$compose_file" up $services &
else
docker compose -f "$compose_file" up &
fi
fi
# Wait for Docker Compose to finish
wait $!