2
0
mirror of https://github.com/schnidrig/openhab-ansible synced 2026-01-11 16:38:47 +01:00

docker stuff

This commit is contained in:
Christian Schnidrig
2021-03-01 08:54:42 +01:00
parent 7bccead600
commit d2e8ae6a9d
6 changed files with 111 additions and 0 deletions

View File

@@ -1,3 +1,6 @@
Note: gave up on this since it repeatedly failed to read from the serial ports after a few hours of operation.
# openhab-ansible
Ansible playbooks to setup openhab on a raspberry pi.

View File

@@ -0,0 +1,67 @@
- name: create directories for openhab
file:
path: "{{ item }}"
owner: pi
group: pi
mode: '0755'
state: directory
loop:
- "{{ openhab_root_dir }}"
- "{{ openhab_root_dir }}/conf"
- "{{ openhab_root_dir }}/userdata"
- "{{ openhab_root_dir }}/addons"
- "{{ openhab_root_dir }}/restore"
# https://hub.docker.com/r/openhab/openhab/
- name: Create openhab container
community.docker.docker_container:
name: "openhab"
image: "openhab/openhab:{{ openhab_version }}"
state: "started"
container_default_behavior: compatibility
command: "bash -c 'if [ -e /restore/restore.zip ]; then echo y |/openhab/runtime/bin/restore /restore/restore.zip ; fi; exec tini -s ./start.sh server'"
#detach: "yes"
#interactive: "yes"
#tty: "yes"
#networks:
# - name: "host"
ports:
- 8080:8080
- 8443:8443
env:
"EXTRA_JAVA_OPTS": "-Duser.timezone={{ timezone }}"
"USER_ID": "{{ openhab_userid }}"
"GROUP_ID": "{{ openhab_groupid }}"
restart_policy: "unless-stopped"
privileged: yes
# devices:
# - "/dev/ttyUSB0:/dev/ttyUSB0"
# - "/dev/ttyAMA0:/dev/ttyAMA0"
mounts:
- target: "/openhab/conf"
source: "{{ openhab_root_dir }}/conf"
type: bind
- target: "/openhab/userdata"
source: "{{ openhab_root_dir }}/userdata"
type: bind
- target: "/openhab/addons"
source: "{{ openhab_root_dir }}/addons"
type: bind
- target: "/restore"
source: "{{ openhab_root_dir }}/restore"
type: bind
- target: /etc/localtime
source: /etc/localtime
type: bind
read_only: yes
- target: /etc/timezone
source: /etc/timezone
type: bind
read_only: yes
- target: /dev
source: /dev
type: bind

View File

@@ -0,0 +1,15 @@
- name: Download Rollershutters dependencies
get_url:
url: "{{ item.src }}"
dest: "/home/pi/openhab/addons/{{ item.name }}"
mode: "0644"
loop:
# https://mvnrepository.com/artifact/org.apache.servicemix.bundles/org.apache.servicemix.bundles.quartz
- name: "org.apache.servicemix.bundles.quartz-2.3.2_1.jar"
src: "https://repo1.maven.org/maven2/org/apache/servicemix/bundles/org.apache.servicemix.bundles.quartz/2.3.2_1/org.apache.servicemix.bundles.quartz-2.3.2_1.jar"
# seems to be included in openhab already
#- name: "snakeyaml-1.27.jar"
# src: "https://repo1.maven.org/maven2/org/yaml/snakeyaml/1.27/snakeyaml-1.27.jar"
tags:
- javalibs

View File

@@ -0,0 +1,17 @@
---
- name: create scripts dir
file:
dest: "/home/pi/bin"
state: directory
- name: create scripts
template:
src: "{{ item }}.sh"
dest: "/home/pi/bin/{{ item }}"
owner: root
group: root
mode: "u=rwx,g=xr,o=rx"
loop:
- client
- backup

View File

@@ -0,0 +1,8 @@
BACKUP_DIR="/home/pi/openhab/userdata/backup"
BACKUP_SERVER_URL="christian@ds3018:/volume1/backup/openhab"
sudo docker exec -ti openhab /openhab/runtime/bin/backup
BACKUP_FILE=$(/bin/ls -tr ${BACKUP_DIR}/ |tail -1)
scp ${BACKUP_DIR}/${BACKUP_FILE} ${BACKUP_SERVER_URL}/

View File

@@ -0,0 +1 @@
sudo docker exec -it openhab /openhab/runtime/bin/client