From c54f9dc3419f8b3fb36c15fb5b8fc38641aa496b Mon Sep 17 00:00:00 2001 From: pvizeli Date: Tue, 28 Mar 2017 12:25:49 +0200 Subject: [PATCH] Add HassIO HostControll support --- hassio_api/README.md | 43 ++++++++++++--- .../start-resin-supervisor | 4 +- .../hassio-host-controll.bb | 37 +++++++++++++ .../hassio-host-controll/hassio-hc | 53 +++++++++++++++++++ .../hassio-host-controll/hassio-hc.service | 11 ++++ .../resinhup/resinhup.bbappend | 37 +------------ .../resinhup/resinhup/resinhup.service | 19 ------- .../resinhup/resinhup/resinhup.timer | 9 ---- supervisor/README.md | 10 +++- 9 files changed, 148 insertions(+), 75 deletions(-) create mode 100644 meta-hassio/recipes-support/hassio-host-controll/hassio-host-controll.bb create mode 100644 meta-hassio/recipes-support/hassio-host-controll/hassio-host-controll/hassio-hc create mode 100644 meta-hassio/recipes-support/hassio-host-controll/hassio-host-controll/hassio-hc.service delete mode 100644 meta-hassio/recipes-support/resinhup/resinhup/resinhup.service delete mode 100644 meta-hassio/recipes-support/resinhup/resinhup/resinhup.timer diff --git a/hassio_api/README.md b/hassio_api/README.md index 45b6d914b..1983176b1 100644 --- a/hassio_api/README.md +++ b/hassio_api/README.md @@ -1,17 +1,46 @@ # HassIO Server -## REST API Supervisor +## Host Controll -### /supervisor/info +Communicate over unix socket with a host daemon. -### /supervisor/network -- Payload: {'hostname': '', 'mode': 'dhcp|fixed', 'ssid': '', 'ip': '', 'netmask': '', 'gateway': ''} +- commands +``` +# info +# reboot +# shutdown +# host-update [v] +# supervisor-update [v] -### /supervisor/reboot +# network info +# network hostname xy +# network wlan ssd xy +# network wlan password xy +# network int ip xy +# network int netmask xy +# network int route xy +``` -### /supervisor/shutdown +- Answer +``` +[{}] +OK|ERROR +``` + +## HassIO REST API + +Interface for HomeAssistant to controll things from supervisor. + +### host +- `/host/network` +Payload: {'hostname': '', 'mode': 'dhcp|fixed', 'ssid': '', 'ip': '', 'netmask': '', 'gateway': ''} + +- `/host/reboot` + +- `/host/shutdown` + +- `/host/info` -## REST API HomeAssistant ### /homeassistant/info diff --git a/meta-hassio/recipes-containers/docker-disk/docker-resin-supervisor-disk/start-resin-supervisor b/meta-hassio/recipes-containers/docker-disk/docker-resin-supervisor-disk/start-resin-supervisor index 604bdcf9e..c4fb76b9a 100644 --- a/meta-hassio/recipes-containers/docker-disk/docker-resin-supervisor-disk/start-resin-supervisor +++ b/meta-hassio/recipes-containers/docker-disk/docker-resin-supervisor-disk/start-resin-supervisor @@ -10,11 +10,11 @@ runSupervisor() { docker rm --force resin_supervisor || true docker run --privileged --name resin_supervisor \ -v /var/run/docker.sock:/var/run/docker.sock \ - -v /var/run/hassio_hc.sock:/var/run/hassio_hc.sock \ + -v /var/run/hassio_hc.sock:/var/run/hassio-hc.sock \ -v /resin-data:/data \ -v /var/log/supervisor-log:/var/log \ -e DOCKER_SOCKET=/var/run/docker.sock \ - -e HASSIO_HC_SOCKET=/var/run/hassio_hc.sock \ + -e HASSIO_HC_SOCKET=/var/run/hassio-hc.sock \ -e SUPERVISOR_SHARE=/resin-data \ -e SUPERVISOR_NAME=resin_supervisor \ -e HOMEASSISTANT_REPOSITORY=${HOMEASSISTANT_REPOSITORY} \ diff --git a/meta-hassio/recipes-support/hassio-host-controll/hassio-host-controll.bb b/meta-hassio/recipes-support/hassio-host-controll/hassio-host-controll.bb new file mode 100644 index 000000000..a221fbe18 --- /dev/null +++ b/meta-hassio/recipes-support/hassio-host-controll/hassio-host-controll.bb @@ -0,0 +1,37 @@ +DESCRIPTION = "hassio device controll" +SECTION = "console/utils" + +SRC_URI = " + file://hassio-hc \ + file://hassio-hc.service \ + " + +inherit allarch systemd + +SYSTEMD_SERVICE_${PN} += "hassio-hc.service" +SYSTEMD_AUTO_ENABLE = "enable" + +RDEPENDS_${PN} = " \ + bash \ + socat \ + " + +FILES_${PN} += " \ + ${systemd_unitdir} \ + ${bindir} \ + " + +do_install() { + install -d ${D}${bindir} + install -m 0775 ${WORKDIR}/hassio-hc ${D}${bindir}/hassio-hc + + if ${@bb.utils.contains('DISTRO_FEATURES','systemd','true','false',d)}; then + install -d ${D}${systemd_unitdir}/system + install -c -m 0644 ${WORKDIR}/hassio-hc.service ${D}${systemd_unitdir}/system + + sed -i -e 's,@BASE_BINDIR@,${base_bindir},g' \ + -e 's,@SBINDIR@,${sbindir},g' \ + -e 's,@BINDIR@,${bindir},g' \ + ${D}${systemd_unitdir}/system/*.service + fi +} diff --git a/meta-hassio/recipes-support/hassio-host-controll/hassio-host-controll/hassio-hc b/meta-hassio/recipes-support/hassio-host-controll/hassio-host-controll/hassio-hc new file mode 100644 index 000000000..f6fa848e8 --- /dev/null +++ b/meta-hassio/recipes-support/hassio-host-controll/hassio-host-controll/hassio-hc @@ -0,0 +1,53 @@ +#!/bin/bash + +set -e + +# Don't run anything before this source as it sets PATH here +source /etc/profile + +# load config +source /usr/sbin/resin-vars +source /etc/resin-supervisor/supervisor.conf + +# +# MAIN +# +while read cmd +do + IFS=" " read -r -a parse <<< $cmd + + if [ ${parse[0]} == "info" ]; then + echo "{'host': 'resinos', 'version': '$RESINOS_VERSION'}" + continue + fi + if [ ${parse[0]} == "reboot" ]; then + systemctl reboot + echo "OK" + continue + fi + if [ ${parse[0]} == "shutdown" ]; then + systemctl poweroff + echo "OK" + continue + fi + if [ ${parse[0]} == "host-update" ]; then + if [ ${parse[@]} -eq 2]; then + resinhub --hostos-version ${parse[1]} + else + resinhub + fi + echo "OK" + continue + fi + if [ ${parse[0]} == "supevisor-update" ]; then + if [ ${parse[@]} -eq 2]; then + update-resin-supervisor --supervisor-tag ${parse[1]} + else + update-resin-supervisor + fi + echo "OK" + continue + fi + + echo "ERROR" +done diff --git a/meta-hassio/recipes-support/hassio-host-controll/hassio-host-controll/hassio-hc.service b/meta-hassio/recipes-support/hassio-host-controll/hassio-host-controll/hassio-hc.service new file mode 100644 index 000000000..c37af0288 --- /dev/null +++ b/meta-hassio/recipes-support/hassio-host-controll/hassio-host-controll/hassio-hc.service @@ -0,0 +1,11 @@ +[Unit] +Description=HassIO HostControll +Wants=resin-supervisor.service +Before=resin-supervisor.service + +[Service] +Type=simple +ExecStart=@BINDIR@/socat UNIX:/var/run/hassio-hc.sock,fork EXEC:@BINDIR@/hassio-hc + +[Install] +WantedBy=resin.target diff --git a/meta-hassio/recipes-support/resinhup/resinhup.bbappend b/meta-hassio/recipes-support/resinhup/resinhup.bbappend index 032d47e4a..e5feb22e1 100644 --- a/meta-hassio/recipes-support/resinhup/resinhup.bbappend +++ b/meta-hassio/recipes-support/resinhup/resinhup.bbappend @@ -1,44 +1,9 @@ FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:" -SRC_URI = " \ - file://resinhup \ - file://hassio.conf \ - file://resinhup.timer \ - file://resinhup.service \ - " - -inherit systemd - -SYSTEMD_SERVICE_${PN} += " \ - resinhup.service \ - resinhup.timer \ - " - -SYSTEMD_AUTO_ENABLE = "enable" - -FILES_${PN} += " \ - ${systemd_unitdir} \ - ${bindir} \ - ${sysconfdir} \ - " +SRC_URI += "file://resinhup" do_install_append() { - install -d ${D}${sysconfdir} - install -m 0755 ${WORKDIR}/hassio.conf ${D}${sysconfdir} - sed -i -e 's:@HASSIO_VERSION@:${HASSIO_VERSION}:g' ${D}${sysconfdir}/hassio.conf - install -d ${D}${bindir} install -m 0755 ${WORKDIR}/resinhup ${D}${bindir} - - if ${@bb.utils.contains('DISTRO_FEATURES','systemd','true','false',d)}; then - install -d ${D}${systemd_unitdir}/system - install -c -m 0644 ${WORKDIR}/resinhup.service ${D}${systemd_unitdir}/system - install -c -m 0644 ${WORKDIR}/resinhup.timer ${D}${systemd_unitdir}/system - - sed -i -e 's,@BASE_BINDIR@,${base_bindir},g' \ - -e 's,@SBINDIR@,${sbindir},g' \ - -e 's,@BINDIR@,${bindir},g' \ - ${D}${systemd_unitdir}/system/*.service - fi } diff --git a/meta-hassio/recipes-support/resinhup/resinhup/resinhup.service b/meta-hassio/recipes-support/resinhup/resinhup/resinhup.service deleted file mode 100644 index d083ef62b..000000000 --- a/meta-hassio/recipes-support/resinhup/resinhup/resinhup.service +++ /dev/null @@ -1,19 +0,0 @@ -[Unit] -Description=Resinhup updater -Requires=\ - docker.service \ - etc-resin\x2dsupervisor.mount \ - tmp.mount -Wants=\ - mnt-boot.mount \ - resin-supervisor.service -After=\ - docker.service \ - tmp.mount \ - mnt-boot.mount \ - etc-resin\x2dsupervisor.mount \ - resin-supervisor.service - -[Service] -Type=simple -ExecStart=@BASE_BINDIR@/bash @BINDIR@/resinhub diff --git a/meta-hassio/recipes-support/resinhup/resinhup/resinhup.timer b/meta-hassio/recipes-support/resinhup/resinhup/resinhup.timer deleted file mode 100644 index 35621ca02..000000000 --- a/meta-hassio/recipes-support/resinhup/resinhup/resinhup.timer +++ /dev/null @@ -1,9 +0,0 @@ -[Unit] -Description=Resinhup updater timer - -[Timer] -OnBootSec=15min -OnUnitInactiveSec=1d - -[Install] -WantedBy=resin.target diff --git a/supervisor/README.md b/supervisor/README.md index a482a173c..322fa3679 100644 --- a/supervisor/README.md +++ b/supervisor/README.md @@ -1,14 +1,20 @@ +# HassIO supervisor + +- Docker socket for Docker management +- HassIO HostControll socket for manage host functions +- Persistent volume to store all data + ## Run supervisor on a normal docker host ```bash docker run --privileged --name resin_supervisor \ -v /var/run/docker.sock:/var/run/docker.sock \ - -v /var/run/hassio_hc.sock:/var/run/hassio_hc.sock \ + -v /var/run/hassio_hc.sock:/var/run/hassio-hc.sock \ -v /resin-data:/data \ -v /var/log/supervisor-log:/var/log \ -e DOCKER_SOCKET=/var/run/docker.sock \ - -e HASSIO_HC_SOCKET=/var/run/hassio_hc.sock \ + -e HASSIO_HC_SOCKET=/var/run/hassio-hc.sock \ -e SUPERVISOR_SHARE=/resin-data \ -e SUPERVISOR_NAME=resin_supervisor \ -e HOMEASSISTANT_REPOSITORY=${HOMEASSISTANT_REPOSITORY} \