diff --git a/README.md b/README.md index 22da2ee..c7fbbbb 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,23 @@ - https://hub.docker.com/r/openhab/openhab/ - https://github.com/openhab/openhab-docker +### Database + +Connect to database container: +``` +source openhab.conf +mariadb -h 172.55.55.101 -uopenhab -p${OPENHAB_DATABASE_PASSWORD} openhab +``` + +Install the `jdbc:mariadb` persistence service and add the following lines to `data/conf/services/jdbc.cfg`: +``` +url=jdbc:mariadb://db-openhab:3306/openhab +user=openhab +password=dbpw +``` +Replace `dbpw` with your password from `openhab.config`. + + ### weather binding Copy these folders: - `webapps/weather-data/layouts` -> `./data/userdata/webapps/weather-data/layouts` diff --git a/backup.sh b/backup.sh index d3b4397..2aedeb2 100755 --- a/backup.sh +++ b/backup.sh @@ -15,6 +15,7 @@ mkdir -p $backup_dir/data/conf mkdir -p $backup_dir/data/addons mkdir -p $backup_dir/data/userdata +mkdir -p $backup_dir/data/db ## backup @@ -30,3 +31,6 @@ # openHAB userdata tar -C data -cjf ${PWD}/${backup_dir}/data/userdata/${DATE}.tbz2 userdata + +# openHAB db dir +sudo tar -C data -cjf ${PWD}/${backup_dir}/data/db/${DATE}.tbz2 db diff --git a/conf/mariadb/docker.cnf b/conf/mariadb/docker.cnf new file mode 100644 index 0000000..4f1829d --- /dev/null +++ b/conf/mariadb/docker.cnf @@ -0,0 +1,3 @@ +[mysqld] +skip-host-cache +skip-name-resolve diff --git a/conf/mariadb/mysql.cnf b/conf/mariadb/mysql.cnf new file mode 100644 index 0000000..0de2d9b --- /dev/null +++ b/conf/mariadb/mysql.cnf @@ -0,0 +1,12 @@ +[mysqld] +character-set-client-handshake = FALSE +character-set-server = utf8mb4 +collation-server = utf8mb4_unicode_ci +innodb_file_per_table = TRUE +bind-address = 0.0.0.0 + +[client] +default-character-set = utf8mb4 + +[mysql] +default-character-set = utf8mb4 diff --git a/docker-compose.yml b/docker-compose.yml index f7257d4..0647ec8 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,6 +5,9 @@ image: openhab/openhab:2.3.0-${OPENHAB_ARCH:-amd64}-debian mem_limit: ${OPENHAB_MEMORY_LIMIT:-2g} restart: always + depends_on: + db-openhab: + condition: service_healthy tty: true logging: driver: json-file @@ -30,10 +33,35 @@ - "${OPENHAB_OSGI_BIND:-127.0.0.1}:${OPENHAB_OSGI_PORT:-5555}:5555" networks: openhab-network: - ipv4_address: 172.55.55.100 + ipv4_address: ${IPV4_NETWORK:-172.55.55}.100 aliases: - openhab-main + db-openhab: + image: mariadb:10.3 + restart: always + command: mysqld --skip-name-resolve --skip-host-cache --log-warnings=0 + healthcheck: + test: ["CMD", "mysqladmin", "-uopenhab", "-p$OPENHAB_DATABASE_PASSWORD", "ping", "-h", "localhost"] + interval: 30s + timeout: 30s + retries: 10 + environment: + - MYSQL_ROOT_PASSWORD=${OPENHAB_DATABASE_ROOT} + - MYSQL_DATABASE=openhab + - MYSQL_USER=openhab + - MYSQL_PASSWORD=${OPENHAB_DATABASE_PASSWORD} + volumes: + - /etc/localtime:/etc/localtime:ro + - /etc/timezone:/etc/timezone:ro + - ./data/db/:/var/lib/mysql/ + - ./conf/mariadb:/etc/mysql/conf.d/:ro + networks: + openhab-network: + ipv4_address: ${IPV4_NETWORK:-172.55.55}.101 + aliases: + - openhab-db + networks: openhab-network: @@ -42,5 +70,5 @@ ipam: driver: default config: - - subnet: 172.55.55.0/24 + - subnet: ${IPV4_NETWORK:-172.55.55}.0/24 diff --git a/install.sh b/install.sh index 92e2000..5286055 100755 --- a/install.sh +++ b/install.sh @@ -17,6 +17,14 @@ # replace uid and gid in config file sed -i "/^OPENHAB_USER/c\\\OPENHAB_USER_ID=${uid}" openhab.conf + # db passwords + pw1=$(