Commit 7c3eee66dbbf2b4d7f579b88a8d4e8b3e58087c0

Authored by viktor
1 parent 72063a25

start tb-cassandra with 'thingsboard' user (with postgresql server)

... ... @@ -22,15 +22,13 @@ RUN echo 'deb http://apt.postgresql.org/pub/repos/apt/ stretch-pgdg main' | tee
22 22 RUN curl -L https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
23 23 RUN echo 'deb http://www.apache.org/dist/cassandra/debian 311x main' | tee --append /etc/apt/sources.list.d/cassandra.list > /dev/null
24 24 RUN curl -L https://www.apache.org/dist/cassandra/KEYS | apt-key add -
  25 +ENV PG_MAJOR=11
25 26 RUN apt-get update
26 27 RUN apt-get install -y cassandra cassandra-tools postgresql-11
27 28 RUN update-rc.d cassandra disable
28 29 RUN update-rc.d postgresql disable
29 30 RUN sed -i.old '/ulimit/d' /etc/init.d/cassandra
30 31
31   -RUN mkdir -p /var/log/postgres
32   -RUN chown -R postgres:postgres /var/log/postgres
33   -
34 32 COPY logback.xml ${pkg.name}.conf start-db.sh stop-db.sh start-tb.sh upgrade-tb.sh install-tb.sh ${pkg.name}.deb /tmp/
35 33
36 34 RUN chmod a+x /tmp/*.sh \
... ... @@ -58,26 +56,38 @@ ENV CASSANDRA_DATA=/data/cassandra
58 56 ENV SPRING_JPA_DATABASE_PLATFORM=org.hibernate.dialect.PostgreSQLDialect
59 57 ENV SPRING_DRIVER_CLASS_NAME=org.postgresql.Driver
60 58 ENV SPRING_DATASOURCE_URL=jdbc:postgresql://localhost:5432/thingsboard
61   -ENV SPRING_DATASOURCE_USERNAME=postgres
  59 +ENV SPRING_DATASOURCE_USERNAME=${pkg.user}
62 60 ENV SPRING_DATASOURCE_PASSWORD=postgres
63 61
64 62 ENV CASSANDRA_HOST=localhost
65 63 ENV CASSANDRA_PORT=9042
66 64 ENV CASSANDRA_HOME=/opt/cassandra
67   -ENV PATH $CASSANDRA_HOME/bin:$PATH
68 65
69   -RUN rm -rf /var/lib/cassandra
  66 +ENV PATH=$CASSANDRA_HOME/bin:$PATH
  67 +ENV PATH=$PATH:/usr/lib/postgresql/$PG_MAJOR/bin
  68 +
  69 +ENV PGLOG=/var/log/postgres
  70 +ENV CASSANDRA_LOG=/var/log/cassandra
  71 +
  72 +# postgres config
  73 +RUN mkdir -p $PGLOG
  74 +RUN chown -R ${pkg.user}:${pkg.user} $PGLOG
  75 +RUN chown -R ${pkg.user}:${pkg.user} /var/log/postgresql
  76 +RUN chown -R ${pkg.user}:${pkg.user} /var/run/postgresql
70 77
  78 +# cassandra config
  79 +RUN rm -rf /var/lib/cassandra
71 80 RUN chmod a+w /var/lib
  81 +RUN chown -R ${pkg.user}:${pkg.user} $CASSANDRA_LOG
  82 +
72 83
73 84 RUN mkdir -p $DATA_FOLDER
74   -RUN chown -R cassandra:cassandra /data
  85 +RUN chown -R ${pkg.user}:${pkg.user} $DATA_FOLDER
  86 +RUN chown -R ${pkg.user}:${pkg.user} /var/log/${pkg.name}
75 87
76   -RUN chown -R cassandra:cassandra /var/log/${pkg.name}
77 88 RUN chmod 555 ${pkg.installFolder}/bin/${pkg.name}.jar
78 89
79   -
80   -USER cassandra
  90 +USER ${pkg.user}
81 91
82 92 EXPOSE 9090
83 93 EXPOSE 1883
... ...
... ... @@ -17,18 +17,17 @@
17 17
18 18 firstlaunch=${DATA_FOLDER}/.firstlaunch
19 19
20   -export PG_CTL=$(find /usr/lib/postgresql/ -name pg_ctl)
  20 +PG_CTL=$(find /usr/lib/postgresql/ -name pg_ctl)
21 21
22 22 if [ ! -d ${PGDATA} ]; then
23 23 mkdir -p ${PGDATA}
24   - chown -R postgres:postgres ${PGDATA}
25   - su postgres -c '${PG_CTL} initdb -U postgres'
  24 + ${PG_CTL} initdb
26 25 fi
27 26
28   -su postgres -c '${PG_CTL} -l /var/log/postgres/postgres.log -w start'
  27 +exec setsid nohup postgres >> ${PGLOG}/postgres.log 2>&1 &
29 28
30 29 if [ ! -f ${firstlaunch} ]; then
31   - su postgres -c 'psql -U postgres -d postgres -c "CREATE DATABASE thingsboard"'
  30 + psql -U ${pkg.user} -d postgres -c "CREATE DATABASE thingsboard"
32 31 fi
33 32
34 33 cassandra_data_dir=${CASSANDRA_DATA}
... ... @@ -41,7 +40,7 @@ if [ ! -L ${cassandra_data_link} ]; then
41 40 ln -s ${cassandra_data_dir} ${cassandra_data_link}
42 41 fi
43 42
44   -service cassandra start
  43 +exec setsid nohup cassandra >> ${CASSANDRA_LOG}/cassandra.log 2>&1 &
45 44
46 45 until nmap $CASSANDRA_HOST -p $CASSANDRA_PORT | grep "$CASSANDRA_PORT/tcp open"
47 46 do
... ...
... ... @@ -20,6 +20,10 @@ CASSANDRA_PID=$(ps aux | grep '[c]assandra' | awk '{print $2}')
20 20 echo "Stopping cassandra (pid ${CASSANDRA_PID})."
21 21 kill -SIGTERM ${CASSANDRA_PID}
22 22
  23 +PG_CTL=$(find /usr/lib/postgresql/ -name pg_ctl)
  24 +echo "Stopping postgres."
  25 +${PG_CTL} stop
  26 +
23 27 while [ -e /proc/${CASSANDRA_PID} ]
24 28 do
25 29 echo "Waiting for cassandra to stop."
... ...