Merge pull request #145 from volodymyr-babak/feature/kubernetes
Kubernetes scripts
This commit is contained in:
		
						commit
						1193539119
					
				@ -19,12 +19,18 @@ server:
 | 
			
		||||
  address: "${HTTP_BIND_ADDRESS:0.0.0.0}"
 | 
			
		||||
  # Server bind port
 | 
			
		||||
  port: "${HTTP_BIND_PORT:8080}"
 | 
			
		||||
# Uncomment the following section to enable ssl
 | 
			
		||||
#  ssl:
 | 
			
		||||
#    key-store: classpath:keystore/keystore.p12
 | 
			
		||||
#    key-store-password: thingsboard
 | 
			
		||||
#    keyStoreType: PKCS12
 | 
			
		||||
#    keyAlias: tomcat
 | 
			
		||||
  # Server SSL configuration
 | 
			
		||||
  ssl:
 | 
			
		||||
    # Enable/disable SSL support
 | 
			
		||||
    enabled: "${SSL_ENABLED:false}"
 | 
			
		||||
    # Path to the key store that holds the SSL certificate
 | 
			
		||||
    key-store: "${SSL_KEY_STORE:classpath:keystore/keystore.p12}"
 | 
			
		||||
    # Password used to access the key store
 | 
			
		||||
    key-store-password: "${SSL_KEY_STORE_PASSWORD:thingsboard}"
 | 
			
		||||
    # Type of the key store
 | 
			
		||||
    key-store-type: "${SSL_KEY_STORE_TYPE:PKCS12}"
 | 
			
		||||
    # Alias that identifies the key in the key store
 | 
			
		||||
    key-alias: "${SSL_KEY_ALIAS:tomcat}"
 | 
			
		||||
 | 
			
		||||
# Zookeeper connection parameters. Used for service discovery.
 | 
			
		||||
zk:
 | 
			
		||||
@ -79,12 +85,18 @@ mqtt:
 | 
			
		||||
    leak_detector_level: "${NETTY_LEASK_DETECTOR_LVL:DISABLED}"
 | 
			
		||||
    boss_group_thread_count: "${NETTY_BOSS_GROUP_THREADS:1}"
 | 
			
		||||
    worker_group_thread_count: "${NETTY_WORKER_GROUP_THREADS:12}"
 | 
			
		||||
# Uncomment the following lines to enable ssl for MQTT
 | 
			
		||||
#  ssl:
 | 
			
		||||
#    key_store: mqttserver.jks
 | 
			
		||||
#    key_store_password: server_ks_password
 | 
			
		||||
#    key_password: server_key_password
 | 
			
		||||
#    key_store_type: JKS
 | 
			
		||||
  # MQTT SSL configuration
 | 
			
		||||
  ssl:
 | 
			
		||||
    # Enable/disable SSL support
 | 
			
		||||
    enabled: "${MQTT_SSL_ENABLED:false}"
 | 
			
		||||
    # Path to the key store that holds the SSL certificate
 | 
			
		||||
    key_store: "${MQTT_SSL_KEY_STORE:mqttserver.jks}"
 | 
			
		||||
    # Password used to access the key store
 | 
			
		||||
    key_store_password: "${MQTT_SSL_KEY_STORE_PASSWORD:server_ks_password}"
 | 
			
		||||
    # Password used to access the key
 | 
			
		||||
    key_password: "${MQTT_SSL_KEY_PASSWORD:server_key_password}"
 | 
			
		||||
    # Type of the key store
 | 
			
		||||
    key_store_type: "${MQTT_SSL_KEY_STORE_TYPE:JKS}"
 | 
			
		||||
 | 
			
		||||
# CoAP server parameters
 | 
			
		||||
coap:
 | 
			
		||||
 | 
			
		||||
@ -45,7 +45,6 @@ public class ServiceCacheConfiguration {
 | 
			
		||||
    @Value("${cache.device_credentials.time_to_live}")
 | 
			
		||||
    private Integer cacheDeviceCredentialsTTL;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    @Value("${zk.enabled}")
 | 
			
		||||
    private boolean zkEnabled;
 | 
			
		||||
    @Value("${zk.url}")
 | 
			
		||||
 | 
			
		||||
@ -1 +1,7 @@
 | 
			
		||||
CASSANDRA_DATA_DIR=/home/docker/cassandra_volume
 | 
			
		||||
 | 
			
		||||
# cassandra schema container environment variables
 | 
			
		||||
CREATE_SCHEMA=true
 | 
			
		||||
ADD_SYSTEM_DATA=false
 | 
			
		||||
ADD_DEMO_DATA=false
 | 
			
		||||
CASSANDRA_URL=cassandra
 | 
			
		||||
							
								
								
									
										132
									
								
								docker/cassandra/cassandra.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										132
									
								
								docker/cassandra/cassandra.yaml
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,132 @@
 | 
			
		||||
#
 | 
			
		||||
# Copyright © 2016-2017 The Thingsboard Authors
 | 
			
		||||
#
 | 
			
		||||
# Licensed under the Apache License, Version 2.0 (the "License");
 | 
			
		||||
# you may not use this file except in compliance with the License.
 | 
			
		||||
# You may obtain a copy of the License at
 | 
			
		||||
#
 | 
			
		||||
#     http://www.apache.org/licenses/LICENSE-2.0
 | 
			
		||||
#
 | 
			
		||||
# Unless required by applicable law or agreed to in writing, software
 | 
			
		||||
# distributed under the License is distributed on an "AS IS" BASIS,
 | 
			
		||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
			
		||||
# See the License for the specific language governing permissions and
 | 
			
		||||
# limitations under the License.
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
apiVersion: v1
 | 
			
		||||
kind: Service
 | 
			
		||||
metadata:
 | 
			
		||||
  name: cassandra-headless
 | 
			
		||||
  labels:
 | 
			
		||||
    app: cassandra-headless
 | 
			
		||||
spec:
 | 
			
		||||
  ports:
 | 
			
		||||
    - port: 9042
 | 
			
		||||
      name: cql
 | 
			
		||||
  clusterIP: None
 | 
			
		||||
  selector:
 | 
			
		||||
    app: cassandra
 | 
			
		||||
---
 | 
			
		||||
apiVersion: "apps/v1beta1"
 | 
			
		||||
kind: StatefulSet
 | 
			
		||||
metadata:
 | 
			
		||||
  name: cassandra
 | 
			
		||||
spec:
 | 
			
		||||
  serviceName: cassandra-headless
 | 
			
		||||
  replicas: 2
 | 
			
		||||
  template:
 | 
			
		||||
    metadata:
 | 
			
		||||
      labels:
 | 
			
		||||
        app: cassandra
 | 
			
		||||
    spec:
 | 
			
		||||
      nodeSelector:
 | 
			
		||||
        machinetype: other
 | 
			
		||||
      affinity:
 | 
			
		||||
        podAntiAffinity:
 | 
			
		||||
          requiredDuringSchedulingIgnoredDuringExecution:
 | 
			
		||||
            - labelSelector:
 | 
			
		||||
                matchExpressions:
 | 
			
		||||
                  - key: "app"
 | 
			
		||||
                    operator: In
 | 
			
		||||
                    values:
 | 
			
		||||
                    - cassandra-headless
 | 
			
		||||
              topologyKey: "kubernetes.io/hostname"
 | 
			
		||||
      containers:
 | 
			
		||||
      - name: cassandra
 | 
			
		||||
        image: cassandra:3.9
 | 
			
		||||
        imagePullPolicy: Always
 | 
			
		||||
        ports:
 | 
			
		||||
        - containerPort: 7000
 | 
			
		||||
          name: intra-node
 | 
			
		||||
        - containerPort: 7001
 | 
			
		||||
          name: tls-intra-node
 | 
			
		||||
        - containerPort: 7199
 | 
			
		||||
          name: jmx
 | 
			
		||||
        - containerPort: 9042
 | 
			
		||||
          name: cql
 | 
			
		||||
        - containerPort: 9160
 | 
			
		||||
          name: thrift
 | 
			
		||||
        securityContext:
 | 
			
		||||
          capabilities:
 | 
			
		||||
            add:
 | 
			
		||||
              - IPC_LOCK
 | 
			
		||||
        lifecycle:
 | 
			
		||||
          preStop:
 | 
			
		||||
            exec:
 | 
			
		||||
              command: ["/bin/sh", "-c", "PID=$(pidof java) && kill $PID && while ps -p $PID > /dev/null; do sleep 1; done"]
 | 
			
		||||
        env:
 | 
			
		||||
          - name: MAX_HEAP_SIZE
 | 
			
		||||
            value: 2048M
 | 
			
		||||
          - name: HEAP_NEWSIZE
 | 
			
		||||
            value: 100M
 | 
			
		||||
          - name: CASSANDRA_SEEDS
 | 
			
		||||
            value: "cassandra-0.cassandra-headless.default.svc.cluster.local"
 | 
			
		||||
          - name: CASSANDRA_CLUSTER_NAME
 | 
			
		||||
            value: "Thingsboard-Cluster"
 | 
			
		||||
          - name: CASSANDRA_DC
 | 
			
		||||
            value: "DC1-Thingsboard-Cluster"
 | 
			
		||||
          - name: CASSANDRA_RACK
 | 
			
		||||
            value: "Rack-Thingsboard-Cluster"
 | 
			
		||||
          - name: CASSANDRA_AUTO_BOOTSTRAP
 | 
			
		||||
            value: "false"
 | 
			
		||||
          - name: POD_IP
 | 
			
		||||
            valueFrom:
 | 
			
		||||
              fieldRef:
 | 
			
		||||
                fieldPath: status.podIP
 | 
			
		||||
          - name: POD_NAMESPACE
 | 
			
		||||
            valueFrom:
 | 
			
		||||
              fieldRef:
 | 
			
		||||
                fieldPath: metadata.namespace
 | 
			
		||||
        readinessProbe:
 | 
			
		||||
          exec:
 | 
			
		||||
            command:
 | 
			
		||||
            - /bin/bash
 | 
			
		||||
            - -c
 | 
			
		||||
            - /ready-probe.sh
 | 
			
		||||
          initialDelaySeconds: 15
 | 
			
		||||
          timeoutSeconds: 5
 | 
			
		||||
        volumeMounts:
 | 
			
		||||
        - name: cassandra-data
 | 
			
		||||
          mountPath: /var/lib/cassandra/data
 | 
			
		||||
        - name: cassandra-commitlog
 | 
			
		||||
          mountPath: /var/lib/cassandra/commitlog
 | 
			
		||||
  volumeClaimTemplates:
 | 
			
		||||
  - metadata:
 | 
			
		||||
      name: cassandra-data
 | 
			
		||||
      annotations:
 | 
			
		||||
        volume.beta.kubernetes.io/storage-class: fast
 | 
			
		||||
    spec:
 | 
			
		||||
      accessModes: [ "ReadWriteOnce" ]
 | 
			
		||||
      resources:
 | 
			
		||||
        requests:
 | 
			
		||||
          storage: 3Gi
 | 
			
		||||
  - metadata:
 | 
			
		||||
      name: cassandra-commitlog
 | 
			
		||||
      annotations:
 | 
			
		||||
        volume.beta.kubernetes.io/storage-class: fast
 | 
			
		||||
    spec:
 | 
			
		||||
      accessModes: [ "ReadWriteOnce" ]
 | 
			
		||||
      resources:
 | 
			
		||||
        requests:
 | 
			
		||||
          storage: 2Gi
 | 
			
		||||
							
								
								
									
										32
									
								
								docker/deploy.sh → docker/common/common.yaml
									
									
									
									
									
										
										
										Executable file → Normal file
									
								
							
							
						
						
									
										32
									
								
								docker/deploy.sh → docker/common/common.yaml
									
									
									
									
									
										
										
										Executable file → Normal file
									
								
							@ -1,4 +1,3 @@
 | 
			
		||||
#!/bin/bash
 | 
			
		||||
#
 | 
			
		||||
# Copyright © 2016-2017 The Thingsboard Authors
 | 
			
		||||
#
 | 
			
		||||
@ -15,17 +14,20 @@
 | 
			
		||||
# limitations under the License.
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
command='docker-compose -f docker-compose.yml -f docker-compose.random.yml'
 | 
			
		||||
 | 
			
		||||
echo "stopping images.."
 | 
			
		||||
$command stop
 | 
			
		||||
 | 
			
		||||
echo "removing stopped images.."
 | 
			
		||||
$command rm -f
 | 
			
		||||
 | 
			
		||||
echo "building images.."
 | 
			
		||||
$command build
 | 
			
		||||
 | 
			
		||||
echo "starting images..."
 | 
			
		||||
$command up -d
 | 
			
		||||
---
 | 
			
		||||
apiVersion: storage.k8s.io/v1beta1
 | 
			
		||||
kind: StorageClass
 | 
			
		||||
metadata:
 | 
			
		||||
  name: slow
 | 
			
		||||
provisioner: kubernetes.io/gce-pd
 | 
			
		||||
parameters:
 | 
			
		||||
  type: pd-standard
 | 
			
		||||
---
 | 
			
		||||
apiVersion: storage.k8s.io/v1beta1
 | 
			
		||||
kind: StorageClass
 | 
			
		||||
metadata:
 | 
			
		||||
  name: fast
 | 
			
		||||
provisioner: kubernetes.io/gce-pd
 | 
			
		||||
parameters:
 | 
			
		||||
  type: pd-ssd
 | 
			
		||||
---
 | 
			
		||||
@ -17,7 +17,7 @@
 | 
			
		||||
version: '2'
 | 
			
		||||
 | 
			
		||||
services:
 | 
			
		||||
  db:
 | 
			
		||||
  cassandra:
 | 
			
		||||
    ports:
 | 
			
		||||
      - "9042:9042"
 | 
			
		||||
      - "9160:9160"
 | 
			
		||||
 | 
			
		||||
@ -17,24 +17,32 @@
 | 
			
		||||
version: '2'
 | 
			
		||||
 | 
			
		||||
services:
 | 
			
		||||
  thingsboard:
 | 
			
		||||
    image: "thingsboard/application:1.2.3"
 | 
			
		||||
  tb:
 | 
			
		||||
    image: "thingsboard/application:1.2.4"
 | 
			
		||||
    ports:
 | 
			
		||||
      - "8080:8080"
 | 
			
		||||
      - "1883:1883"
 | 
			
		||||
      - "5683:5683/udp"
 | 
			
		||||
    env_file:
 | 
			
		||||
      - thingsboard.env
 | 
			
		||||
    entrypoint: ./run_thingsboard.sh
 | 
			
		||||
  thingsboard-db-schema:
 | 
			
		||||
    image: "thingsboard/thingsboard-db-schema:1.2.3"
 | 
			
		||||
    env_file:
 | 
			
		||||
      - thingsboard-db-schema.env
 | 
			
		||||
    entrypoint: ./install_schema.sh
 | 
			
		||||
  db:
 | 
			
		||||
      - tb.env
 | 
			
		||||
    entrypoint: ./run-application.sh
 | 
			
		||||
  tb-cassandra-schema:
 | 
			
		||||
    image: "thingsboard/tb-cassandra-schema:1.2.4"
 | 
			
		||||
    environment:
 | 
			
		||||
      - CREATE_SCHEMA=${CREATE_SCHEMA}
 | 
			
		||||
      - ADD_SYSTEM_DATA=${ADD_SYSTEM_DATA}
 | 
			
		||||
      - ADD_DEMO_DATA=${ADD_DEMO_DATA}
 | 
			
		||||
      - CASSANDRA_URL=${CASSANDRA_URL}
 | 
			
		||||
    entrypoint: ./install-schema.sh
 | 
			
		||||
  cassandra:
 | 
			
		||||
    image: "cassandra:3.9"
 | 
			
		||||
    ports:
 | 
			
		||||
      - "9042"
 | 
			
		||||
      - "9160"
 | 
			
		||||
    volumes:
 | 
			
		||||
      - "${CASSANDRA_DATA_DIR}:/var/lib/cassandra"
 | 
			
		||||
  zk:
 | 
			
		||||
    image: "zookeeper:3.4.9"
 | 
			
		||||
    ports:
 | 
			
		||||
      - "2181"
 | 
			
		||||
    restart: always
 | 
			
		||||
 | 
			
		||||
@ -16,12 +16,12 @@
 | 
			
		||||
 | 
			
		||||
FROM cassandra:3.9
 | 
			
		||||
 | 
			
		||||
ADD install_schema.sh /root/install_schema.sh
 | 
			
		||||
ADD install-schema.sh /root/install-schema.sh
 | 
			
		||||
 | 
			
		||||
RUN apt-get update \
 | 
			
		||||
        && apt-get install -y nmap
 | 
			
		||||
 | 
			
		||||
RUN chmod +x /root/install_schema.sh
 | 
			
		||||
RUN chmod +x /root/install-schema.sh
 | 
			
		||||
 | 
			
		||||
ADD schema.cql /root/schema.cql
 | 
			
		||||
ADD demo-data.cql /root/demo-data.cql
 | 
			
		||||
							
								
								
									
										13
									
								
								docker/tb-cassandra-schema/Makefile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								docker/tb-cassandra-schema/Makefile
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,13 @@
 | 
			
		||||
VERSION=1.2.4
 | 
			
		||||
PROJECT=thingsboard
 | 
			
		||||
APP=tb-cassandra-schema
 | 
			
		||||
 | 
			
		||||
build:
 | 
			
		||||
	cp ../../dao/src/main/resources/schema.cql .
 | 
			
		||||
	cp ../../dao/src/main/resources/demo-data.cql .
 | 
			
		||||
	cp ../../dao/src/main/resources/system-data.cql .
 | 
			
		||||
	docker build --pull -t ${PROJECT}/${APP}:${VERSION} .
 | 
			
		||||
	rm schema.cql demo-data.cql system-data.cql
 | 
			
		||||
 | 
			
		||||
push: build
 | 
			
		||||
	docker push ${PROJECT}/${APP}:${VERSION}
 | 
			
		||||
@ -16,15 +16,15 @@
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
until nmap db -p 9042 | grep "9042/tcp open"
 | 
			
		||||
until nmap $CASSANDRA_URL -p 9042 | grep "9042/tcp open"
 | 
			
		||||
do
 | 
			
		||||
  echo "Wait for Cassandra..."
 | 
			
		||||
  echo "Wait for $CASSANDRA_URL..."
 | 
			
		||||
  sleep 10
 | 
			
		||||
done
 | 
			
		||||
 | 
			
		||||
if [ "$SKIP_SCHEMA_CREATION" == "false" ]; then
 | 
			
		||||
if [ "$CREATE_SCHEMA" == "true" ]; then
 | 
			
		||||
    echo "Creating 'Thingsboard' keyspace..."
 | 
			
		||||
    cqlsh db -f /root/schema.cql
 | 
			
		||||
    cqlsh $CASSANDRA_URL -f /root/schema.cql
 | 
			
		||||
    if [ "$?" -eq 0 ]; then
 | 
			
		||||
        echo "'Thingsboard' keyspace was successfully created!"
 | 
			
		||||
    else
 | 
			
		||||
@ -32,9 +32,9 @@ if [ "$SKIP_SCHEMA_CREATION" == "false" ]; then
 | 
			
		||||
    fi
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
if [ "$SKIP_SYSTEM_DATA" == "false" ]; then
 | 
			
		||||
if [ "$ADD_SYSTEM_DATA" == "true" ]; then
 | 
			
		||||
    echo "Adding system data..."
 | 
			
		||||
    cqlsh db -f /root/system-data.cql
 | 
			
		||||
    cqlsh $CASSANDRA_URL -f /root/system-data.cql
 | 
			
		||||
    if [ "$?" -eq 0 ]; then
 | 
			
		||||
        echo "System data was successfully added!"
 | 
			
		||||
    else
 | 
			
		||||
@ -42,9 +42,9 @@ if [ "$SKIP_SYSTEM_DATA" == "false" ]; then
 | 
			
		||||
    fi
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
if [ "$SKIP_DEMO_DATA" == "false" ]; then
 | 
			
		||||
if [ "$ADD_DEMO_DATA" == "true" ]; then
 | 
			
		||||
    echo "Adding demo data..."
 | 
			
		||||
    cqlsh db -f /root/demo-data.cql
 | 
			
		||||
    cqlsh $CASSANDRA_URL -f /root/demo-data.cql
 | 
			
		||||
    if [ "$?" -eq 0 ]; then
 | 
			
		||||
        echo "Demo data was successfully added!"
 | 
			
		||||
    else
 | 
			
		||||
@ -14,13 +14,26 @@
 | 
			
		||||
# limitations under the License.
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
version: '2'
 | 
			
		||||
 | 
			
		||||
services:
 | 
			
		||||
  db:
 | 
			
		||||
    ports:
 | 
			
		||||
      - "9042"
 | 
			
		||||
      - "9160"
 | 
			
		||||
  zk:
 | 
			
		||||
    ports:
 | 
			
		||||
      - "2181"
 | 
			
		||||
apiVersion: v1
 | 
			
		||||
kind: Pod
 | 
			
		||||
metadata:
 | 
			
		||||
  name: tb-cassandra-schema
 | 
			
		||||
spec:
 | 
			
		||||
  containers:
 | 
			
		||||
  - name: tb-cassandra-schema
 | 
			
		||||
    imagePullPolicy: Always
 | 
			
		||||
    image: thingsboard/tb-cassandra-schema:1.2.4
 | 
			
		||||
    env:
 | 
			
		||||
    - name: CREATE_SCHEMA
 | 
			
		||||
      value: "false"
 | 
			
		||||
    - name: ADD_SYSTEM_DATA
 | 
			
		||||
      value: "false"
 | 
			
		||||
    - name : ADD_DEMO_DATA
 | 
			
		||||
      value: "false"
 | 
			
		||||
    - name : CASSANDRA_URL
 | 
			
		||||
      value: "cassandra-headless"
 | 
			
		||||
    command:
 | 
			
		||||
    - sh
 | 
			
		||||
    - -c
 | 
			
		||||
    - ./install-schema.sh
 | 
			
		||||
  restartPolicy: Never
 | 
			
		||||
@ -1,6 +1,7 @@
 | 
			
		||||
#Thingsboard server configuration
 | 
			
		||||
 | 
			
		||||
CASSANDRA_URL=db:9042
 | 
			
		||||
TB_CASSANDRA_SCHEMA_URL=tb-cassandra-schema
 | 
			
		||||
CASSANDRA_URL=cassandra:9042
 | 
			
		||||
ZOOKEEPER_URL=zk:2181
 | 
			
		||||
MQTT_BIND_ADDRESS=0.0.0.0
 | 
			
		||||
MQTT_BIND_PORT=1883
 | 
			
		||||
@ -16,9 +16,9 @@
 | 
			
		||||
 | 
			
		||||
FROM openjdk:8-jre
 | 
			
		||||
 | 
			
		||||
ADD run_thingsboard.sh /root/run_thingsboard.sh
 | 
			
		||||
ADD run-application.sh /root/run-application.sh
 | 
			
		||||
ADD thingsboard.deb /root/thingsboard.deb
 | 
			
		||||
 | 
			
		||||
RUN chmod +x /root/run_thingsboard.sh
 | 
			
		||||
RUN chmod +x /root/run-application.sh
 | 
			
		||||
 | 
			
		||||
WORKDIR /root
 | 
			
		||||
							
								
								
									
										11
									
								
								docker/tb/Makefile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								docker/tb/Makefile
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,11 @@
 | 
			
		||||
VERSION=1.2.4
 | 
			
		||||
PROJECT=thingsboard
 | 
			
		||||
APP=application
 | 
			
		||||
 | 
			
		||||
build:
 | 
			
		||||
	cp ../../application/target/thingsboard.deb .
 | 
			
		||||
	docker build --pull -t ${PROJECT}/${APP}:${VERSION} .
 | 
			
		||||
	rm thingsboard.deb
 | 
			
		||||
 | 
			
		||||
push: build
 | 
			
		||||
	docker push ${PROJECT}/${APP}:${VERSION}
 | 
			
		||||
@ -21,12 +21,12 @@ dpkg -i /root/thingsboard.deb
 | 
			
		||||
reachable=0
 | 
			
		||||
while [ $reachable -eq 0 ];
 | 
			
		||||
do
 | 
			
		||||
  echo "thingsboard-db-schema container is still in progress. waiting until it completed..."
 | 
			
		||||
  echo "$TB_CASSANDRA_SCHEMA_URL container is still in progress. waiting until it completed..."
 | 
			
		||||
  sleep 3
 | 
			
		||||
  ping -q -c 1 thingsboard-db-schema > /dev/null 2>&1
 | 
			
		||||
  ping -q -c 1 $TB_CASSANDRA_SCHEMA_URL > /dev/null 2>&1
 | 
			
		||||
  if [ "$?" -ne 0 ];
 | 
			
		||||
  then
 | 
			
		||||
    echo "thingsboard-db-schema container completed!"
 | 
			
		||||
    echo "$TB_CASSANDRA_SCHEMA_URL container completed!"
 | 
			
		||||
    reachable=1
 | 
			
		||||
  fi
 | 
			
		||||
done
 | 
			
		||||
							
								
								
									
										121
									
								
								docker/tb/tb.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										121
									
								
								docker/tb/tb.yaml
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,121 @@
 | 
			
		||||
#
 | 
			
		||||
# Copyright © 2016-2017 The Thingsboard Authors
 | 
			
		||||
#
 | 
			
		||||
# Licensed under the Apache License, Version 2.0 (the "License");
 | 
			
		||||
# you may not use this file except in compliance with the License.
 | 
			
		||||
# You may obtain a copy of the License at
 | 
			
		||||
#
 | 
			
		||||
#     http://www.apache.org/licenses/LICENSE-2.0
 | 
			
		||||
#
 | 
			
		||||
# Unless required by applicable law or agreed to in writing, software
 | 
			
		||||
# distributed under the License is distributed on an "AS IS" BASIS,
 | 
			
		||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
			
		||||
# See the License for the specific language governing permissions and
 | 
			
		||||
# limitations under the License.
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
---
 | 
			
		||||
apiVersion: v1
 | 
			
		||||
kind: Service
 | 
			
		||||
metadata:
 | 
			
		||||
  name: tb-service
 | 
			
		||||
  labels:
 | 
			
		||||
    app: tb-service
 | 
			
		||||
spec:
 | 
			
		||||
  ports:
 | 
			
		||||
  - port: 8080
 | 
			
		||||
    name: ui
 | 
			
		||||
  - port: 1883
 | 
			
		||||
    name: mqtt
 | 
			
		||||
  - port: 5683
 | 
			
		||||
    name: coap
 | 
			
		||||
  selector:
 | 
			
		||||
    app: tb
 | 
			
		||||
  type: LoadBalancer
 | 
			
		||||
---
 | 
			
		||||
apiVersion: policy/v1beta1
 | 
			
		||||
kind: PodDisruptionBudget
 | 
			
		||||
metadata:
 | 
			
		||||
  name: tb-budget
 | 
			
		||||
spec:
 | 
			
		||||
  selector:
 | 
			
		||||
    matchLabels:
 | 
			
		||||
      app: tb
 | 
			
		||||
  minAvailable: 3
 | 
			
		||||
---
 | 
			
		||||
apiVersion: v1
 | 
			
		||||
kind: ConfigMap
 | 
			
		||||
metadata:
 | 
			
		||||
  name: tb-config
 | 
			
		||||
data:
 | 
			
		||||
  zookeeper.enabled: "true"
 | 
			
		||||
  zookeeper.url: "zk-headless"
 | 
			
		||||
  cassandra.url: "cassandra-headless:9042"
 | 
			
		||||
---
 | 
			
		||||
apiVersion: apps/v1beta1
 | 
			
		||||
kind: StatefulSet
 | 
			
		||||
metadata:
 | 
			
		||||
  name: tb
 | 
			
		||||
spec:
 | 
			
		||||
  serviceName: "tb-service"
 | 
			
		||||
  replicas: 3
 | 
			
		||||
  template:
 | 
			
		||||
    metadata:
 | 
			
		||||
      labels:
 | 
			
		||||
        app: tb
 | 
			
		||||
    spec:
 | 
			
		||||
      nodeSelector:
 | 
			
		||||
        machinetype: tb
 | 
			
		||||
      affinity:
 | 
			
		||||
        podAntiAffinity:
 | 
			
		||||
          requiredDuringSchedulingIgnoredDuringExecution:
 | 
			
		||||
            - labelSelector:
 | 
			
		||||
                matchExpressions:
 | 
			
		||||
                  - key: "app"
 | 
			
		||||
                    operator: In
 | 
			
		||||
                    values:
 | 
			
		||||
                    - tb-service
 | 
			
		||||
              topologyKey: "kubernetes.io/hostname"
 | 
			
		||||
      containers:
 | 
			
		||||
      - name: tb
 | 
			
		||||
        imagePullPolicy: Always
 | 
			
		||||
        image: thingsboard/application:1.2.4
 | 
			
		||||
        ports:
 | 
			
		||||
        - containerPort: 8080
 | 
			
		||||
          name: ui
 | 
			
		||||
        - containerPort: 1883
 | 
			
		||||
          name: mqtt
 | 
			
		||||
        - containerPort: 5683
 | 
			
		||||
          name: coap
 | 
			
		||||
        - containerPort: 9001
 | 
			
		||||
          name: rpc
 | 
			
		||||
        env:
 | 
			
		||||
        - name: ZOOKEEPER_ENABLED
 | 
			
		||||
          valueFrom:
 | 
			
		||||
            configMapKeyRef:
 | 
			
		||||
              name: tb-config
 | 
			
		||||
              key: zookeeper.enabled
 | 
			
		||||
        - name: ZOOKEEPER_URL
 | 
			
		||||
          valueFrom:
 | 
			
		||||
            configMapKeyRef:
 | 
			
		||||
              name: tb-config
 | 
			
		||||
              key: zookeeper.url
 | 
			
		||||
        - name : CASSANDRA_URL
 | 
			
		||||
          valueFrom:
 | 
			
		||||
            configMapKeyRef:
 | 
			
		||||
              name: tb-config
 | 
			
		||||
              key: cassandra.url
 | 
			
		||||
        - name : RPC_HOST
 | 
			
		||||
          valueFrom:
 | 
			
		||||
            fieldRef:
 | 
			
		||||
              fieldPath: status.podIP
 | 
			
		||||
        command:
 | 
			
		||||
        - sh
 | 
			
		||||
        - -c
 | 
			
		||||
        - ./run-application.sh
 | 
			
		||||
        livenessProbe:
 | 
			
		||||
          httpGet:
 | 
			
		||||
            path: /login
 | 
			
		||||
            port: ui-port
 | 
			
		||||
          initialDelaySeconds: 120
 | 
			
		||||
          timeoutSeconds: 10
 | 
			
		||||
@ -1,5 +0,0 @@
 | 
			
		||||
#Db schema configuration
 | 
			
		||||
 | 
			
		||||
SKIP_SCHEMA_CREATION=false
 | 
			
		||||
SKIP_SYSTEM_DATA=false
 | 
			
		||||
SKIP_DEMO_DATA=false
 | 
			
		||||
@ -1,28 +0,0 @@
 | 
			
		||||
#!/bin/bash
 | 
			
		||||
#
 | 
			
		||||
# Copyright © 2016-2017 The Thingsboard Authors
 | 
			
		||||
#
 | 
			
		||||
# Licensed under the Apache License, Version 2.0 (the "License");
 | 
			
		||||
# you may not use this file except in compliance with the License.
 | 
			
		||||
# You may obtain a copy of the License at
 | 
			
		||||
#
 | 
			
		||||
#     http://www.apache.org/licenses/LICENSE-2.0
 | 
			
		||||
#
 | 
			
		||||
# Unless required by applicable law or agreed to in writing, software
 | 
			
		||||
# distributed under the License is distributed on an "AS IS" BASIS,
 | 
			
		||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
			
		||||
# See the License for the specific language governing permissions and
 | 
			
		||||
# limitations under the License.
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
cp ../../dao/src/main/resources/schema.cql schema.cql
 | 
			
		||||
cp ../../dao/src/main/resources/demo-data.cql demo-data.cql
 | 
			
		||||
cp ../../dao/src/main/resources/system-data.cql system-data.cql
 | 
			
		||||
 | 
			
		||||
docker build -t thingsboard/thingsboard-db-schema:1.2.3 -t thingsboard/thingsboard-db-schema:latest .
 | 
			
		||||
 | 
			
		||||
docker login
 | 
			
		||||
 | 
			
		||||
docker push thingsboard/thingsboard-db-schema:1.2.3
 | 
			
		||||
docker push thingsboard/thingsboard-db-schema:latest
 | 
			
		||||
@ -1,26 +0,0 @@
 | 
			
		||||
#!/bin/bash
 | 
			
		||||
#
 | 
			
		||||
# Copyright © 2016-2017 The Thingsboard Authors
 | 
			
		||||
#
 | 
			
		||||
# Licensed under the Apache License, Version 2.0 (the "License");
 | 
			
		||||
# you may not use this file except in compliance with the License.
 | 
			
		||||
# You may obtain a copy of the License at
 | 
			
		||||
#
 | 
			
		||||
#     http://www.apache.org/licenses/LICENSE-2.0
 | 
			
		||||
#
 | 
			
		||||
# Unless required by applicable law or agreed to in writing, software
 | 
			
		||||
# distributed under the License is distributed on an "AS IS" BASIS,
 | 
			
		||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
			
		||||
# See the License for the specific language governing permissions and
 | 
			
		||||
# limitations under the License.
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
cp ../../application/target/thingsboard.deb thingsboard.deb
 | 
			
		||||
 | 
			
		||||
docker build -t thingsboard/application:1.2.3 -t thingsboard/application:latest .
 | 
			
		||||
 | 
			
		||||
docker login
 | 
			
		||||
 | 
			
		||||
docker push thingsboard/application:1.2.3
 | 
			
		||||
docker push thingsboard/application:latest
 | 
			
		||||
							
								
								
									
										71
									
								
								docker/zookeeper/Dockerfile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										71
									
								
								docker/zookeeper/Dockerfile
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,71 @@
 | 
			
		||||
#
 | 
			
		||||
# Copyright © 2016-2017 The Thingsboard Authors
 | 
			
		||||
#
 | 
			
		||||
# Licensed under the Apache License, Version 2.0 (the "License");
 | 
			
		||||
# you may not use this file except in compliance with the License.
 | 
			
		||||
# You may obtain a copy of the License at
 | 
			
		||||
#
 | 
			
		||||
#     http://www.apache.org/licenses/LICENSE-2.0
 | 
			
		||||
#
 | 
			
		||||
# Unless required by applicable law or agreed to in writing, software
 | 
			
		||||
# distributed under the License is distributed on an "AS IS" BASIS,
 | 
			
		||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
			
		||||
# See the License for the specific language governing permissions and
 | 
			
		||||
# limitations under the License.
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
FROM ubuntu:16.04 
 | 
			
		||||
ENV ZK_USER=zookeeper \
 | 
			
		||||
ZK_DATA_DIR=/var/lib/zookeeper/data \
 | 
			
		||||
ZK_DATA_LOG_DIR=/var/lib/zookeeper/log \
 | 
			
		||||
ZK_LOG_DIR=/var/log/zookeeper \
 | 
			
		||||
JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
 | 
			
		||||
 | 
			
		||||
ARG GPG_KEY=C823E3E5B12AF29C67F81976F5CECB3CB5E9BD2D
 | 
			
		||||
ARG ZK_DIST=zookeeper-3.4.9
 | 
			
		||||
RUN set -x \
 | 
			
		||||
    && apt-get update \
 | 
			
		||||
    && apt-get install -y openjdk-8-jre-headless wget netcat-openbsd \
 | 
			
		||||
	&& wget -q "http://www.apache.org/dist/zookeeper/$ZK_DIST/$ZK_DIST.tar.gz" \
 | 
			
		||||
    && wget -q "http://www.apache.org/dist/zookeeper/$ZK_DIST/$ZK_DIST.tar.gz.asc" \
 | 
			
		||||
    && export GNUPGHOME="$(mktemp -d)" \
 | 
			
		||||
    && gpg --keyserver ha.pool.sks-keyservers.net --recv-key "$GPG_KEY" \
 | 
			
		||||
    && gpg --batch --verify "$ZK_DIST.tar.gz.asc" "$ZK_DIST.tar.gz" \
 | 
			
		||||
    && tar -xzf "$ZK_DIST.tar.gz" -C /opt \
 | 
			
		||||
    && rm -r "$GNUPGHOME" "$ZK_DIST.tar.gz" "$ZK_DIST.tar.gz.asc" \
 | 
			
		||||
    && ln -s /opt/$ZK_DIST /opt/zookeeper \
 | 
			
		||||
    && rm -rf /opt/zookeeper/CHANGES.txt \
 | 
			
		||||
    /opt/zookeeper/README.txt \
 | 
			
		||||
    /opt/zookeeper/NOTICE.txt \
 | 
			
		||||
    /opt/zookeeper/CHANGES.txt \
 | 
			
		||||
    /opt/zookeeper/README_packaging.txt \
 | 
			
		||||
    /opt/zookeeper/build.xml \
 | 
			
		||||
    /opt/zookeeper/config \
 | 
			
		||||
    /opt/zookeeper/contrib \
 | 
			
		||||
    /opt/zookeeper/dist-maven \
 | 
			
		||||
    /opt/zookeeper/docs \
 | 
			
		||||
    /opt/zookeeper/ivy.xml \
 | 
			
		||||
    /opt/zookeeper/ivysettings.xml \
 | 
			
		||||
    /opt/zookeeper/recipes \
 | 
			
		||||
    /opt/zookeeper/src \
 | 
			
		||||
    /opt/zookeeper/$ZK_DIST.jar.asc \
 | 
			
		||||
    /opt/zookeeper/$ZK_DIST.jar.md5 \
 | 
			
		||||
    /opt/zookeeper/$ZK_DIST.jar.sha1 \
 | 
			
		||||
	&& apt-get autoremove -y wget \
 | 
			
		||||
	&& rm -rf /var/lib/apt/lists/*
 | 
			
		||||
 | 
			
		||||
#Copy configuration generator script to bin
 | 
			
		||||
COPY zk-gen-config.sh zk-ok.sh /opt/zookeeper/bin/
 | 
			
		||||
 | 
			
		||||
# Create a user for the zookeeper process and configure file system ownership 
 | 
			
		||||
# for nessecary directories and symlink the distribution as a user executable
 | 
			
		||||
RUN set -x \
 | 
			
		||||
	&& useradd $ZK_USER \
 | 
			
		||||
    && [ `id -u $ZK_USER` -eq 1000 ] \
 | 
			
		||||
    && [ `id -g $ZK_USER` -eq 1000 ] \
 | 
			
		||||
    && mkdir -p $ZK_DATA_DIR $ZK_DATA_LOG_DIR $ZK_LOG_DIR /usr/share/zookeeper /tmp/zookeeper /usr/etc/ \
 | 
			
		||||
	&& chown -R "$ZK_USER:$ZK_USER" /opt/$ZK_DIST $ZK_DATA_DIR $ZK_LOG_DIR $ZK_DATA_LOG_DIR /tmp/zookeeper \
 | 
			
		||||
	&& ln -s /opt/zookeeper/conf/ /usr/etc/zookeeper \
 | 
			
		||||
	&& ln -s /opt/zookeeper/bin/* /usr/bin \
 | 
			
		||||
	&& ln -s /opt/zookeeper/$ZK_DIST.jar /usr/share/zookeeper/ \
 | 
			
		||||
	&& ln -s /opt/zookeeper/lib/* /usr/share/zookeeper 
 | 
			
		||||
							
								
								
									
										9
									
								
								docker/zookeeper/Makefile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								docker/zookeeper/Makefile
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,9 @@
 | 
			
		||||
VERSION=1.2.4
 | 
			
		||||
PROJECT=thingsboard
 | 
			
		||||
APP=zk
 | 
			
		||||
 | 
			
		||||
build:
 | 
			
		||||
	docker build --pull -t ${PROJECT}/${APP}:${VERSION} .
 | 
			
		||||
 | 
			
		||||
push: build
 | 
			
		||||
	docker push ${PROJECT}/${APP}:${VERSION}
 | 
			
		||||
							
								
								
									
										153
									
								
								docker/zookeeper/zk-gen-config.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										153
									
								
								docker/zookeeper/zk-gen-config.sh
									
									
									
									
									
										Executable file
									
								
							@ -0,0 +1,153 @@
 | 
			
		||||
#!/usr/bin/env bash
 | 
			
		||||
#
 | 
			
		||||
# Copyright © 2016-2017 The Thingsboard Authors
 | 
			
		||||
#
 | 
			
		||||
# Licensed under the Apache License, Version 2.0 (the "License");
 | 
			
		||||
# you may not use this file except in compliance with the License.
 | 
			
		||||
# You may obtain a copy of the License at
 | 
			
		||||
#
 | 
			
		||||
#     http://www.apache.org/licenses/LICENSE-2.0
 | 
			
		||||
#
 | 
			
		||||
# Unless required by applicable law or agreed to in writing, software
 | 
			
		||||
# distributed under the License is distributed on an "AS IS" BASIS,
 | 
			
		||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
			
		||||
# See the License for the specific language governing permissions and
 | 
			
		||||
# limitations under the License.
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
ZK_USER=${ZK_USER:-"zookeeper"}
 | 
			
		||||
ZK_LOG_LEVEL=${ZK_LOG_LEVEL:-"INFO"}
 | 
			
		||||
ZK_DATA_DIR=${ZK_DATA_DIR:-"/var/lib/zookeeper/data"}
 | 
			
		||||
ZK_DATA_LOG_DIR=${ZK_DATA_LOG_DIR:-"/var/lib/zookeeper/log"}
 | 
			
		||||
ZK_LOG_DIR=${ZK_LOG_DIR:-"var/log/zookeeper"}
 | 
			
		||||
ZK_CONF_DIR=${ZK_CONF_DIR:-"/opt/zookeeper/conf"}
 | 
			
		||||
ZK_CLIENT_PORT=${ZK_CLIENT_PORT:-2181}
 | 
			
		||||
ZK_SERVER_PORT=${ZK_SERVER_PORT:-2888}
 | 
			
		||||
ZK_ELECTION_PORT=${ZK_ELECTION_PORT:-3888}
 | 
			
		||||
ZK_TICK_TIME=${ZK_TICK_TIME:-2000}
 | 
			
		||||
ZK_INIT_LIMIT=${ZK_INIT_LIMIT:-10}
 | 
			
		||||
ZK_SYNC_LIMIT=${ZK_SYNC_LIMIT:-5}
 | 
			
		||||
ZK_HEAP_SIZE=${ZK_HEAP_SIZE:-2G}
 | 
			
		||||
ZK_MAX_CLIENT_CNXNS=${ZK_MAX_CLIENT_CNXNS:-60}
 | 
			
		||||
ZK_MIN_SESSION_TIMEOUT=${ZK_MIN_SESSION_TIMEOUT:- $((ZK_TICK_TIME*2))}
 | 
			
		||||
ZK_MAX_SESSION_TIMEOUT=${ZK_MAX_SESSION_TIMEOUT:- $((ZK_TICK_TIME*20))}
 | 
			
		||||
ZK_SNAP_RETAIN_COUNT=${ZK_SNAP_RETAIN_COUNT:-3}
 | 
			
		||||
ZK_PURGE_INTERVAL=${ZK_PURGE_INTERVAL:-0}
 | 
			
		||||
ID_FILE="$ZK_DATA_DIR/myid"
 | 
			
		||||
ZK_CONFIG_FILE="$ZK_CONF_DIR/zoo.cfg"
 | 
			
		||||
LOGGER_PROPS_FILE="$ZK_CONF_DIR/log4j.properties"
 | 
			
		||||
JAVA_ENV_FILE="$ZK_CONF_DIR/java.env"
 | 
			
		||||
HOST=`hostname -s`
 | 
			
		||||
DOMAIN=`hostname -d`
 | 
			
		||||
 | 
			
		||||
function print_servers() {
 | 
			
		||||
	 for (( i=1; i<=$ZK_REPLICAS; i++ ))
 | 
			
		||||
	do
 | 
			
		||||
		echo "server.$i=$NAME-$((i-1)).$DOMAIN:$ZK_SERVER_PORT:$ZK_ELECTION_PORT"
 | 
			
		||||
	done
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function validate_env() {
 | 
			
		||||
    echo "Validating environment"
 | 
			
		||||
	if [ -z $ZK_REPLICAS ]; then
 | 
			
		||||
		echo "ZK_REPLICAS is a mandatory environment variable"
 | 
			
		||||
		exit 1
 | 
			
		||||
	fi
 | 
			
		||||
 | 
			
		||||
	if [[ $HOST =~ (.*)-([0-9]+)$ ]]; then
 | 
			
		||||
		NAME=${BASH_REMATCH[1]}
 | 
			
		||||
		ORD=${BASH_REMATCH[2]}
 | 
			
		||||
	else
 | 
			
		||||
		echo "Failed to extract ordinal from hostname $HOST"
 | 
			
		||||
		exit 1
 | 
			
		||||
	fi
 | 
			
		||||
	MY_ID=$((ORD+1))
 | 
			
		||||
	echo "ZK_REPLICAS=$ZK_REPLICAS"
 | 
			
		||||
    echo "MY_ID=$MY_ID"
 | 
			
		||||
    echo "ZK_LOG_LEVEL=$ZK_LOG_LEVEL"
 | 
			
		||||
    echo "ZK_DATA_DIR=$ZK_DATA_DIR"
 | 
			
		||||
    echo "ZK_DATA_LOG_DIR=$ZK_DATA_LOG_DIR"
 | 
			
		||||
    echo "ZK_LOG_DIR=$ZK_LOG_DIR"
 | 
			
		||||
    echo "ZK_CLIENT_PORT=$ZK_CLIENT_PORT"
 | 
			
		||||
    echo "ZK_SERVER_PORT=$ZK_SERVER_PORT"
 | 
			
		||||
    echo "ZK_ELECTION_PORT=$ZK_ELECTION_PORT"
 | 
			
		||||
    echo "ZK_TICK_TIME=$ZK_TICK_TIME"
 | 
			
		||||
    echo "ZK_INIT_LIMIT=$ZK_INIT_LIMIT"
 | 
			
		||||
    echo "ZK_SYNC_LIMIT=$ZK_SYNC_LIMIT"
 | 
			
		||||
    echo "ZK_MAX_CLIENT_CNXNS=$ZK_MAX_CLIENT_CNXNS"
 | 
			
		||||
    echo "ZK_MIN_SESSION_TIMEOUT=$ZK_MIN_SESSION_TIMEOUT"
 | 
			
		||||
    echo "ZK_MAX_SESSION_TIMEOUT=$ZK_MAX_SESSION_TIMEOUT"
 | 
			
		||||
    echo "ZK_HEAP_SIZE=$ZK_HEAP_SIZE"
 | 
			
		||||
    echo "ZK_SNAP_RETAIN_COUNT=$ZK_SNAP_RETAIN_COUNT"
 | 
			
		||||
    echo "ZK_PURGE_INTERVAL=$ZK_PURGE_INTERVAL"
 | 
			
		||||
    echo "ENSEMBLE"
 | 
			
		||||
    print_servers
 | 
			
		||||
    echo "Environment validation successful"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function create_config() {
 | 
			
		||||
	rm -f $ZK_CONFIG_FILE
 | 
			
		||||
    echo "Creating ZooKeeper configuration"
 | 
			
		||||
    echo "#This file was autogenerated by zk DO NOT EDIT" >> $ZK_CONFIG_FILE
 | 
			
		||||
	echo "clientPort=$ZK_CLIENT_PORT" >> $ZK_CONFIG_FILE
 | 
			
		||||
    echo "dataDir=$ZK_DATA_DIR" >> $ZK_CONFIG_FILE
 | 
			
		||||
    echo "dataLogDir=$ZK_DATA_LOG_DIR" >> $ZK_CONFIG_FILE
 | 
			
		||||
    echo "tickTime=$ZK_TICK_TIME" >> $ZK_CONFIG_FILE
 | 
			
		||||
    echo "initLimit=$ZK_INIT_LIMIT" >> $ZK_CONFIG_FILE
 | 
			
		||||
    echo "syncLimit=$ZK_SYNC_LIMIT" >> $ZK_CONFIG_FILE
 | 
			
		||||
    echo "maxClientCnxns=$ZK_MAX_CLIENT_CNXNS" >> $ZK_CONFIG_FILE
 | 
			
		||||
    echo "minSessionTimeout=$ZK_MIN_SESSION_TIMEOUT" >> $ZK_CONFIG_FILE
 | 
			
		||||
    echo "maxSessionTimeout=$ZK_MAX_SESSION_TIMEOUT" >> $ZK_CONFIG_FILE
 | 
			
		||||
    echo "autopurge.snapRetainCount=$ZK_SNAP_RETAIN_COUNT" >> $ZK_CONFIG_FILE
 | 
			
		||||
    echo "autopurge.purgeInteval=$ZK_PURGE_INTERVAL" >> $ZK_CONFIG_FILE
 | 
			
		||||
 | 
			
		||||
    if [ $ZK_REPLICAS -gt 1 ]; then
 | 
			
		||||
    	print_servers >> $ZK_CONFIG_FILE
 | 
			
		||||
    fi
 | 
			
		||||
    echo "Wrote ZooKeeper configuration file to $ZK_CONFIG_FILE"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function create_data_dirs() {
 | 
			
		||||
	echo "Creating ZooKeeper data directories and setting permissions"
 | 
			
		||||
    if [ ! -d $ZK_DATA_DIR  ]; then
 | 
			
		||||
        mkdir -p $ZK_DATA_DIR
 | 
			
		||||
        chown -R $ZK_USER:$ZK_USER $ZK_DATA_DIR
 | 
			
		||||
    fi
 | 
			
		||||
 | 
			
		||||
    if [ ! -d $ZK_DATA_LOG_DIR  ]; then
 | 
			
		||||
        mkdir -p $ZK_DATA_LOG_DIR
 | 
			
		||||
        chown -R $ZK_USER:$ZK_USER $ZK_DATA_LOG_DIR
 | 
			
		||||
    fi
 | 
			
		||||
 | 
			
		||||
    if [ ! -d $ZK_LOG_DIR  ]; then
 | 
			
		||||
        mkdir -p $ZK_LOG_DIR
 | 
			
		||||
        chown -R $ZK_USER:$ZK_USER $ZK_LOG_DIR
 | 
			
		||||
    fi
 | 
			
		||||
    if [ ! -f $ID_FILE ]; then
 | 
			
		||||
        echo $MY_ID >> $ID_FILE
 | 
			
		||||
    fi
 | 
			
		||||
    echo "Created ZooKeeper data directories and set permissions in $ZK_DATA_DIR"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function create_log_props () {
 | 
			
		||||
	rm -f $LOGGER_PROPS_FILE
 | 
			
		||||
    echo "Creating ZooKeeper log4j configuration"
 | 
			
		||||
	echo "zookeeper.root.logger=CONSOLE" >> $LOGGER_PROPS_FILE
 | 
			
		||||
	echo "zookeeper.console.threshold="$ZK_LOG_LEVEL >> $LOGGER_PROPS_FILE
 | 
			
		||||
	echo "log4j.rootLogger=\${zookeeper.root.logger}" >> $LOGGER_PROPS_FILE
 | 
			
		||||
	echo "log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender" >> $LOGGER_PROPS_FILE
 | 
			
		||||
	echo "log4j.appender.CONSOLE.Threshold=\${zookeeper.console.threshold}" >> $LOGGER_PROPS_FILE
 | 
			
		||||
	echo "log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout" >> $LOGGER_PROPS_FILE
 | 
			
		||||
	echo "log4j.appender.CONSOLE.layout.ConversionPattern=%d{ISO8601} [myid:%X{myid}] - %-5p [%t:%C{1}@%L] - %m%n" >> $LOGGER_PROPS_FILE
 | 
			
		||||
	echo "Wrote log4j configuration to $LOGGER_PROPS_FILE"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function create_java_env() {
 | 
			
		||||
    rm -f $JAVA_ENV_FILE
 | 
			
		||||
    echo "Creating JVM configuration file"
 | 
			
		||||
    echo "ZOO_LOG_DIR=$ZK_LOG_DIR" >> $JAVA_ENV_FILE
 | 
			
		||||
    echo "JVMFLAGS=\"-Xmx$ZK_HEAP_SIZE -Xms$ZK_HEAP_SIZE\"" >> $JAVA_ENV_FILE
 | 
			
		||||
    echo "Wrote JVM configuration to $JAVA_ENV_FILE"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
validate_env && create_config && create_log_props && create_data_dirs && create_java_env
 | 
			
		||||
@ -1,4 +1,4 @@
 | 
			
		||||
#!/bin/bash
 | 
			
		||||
#!/usr/bin/env bash
 | 
			
		||||
#
 | 
			
		||||
# Copyright © 2016-2017 The Thingsboard Authors
 | 
			
		||||
#
 | 
			
		||||
@ -15,17 +15,14 @@
 | 
			
		||||
# limitations under the License.
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
# zk-ok.sh uses the ruok ZooKeeper four letter work to determine if the instance
 | 
			
		||||
# is health. The $? variable will be set to 0 if server responds that it is 
 | 
			
		||||
# healthy, or 1 if the server fails to respond.
 | 
			
		||||
 | 
			
		||||
command='docker-compose -f docker-compose.yml -f docker-compose.static.yml'
 | 
			
		||||
 | 
			
		||||
echo "stopping images.."
 | 
			
		||||
$command stop
 | 
			
		||||
 | 
			
		||||
echo "removing stopped images.."
 | 
			
		||||
$command rm -f
 | 
			
		||||
 | 
			
		||||
echo "building images.."
 | 
			
		||||
$command build
 | 
			
		||||
 | 
			
		||||
echo "starting cassandra, zookeeper, thingsboard-db-schema images..."
 | 
			
		||||
$command up -d db zk thingsboard-db-schema
 | 
			
		||||
ZK_CLIENT_PORT=${ZK_CLIENT_PORT:-2181}
 | 
			
		||||
OK=$(echo ruok | nc 127.0.0.1 $ZK_CLIENT_PORT)
 | 
			
		||||
if [ "$OK" == "imok" ]; then
 | 
			
		||||
	exit 0
 | 
			
		||||
else
 | 
			
		||||
	exit 1
 | 
			
		||||
fi
 | 
			
		||||
							
								
								
									
										190
									
								
								docker/zookeeper/zookeeper.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										190
									
								
								docker/zookeeper/zookeeper.yaml
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,190 @@
 | 
			
		||||
#
 | 
			
		||||
# Copyright © 2016-2017 The Thingsboard Authors
 | 
			
		||||
#
 | 
			
		||||
# Licensed under the Apache License, Version 2.0 (the "License");
 | 
			
		||||
# you may not use this file except in compliance with the License.
 | 
			
		||||
# You may obtain a copy of the License at
 | 
			
		||||
#
 | 
			
		||||
#     http://www.apache.org/licenses/LICENSE-2.0
 | 
			
		||||
#
 | 
			
		||||
# Unless required by applicable law or agreed to in writing, software
 | 
			
		||||
# distributed under the License is distributed on an "AS IS" BASIS,
 | 
			
		||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
			
		||||
# See the License for the specific language governing permissions and
 | 
			
		||||
# limitations under the License.
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
apiVersion: v1
 | 
			
		||||
kind: Service
 | 
			
		||||
metadata:
 | 
			
		||||
  name: zk-headless
 | 
			
		||||
  labels:
 | 
			
		||||
    app: zk-headless
 | 
			
		||||
spec:
 | 
			
		||||
  ports:
 | 
			
		||||
  - port: 2888
 | 
			
		||||
    name: server
 | 
			
		||||
  - port: 3888
 | 
			
		||||
    name: leader-election
 | 
			
		||||
  clusterIP: None
 | 
			
		||||
  selector:
 | 
			
		||||
    app: zk
 | 
			
		||||
---
 | 
			
		||||
apiVersion: v1
 | 
			
		||||
kind: ConfigMap
 | 
			
		||||
metadata:
 | 
			
		||||
  name: zk-config
 | 
			
		||||
data:
 | 
			
		||||
  ensemble: "zk-0;zk-1;zk-2"
 | 
			
		||||
  replicas: "3"
 | 
			
		||||
  jvm.heap: "500m"
 | 
			
		||||
  tick: "2000"
 | 
			
		||||
  init: "10"
 | 
			
		||||
  sync: "5"
 | 
			
		||||
  client.cnxns: "60"
 | 
			
		||||
  snap.retain: "3"
 | 
			
		||||
  purge.interval: "1"
 | 
			
		||||
  client.port: "2181"
 | 
			
		||||
  server.port: "2888"
 | 
			
		||||
  election.port: "3888"
 | 
			
		||||
---
 | 
			
		||||
apiVersion: policy/v1beta1
 | 
			
		||||
kind: PodDisruptionBudget
 | 
			
		||||
metadata:
 | 
			
		||||
  name: zk-budget
 | 
			
		||||
spec:
 | 
			
		||||
  selector:
 | 
			
		||||
    matchLabels:
 | 
			
		||||
      app: zk
 | 
			
		||||
  minAvailable: 3
 | 
			
		||||
---
 | 
			
		||||
apiVersion: apps/v1beta1
 | 
			
		||||
kind: StatefulSet
 | 
			
		||||
metadata:
 | 
			
		||||
  name: zk
 | 
			
		||||
spec:
 | 
			
		||||
  serviceName: zk-headless
 | 
			
		||||
  replicas: 3
 | 
			
		||||
  template:
 | 
			
		||||
    metadata:
 | 
			
		||||
      labels:
 | 
			
		||||
        app: zk
 | 
			
		||||
      annotations:
 | 
			
		||||
        pod.alpha.kubernetes.io/initialized: "true"
 | 
			
		||||
    spec:
 | 
			
		||||
      nodeSelector:
 | 
			
		||||
        machinetype: other
 | 
			
		||||
      affinity:
 | 
			
		||||
        podAntiAffinity:
 | 
			
		||||
          requiredDuringSchedulingIgnoredDuringExecution:
 | 
			
		||||
            - labelSelector:
 | 
			
		||||
                matchExpressions:
 | 
			
		||||
                  - key: "app"
 | 
			
		||||
                    operator: In
 | 
			
		||||
                    values:
 | 
			
		||||
                    - zk-headless
 | 
			
		||||
              topologyKey: "kubernetes.io/hostname"
 | 
			
		||||
      containers:
 | 
			
		||||
      - name: zk
 | 
			
		||||
        imagePullPolicy: Always
 | 
			
		||||
        image: thingsboard/zk:1.2.4
 | 
			
		||||
        ports:
 | 
			
		||||
        - containerPort: 2181
 | 
			
		||||
          name: client
 | 
			
		||||
        - containerPort: 2888
 | 
			
		||||
          name: server
 | 
			
		||||
        - containerPort: 3888
 | 
			
		||||
          name: leader-election
 | 
			
		||||
        env:
 | 
			
		||||
        - name : ZK_ENSEMBLE
 | 
			
		||||
          valueFrom:
 | 
			
		||||
            configMapKeyRef:
 | 
			
		||||
              name: zk-config
 | 
			
		||||
              key: ensemble
 | 
			
		||||
        - name : ZK_REPLICAS
 | 
			
		||||
          valueFrom:
 | 
			
		||||
            configMapKeyRef:
 | 
			
		||||
              name: zk-config
 | 
			
		||||
              key: replicas
 | 
			
		||||
        - name : ZK_HEAP_SIZE
 | 
			
		||||
          valueFrom:
 | 
			
		||||
            configMapKeyRef:
 | 
			
		||||
              name: zk-config
 | 
			
		||||
              key: jvm.heap
 | 
			
		||||
        - name : ZK_TICK_TIME
 | 
			
		||||
          valueFrom:
 | 
			
		||||
            configMapKeyRef:
 | 
			
		||||
              name: zk-config
 | 
			
		||||
              key: tick
 | 
			
		||||
        - name : ZK_INIT_LIMIT
 | 
			
		||||
          valueFrom:
 | 
			
		||||
            configMapKeyRef:
 | 
			
		||||
              name: zk-config
 | 
			
		||||
              key: init
 | 
			
		||||
        - name : ZK_SYNC_LIMIT
 | 
			
		||||
          valueFrom:
 | 
			
		||||
            configMapKeyRef:
 | 
			
		||||
              name: zk-config
 | 
			
		||||
              key: tick
 | 
			
		||||
        - name : ZK_MAX_CLIENT_CNXNS
 | 
			
		||||
          valueFrom:
 | 
			
		||||
            configMapKeyRef:
 | 
			
		||||
              name: zk-config
 | 
			
		||||
              key: client.cnxns
 | 
			
		||||
        - name: ZK_SNAP_RETAIN_COUNT
 | 
			
		||||
          valueFrom:
 | 
			
		||||
            configMapKeyRef:
 | 
			
		||||
              name: zk-config
 | 
			
		||||
              key: snap.retain
 | 
			
		||||
        - name: ZK_PURGE_INTERVAL
 | 
			
		||||
          valueFrom:
 | 
			
		||||
            configMapKeyRef:
 | 
			
		||||
              name: zk-config
 | 
			
		||||
              key: purge.interval
 | 
			
		||||
        - name: ZK_CLIENT_PORT
 | 
			
		||||
          valueFrom:
 | 
			
		||||
            configMapKeyRef:
 | 
			
		||||
              name: zk-config
 | 
			
		||||
              key: client.port
 | 
			
		||||
        - name: ZK_SERVER_PORT
 | 
			
		||||
          valueFrom:
 | 
			
		||||
            configMapKeyRef:
 | 
			
		||||
              name: zk-config
 | 
			
		||||
              key: server.port
 | 
			
		||||
        - name: ZK_ELECTION_PORT
 | 
			
		||||
          valueFrom:
 | 
			
		||||
            configMapKeyRef:
 | 
			
		||||
              name: zk-config
 | 
			
		||||
              key: election.port
 | 
			
		||||
        command:
 | 
			
		||||
        - sh
 | 
			
		||||
        - -c
 | 
			
		||||
        - zk-gen-config.sh && zkServer.sh start-foreground
 | 
			
		||||
        readinessProbe:
 | 
			
		||||
          exec:
 | 
			
		||||
            command:
 | 
			
		||||
            - "zk-ok.sh"
 | 
			
		||||
          initialDelaySeconds: 15
 | 
			
		||||
          timeoutSeconds: 5
 | 
			
		||||
        livenessProbe:
 | 
			
		||||
          exec:
 | 
			
		||||
            command:
 | 
			
		||||
            - "zk-ok.sh"
 | 
			
		||||
          initialDelaySeconds: 15
 | 
			
		||||
          timeoutSeconds: 5
 | 
			
		||||
        volumeMounts:
 | 
			
		||||
        - name: zkdatadir
 | 
			
		||||
          mountPath: /var/lib/zookeeper
 | 
			
		||||
      securityContext:
 | 
			
		||||
        runAsUser: 1000
 | 
			
		||||
        fsGroup: 1000
 | 
			
		||||
  volumeClaimTemplates:
 | 
			
		||||
  - metadata:
 | 
			
		||||
      name: zkdatadir
 | 
			
		||||
      annotations:
 | 
			
		||||
        volume.beta.kubernetes.io/storage-class: slow
 | 
			
		||||
    spec:
 | 
			
		||||
      accessModes: [ "ReadWriteOnce" ]
 | 
			
		||||
      resources:
 | 
			
		||||
        requests:
 | 
			
		||||
          storage: 1Gi
 | 
			
		||||
@ -41,7 +41,7 @@ import java.security.cert.X509Certificate;
 | 
			
		||||
 */
 | 
			
		||||
@Slf4j
 | 
			
		||||
@Component("MqttSslHandlerProvider")
 | 
			
		||||
@ConditionalOnProperty(prefix = "mqtt.ssl", value = "key-store", havingValue = "", matchIfMissing = false)
 | 
			
		||||
@ConditionalOnProperty(prefix = "mqtt.ssl", value = "enabled", havingValue = "true", matchIfMissing = false)
 | 
			
		||||
public class MqttSslHandlerProvider {
 | 
			
		||||
 | 
			
		||||
    public static final String TLS = "TLS";
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user