Skip to content

Commit c8da916

Browse files
committed
semi auto installation setup for rpi
1 parent eaafd0d commit c8da916

File tree

5 files changed

+100
-25
lines changed

5 files changed

+100
-25
lines changed

shellscript/setup_yun2inf.sh

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,15 @@ echo 'This will help you setup your Yun2inf Docker Network'
77
echo '6 containers: 1) Database Container 2) FROST-Server Container 3) Grafana Container 4)yun2inf_proj 5)BIMServer 6)nginx'
88
echo '------------------------------------------------------'
99
#---------------------------------------------------------
10+
# AMD64 or ARM64
11+
#---------------------------------------------------------
12+
echo 'Is this an amd64 or arm64 Machine'
13+
read -p "(default=amd64): " ARCH
14+
ARCH=${ARCH:-amd64}
15+
#---------------------------------------------------------
1016
# POSTGRES
1117
#---------------------------------------------------------
18+
echo
1219
echo 'Enter DB Container Name'
1320
read -p "(default=spatempdb): " CONTAINERNAME1
1421
CONTAINERNAME1=${CONTAINERNAME1:-spatempdb}
@@ -102,6 +109,7 @@ NPORT=${NPORT:-80}
102109

103110
#PRINT SETTING
104111
echo '---------------------------------'
112+
echo 'Machine Architecture:' $ARCH
105113
echo 'Container Name1:' $CONTAINERNAME1
106114
echo 'DBPort: ' $DBPORT
107115
echo 'Username: ' $DBUSER
@@ -216,7 +224,7 @@ docker run -d --name "$CONTAINERNAME1"\
216224
-e "POSTGRES_PASSWORD=$DBPASSWORD"\
217225
-e "POSTGRES_DB=$DBNAME"\
218226
-v "spatempdb_volume:/var/lib/postgresql/data"\
219-
chenkianwee/timescale-3dcitydb:2.20.3-5.0.0
227+
chenkianwee/timescale-3dcitydb:a-2.20.3-5.0.0
220228

221229
echo '------------------------------------------------------'
222230
echo 'Trying to start FROST-Server Container ...'
@@ -251,26 +259,6 @@ docker run -d --name "$CONTAINERNAME2"\
251259
-e "plugins.openApi.enable=true"\
252260
fraunhoferiosb/frost-server:2.6
253261

254-
#wait for abit before reconfiguring the FROST-server
255-
echo '------------------------------------------------------'
256-
echo 'Configuring the database container ... '
257-
echo '------------------------------------------------------'
258-
TOTAL=30
259-
TIME=0
260-
while [ $TIME -le $TOTAL ]
261-
do
262-
echo "Configuring database, wait for $TOTAL seconds ... $TIME seconds"
263-
TIME=$(($TIME + 10))
264-
sleep 10
265-
done
266-
267-
#docker exec -it "$CONTAINERNAME1" psql -U "$DBUSER" -d "$DBNAME" -c 'CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE;'
268-
docker exec -it "$CONTAINERNAME1" psql -U "$DBUSER" -d "$DBNAME" -c "ALTER TABLE \"OBSERVATIONS\" DROP CONSTRAINT \"OBSERVATIONS_pkey\";"
269-
docker exec -it "$CONTAINERNAME1" psql -U "$DBUSER" -d "$DBNAME" -c "SELECT create_hypertable('\"OBSERVATIONS\"','PHENOMENON_TIME_START',chunk_time_interval => interval '7 days');"
270-
docker exec -it "$CONTAINERNAME1" psql -U "$DBUSER" -d "$DBNAME" -c "CREATE INDEX \"OBSERVATIONS_pkey\" ON \"OBSERVATIONS\" USING btree(\"ID\");"
271-
docker exec -it "$CONTAINERNAME1" psql -U "$DBUSER" -d "$DBNAME" -c "CREATE INDEX \"OBS-DS_ID-PHTIME_SE-O_ID\" on \"OBSERVATIONS\" using btree(\"DATASTREAM_ID\",\"PHENOMENON_TIME_START\" asc, \"PHENOMENON_TIME_END\" asc);"
272-
docker exec -it "$CONTAINERNAME1" psql -U "$DBUSER" -d "$DBNAME" -c "ALTER TABLE \"OBSERVATIONS\" ADD PRIMARY KEY (\"ID\", \"PHENOMENON_TIME_START\");"
273-
274262
echo '------------------------------------------------------'
275263
echo 'Trying to start grafana container now ...'
276264
echo '------------------------------------------------------'
@@ -324,6 +312,36 @@ docker exec -it "$CONTAINERNAME6" rm /etc/nginx/conf.d/default.conf
324312
docker restart "$CONTAINERNAME6"
325313
mv yun2inf.conf ../nginx/yun2inf.conf
326314

315+
#wait for abit before reconfiguring the FROST-server
316+
echo '------------------------------------------------------'
317+
echo 'Configuring the database container ... '
318+
echo '------------------------------------------------------'
319+
if [ $ARCH = "amd64" ]; then
320+
echo "Automated timescale setup for amd64 machine"
321+
TOTAL=30
322+
TIME=0
323+
while [ $TIME -le $TOTAL ]
324+
do
325+
echo "Configuring database, wait for $TOTAL seconds ... $TIME seconds"
326+
TIME=$(($TIME + 10))
327+
sleep 10
328+
done
329+
330+
#docker exec -it "$CONTAINERNAME1" psql -U "$DBUSER" -d "$DBNAME" -c 'CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE;'
331+
docker exec -it "$CONTAINERNAME1" psql -U "$DBUSER" -d "$DBNAME" -c "ALTER TABLE \"OBSERVATIONS\" DROP CONSTRAINT \"OBSERVATIONS_pkey\";"
332+
docker exec -it "$CONTAINERNAME1" psql -U "$DBUSER" -d "$DBNAME" -c "SELECT create_hypertable('\"OBSERVATIONS\"','PHENOMENON_TIME_START',chunk_time_interval => interval '7 days');"
333+
docker exec -it "$CONTAINERNAME1" psql -U "$DBUSER" -d "$DBNAME" -c "CREATE INDEX \"OBSERVATIONS_pkey\" ON \"OBSERVATIONS\" USING btree(\"ID\");"
334+
docker exec -it "$CONTAINERNAME1" psql -U "$DBUSER" -d "$DBNAME" -c "CREATE INDEX \"OBS-DS_ID-PHTIME_SE-O_ID\" on \"OBSERVATIONS\" using btree(\"DATASTREAM_ID\",\"PHENOMENON_TIME_START\" asc, \"PHENOMENON_TIME_END\" asc);"
335+
docker exec -it "$CONTAINERNAME1" psql -U "$DBUSER" -d "$DBNAME" -c "ALTER TABLE \"OBSERVATIONS\" ADD PRIMARY KEY (\"ID\", \"PHENOMENON_TIME_START\");"
336+
elif [ $ARCH = "arm64" ]; then
337+
echo "Instructions for arm64 machine to complete your timescale setup"
338+
echo "For Raspberry Pi Installation, make sure your FROST-Server is working with your Postgresql before installing TimescaleDB"
339+
echo "Visit https://chenkianwee.github.io/yun2infinity/docs/020/020installation.html#check-if-frost-server-is-successfully-configured to check if your FROST-server and postgresql is running properly"
340+
echo "Run the tsdb4rpi.sh to install timescale with the following command: sudo sh tscitydb4rpi.sh"
341+
else
342+
echo "Unsupported Machine Type"
343+
fi
344+
327345
echo '------------------------------------------------------'
328-
echo 'Successfully installed yun2infinity'
346+
echo 'End of Setup'
329347
echo '------------------------------------------------------'

shellscript/tsdb4rpi.sh

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#wait for abit before reconfiguring the FROST-server
2+
echo '------------------------------------------------------'
3+
echo 'Configuring the database container ... '
4+
echo '------------------------------------------------------'
5+
echo
6+
echo 'Enter DB Container Name'
7+
read -p "(default=spatempdb): " CONTAINERNAME1
8+
CONTAINERNAME1=${CONTAINERNAME1:-spatempdb}
9+
#DBUSER
10+
echo
11+
echo 'Enter User for Database'
12+
read -p "(default=postgres): " DBUSER
13+
DBUSER=${DBUSER:-postgres}
14+
#DBNAME
15+
echo
16+
echo 'Enter Name for the Database'
17+
read -p "(default=spatempdb): " DBNAME
18+
DBNAME=${DBNAME:-spatempdb}
19+
20+
# install timescaledb (https://docs.tigerdata.com/self-hosted/latest/install/installation-linux/)
21+
# timescaledb tuning tool (https://docs.tigerdata.com/self-hosted/latest/configuration/timescaledb-tune/)
22+
docker exec -u root "$CONTAINERNAME1" bash -c 'echo "deb https://packagecloud.io/timescale/timescaledb/debian/ $(lsb_release -c -s) main" | tee /etc/apt/sources.list.d/timescaledscaledb.list'
23+
docker exec -u root "$CONTAINERNAME1" bash -c 'wget --quiet -O - https://packagecloud.io/timescale/timescaledb/gpgkey | gpg --dearmor -o /etc/apt/trusted.gpg.d/timescaledb.gpg'
24+
docker exec -it -u root "$CONTAINERNAME1" apt-get update
25+
docker exec -it -u root "$CONTAINERNAME1" apt-get install -y timescaledb-2-postgresql-17=2.20.3~debian12
26+
docker exec -it -u root "$CONTAINERNAME1" timescaledb-tune --quiet --yes
27+
docker exec -u root spatempdb bash -c "echo \"shared_preload_libraries = 'timescaledb,pg_cron'\" >> /etc/postgresql/17/main/postgresql.conf"
28+
docker restart "$CONTAINERNAME1"
29+
30+
TOTAL=30
31+
TIME=0
32+
while [ $TIME -le $TOTAL ]
33+
do
34+
echo "Configuring database, wait for $TOTAL seconds ... $TIME seconds"
35+
TIME=$(($TIME + 10))
36+
sleep 10
37+
done
38+
39+
docker exec -it -u "$DBUSER" "$CONTAINERNAME1" psql -U "$DBUSER" -d "$DBNAME" -c 'CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE;'
40+
docker exec -it -u "$DBUSER" "$CONTAINERNAME1" psql -U "$DBUSER" -d "$DBNAME" -c "ALTER TABLE \"OBSERVATIONS\" DROP CONSTRAINT \"OBSERVATIONS_pkey\";"
41+
docker exec -it -u "$DBUSER" "$CONTAINERNAME1" psql -U "$DBUSER" -d "$DBNAME" -c "SELECT create_hypertable('\"OBSERVATIONS\"','PHENOMENON_TIME_START',chunk_time_interval => interval '7 days');"
42+
docker exec -it -u "$DBUSER" "$CONTAINERNAME1" psql -U "$DBUSER" -d "$DBNAME" -c "CREATE INDEX \"OBSERVATIONS_pkey\" ON \"OBSERVATIONS\" USING btree(\"ID\");"
43+
docker exec -it -u "$DBUSER" "$CONTAINERNAME1" psql -U "$DBUSER" -d "$DBNAME" -c "CREATE INDEX \"OBS-DS_ID-PHTIME_SE-O_ID\" on \"OBSERVATIONS\" using btree(\"DATASTREAM_ID\",\"PHENOMENON_TIME_START\" asc, \"PHENOMENON_TIME_END\" asc);"
44+
docker exec -it -u "$DBUSER" "$CONTAINERNAME1" psql -U "$DBUSER" -d "$DBNAME" -c "ALTER TABLE \"OBSERVATIONS\" ADD PRIMARY KEY (\"ID\", \"PHENOMENON_TIME_START\");"
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
FROM timescale/timescaledb-ha:pg17.5-ts2.20.3-all-oss
1+
FROM timescale/timescaledb-ha:pg17.5-ts2.20.3-oss
22
LABEL maintainer="chenkianwee chenkianwee@gmail.com"
3-
3+
# the timescaledb-ha docker image is not working for rpi although it is suppose to
44
USER root
55
RUN apt-get update
66
RUN apt-get -y upgrade
@@ -11,5 +11,5 @@ RUN wget https://github.com/3dcitydb/3dcitydb/releases/download/v5.0.0/3dcitydb-
1111
RUN unzip 3dcitydb-5.0.0.zip
1212
RUN rm 3dcitydb-5.0.0.zip
1313

14-
COPY create_extension_postgis_ext.sh /docker-entrypoint-initdb.d
14+
# COPY create_extension_postgis_ext.sh /docker-entrypoint-initdb.d
1515
USER postgres

timescale-3dcitydb/create_extension_postgis_ext.sh renamed to timescale-3dcitydb/tscity_amd64/create_extension_postgis_ext.sh

File renamed without changes.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM kartoza/postgis:17-3.5
2+
LABEL maintainer="chenkianwee chenkianwee@gmail.com"
3+
# the timescaledb-ha docker image is not working for rpi although it is suppose to
4+
# thus i have to build my own image for rpi
5+
USER root
6+
RUN apt-get update
7+
# RUN apt-get -y upgrade
8+
RUN apt-get -y install wget
9+
RUN apt-get -y install unzip
10+
RUN apt-get -y install nano
11+
RUN wget https://github.com/3dcitydb/3dcitydb/releases/download/v5.0.0/3dcitydb-5.0.0.zip
12+
RUN unzip 3dcitydb-5.0.0.zip
13+
RUN rm 3dcitydb-5.0.0.zip

0 commit comments

Comments
 (0)