forked from DroneBridge/DroneBridge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart_db
129 lines (118 loc) · 3.66 KB
/
start_db
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
#!/bin/bash
### BEGIN INIT INFO
# Provides: start DroneBridge
# Required-Start: $remote_fs $syslog $local_fs
# Required-Stop:
# Should-Start: $network
# Should-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 3 5
# Short-Description: DroneBridge startup script
# Description: Helper & auto start script for DroneBridge. Placed in /etc/init.d/ to handle DroneBridge on system boot
### END INIT INFO
declare -a DBModuleNames=("osd" "video_air" "video_gnd" "db_pi_player" "db_pi_player_30" "db_pi_player_48"
"db_pi_player_240" "db_status" "db_proxy" "control_air" "control_ground" "db_communication_air.py"
"db_communication_gnd.py" "init_wifi.py" "start_db_modules.py" "usbbridge" "db_syslog_server" "db_recorder")
RED='\033[0;31m'
GRN='\033[1;32m'
NC='\033[0m' # No Color
function start_osd() {
echo
dos2unix -n /DroneBridge/osdconfig.txt /DroneBridge/osdconfig.txt
echo
cd /home/pi/DroneBridge/osd
echo Building OSD:
make -j2 || {
echo -e "${RED}ERROR: Could not build OSD, check osdconfig.txt!${NC}"
}
cd /tmp
./osd &
}
function stop_db_modules() {
echo "Stopping DroneBridge modules"
for DB_MODULE in ${DBModuleNames[@]}; do
pkill -f "$DB_MODULE"
done
}
function init_dronebridge() {
logrotate -f /etc/logrotate.conf
/home/pi/DroneBridge/syslog_server/db_syslog_server &
if vcgencmd get_throttled | nice grep -q -v "0x0"; then
TEMP=$(cat /sys/class/thermal/thermal_zone0/temp)
TEMP_C=$(($TEMP / 1000))
if [[ "$TEMP_C" -lt 75 ]]; then # it must be under-voltage
mount -o remount,ro /boot
echo "1" >/tmp/undervolt
echo -e "${RED}Under-voltage detected. Please check your power supply!${NC}"
else
echo "0" >/tmp/undervolt
fi
else
echo "0" >/tmp/undervolt
fi
CAM=$(/usr/bin/vcgencmd get_camera | nice grep -c detected=1)
echo "Building DroneBridge modules..." # enables optimizations for specific targets
cd /home/pi/DroneBridge
# Check for last compile target (may need to recompile to get advantage of NEON SIMD)
CPU_ARCHITECTURE=$(uname -m)
COMPILE_TARGET_FILE=.compile_target
LAST_COMPILE_TARGET=$(head -n 1 "$COMPILE_TARGET_FILE")
if [[ -f "$COMPILE_TARGET_FILE" ]] && [[ "$LAST_COMPILE_TARGET" = "$CPU_ARCHITECTURE" ]]; then
echo "DroneBridge is already compiled for the CPU architecture"
else
# Force recompilation in case we are having a different CPU
echo "Re-Compiling DroneBridge..."
CPU_CORES=$(nproc)
rm CMakeCache.txt
cmake .
make -j"$CPU_CORES"
echo "Compilation done"
rm "$COMPILE_TARGET_FILE"
uname -m > "$COMPILE_TARGET_FILE"
fi
DB_VERSION_STR=$(head -n 1 /home/pi/DroneBridge/db_version.txt)
if [[ "$CAM" == "0" ]]; then
echo "Welcome to DroneBridge v"$DB_VERSION_STR" Beta (GND) - "
python3 /home/pi/DroneBridge/startup/init_wifi.py -g
sleep 1
python3 /home/pi/DroneBridge/startup/start_db_modules.py -g
start_osd
else
echo "Welcome to DroneBridge v"$DB_VERSION_STR" Beta (UAV) - "
python3 /home/pi/DroneBridge/startup/init_wifi.py
sleep 1
python3 /home/pi/DroneBridge/startup/start_db_modules.py
fi
}
case "$1" in
start)
init_dronebridge
;;
stop)
stop_db_modules
;;
restart)
stop_db_modules
start_db_modules
;;
force-reload)
stop_db_modules
init_dronebridge
;;
status)
echo "Status of DroneBridge applications"
for DB_MODULE in ${DBModuleNames[@]}; do
if pgrep -f "$DB_MODULE" >/dev/null
then
echo -e "$DB_MODULE ${GRN}running${NC}"
else
echo -e "$DB_MODULE ${RED}stopped${NC}"
fi
done
;;
*)
echo "Usage: /etc/init.d/start_db {start|stop|restart|force-reload|status}"
exit 1
;;
esac
exit 0