forked from luisera/openeew-detection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdetector
41 lines (31 loc) · 1.46 KB
/
detector
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
#!/usr/bin/env sh
set -em
initialized_check_file="/opt/openeew/.initialized"
su - postgres -c "PGDATA='/var/lib/postgresql/data' postgres" &
timeout 1m sh -c "until nc -z 127.0.0.1 5432; do sleep 1; done"
echo "🚀 PostgreSQL with TimescaleDB is ready"
mosquitto -c /opt/openeew/mosquitto.conf -d
timeout 1m sh -c "until nc -z 127.0.0.1 1883; do sleep 1; done"
echo "🚀 Mosquitto is ready"
if [ -f "${initialized_check_file}" ]; then
echo "✅ Already initialized, skipping initialization"
else
echo "⏲ Initializing..."
if [ -n "${username}" ] && [ -n "${password}" ]; then
echo "🔑 Using authentication"
touch /opt/openeew/mosquitto_passwords
mosquitto_passwd -b /opt/openeew/mosquitto_passwords "${username}" "${password}"
echo "password_file /opt/openeew/mosquitto_passwords" >> /opt/openeew/mosquitto.conf
else
echo "⚠ Not using authentication"
fi
su - postgres -c "createuser --login detector"
su - postgres -c "createdb --owner detector detector"
su - postgres -c "psql --username detector --dbname detector --file /opt/openeew/init_db.sql"
touch "${initialized_check_file}"
echo "✅ Initialized"
fi
watch -n 600 /usr/sbin/logrotate /etc/logrotate.d/* &
python3 /opt/openeew/receive_devices.py --username "${username}" --password "${password}" &
python3 /opt/openeew/receive_earthquakes.py --username "${username}" --password "${password}" &
python3 /opt/openeew/detection.py --username "${username}" --password "${password}"