Add HassIO HostControll support

This commit is contained in:
pvizeli 2017-03-28 12:25:49 +02:00
parent c9681f03c7
commit c54f9dc341
9 changed files with 148 additions and 75 deletions

View File

@ -1,17 +1,46 @@
# HassIO Server # HassIO Server
## REST API Supervisor ## Host Controll
### /supervisor/info Communicate over unix socket with a host daemon.
### /supervisor/network - commands
- Payload: {'hostname': '', 'mode': 'dhcp|fixed', 'ssid': '', 'ip': '', 'netmask': '', 'gateway': ''} ```
# 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 ### /homeassistant/info

View File

@ -10,11 +10,11 @@ runSupervisor() {
docker rm --force resin_supervisor || true docker rm --force resin_supervisor || true
docker run --privileged --name resin_supervisor \ docker run --privileged --name resin_supervisor \
-v /var/run/docker.sock:/var/run/docker.sock \ -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 /resin-data:/data \
-v /var/log/supervisor-log:/var/log \ -v /var/log/supervisor-log:/var/log \
-e DOCKER_SOCKET=/var/run/docker.sock \ -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_SHARE=/resin-data \
-e SUPERVISOR_NAME=resin_supervisor \ -e SUPERVISOR_NAME=resin_supervisor \
-e HOMEASSISTANT_REPOSITORY=${HOMEASSISTANT_REPOSITORY} \ -e HOMEASSISTANT_REPOSITORY=${HOMEASSISTANT_REPOSITORY} \

View File

@ -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
}

View File

@ -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

View File

@ -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

View File

@ -1,44 +1,9 @@
FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:" FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
SRC_URI = " \ SRC_URI += "file://resinhup"
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} \
"
do_install_append() { 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 -d ${D}${bindir}
install -m 0755 ${WORKDIR}/resinhup ${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
} }

View File

@ -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

View File

@ -1,9 +0,0 @@
[Unit]
Description=Resinhup updater timer
[Timer]
OnBootSec=15min
OnUnitInactiveSec=1d
[Install]
WantedBy=resin.target

View File

@ -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 ## Run supervisor on a normal docker host
```bash ```bash
docker run --privileged --name resin_supervisor \ docker run --privileged --name resin_supervisor \
-v /var/run/docker.sock:/var/run/docker.sock \ -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 /resin-data:/data \
-v /var/log/supervisor-log:/var/log \ -v /var/log/supervisor-log:/var/log \
-e DOCKER_SOCKET=/var/run/docker.sock \ -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_SHARE=/resin-data \
-e SUPERVISOR_NAME=resin_supervisor \ -e SUPERVISOR_NAME=resin_supervisor \
-e HOMEASSISTANT_REPOSITORY=${HOMEASSISTANT_REPOSITORY} \ -e HOMEASSISTANT_REPOSITORY=${HOMEASSISTANT_REPOSITORY} \