From f22b8b181bfe98e899e79b4857d9ec5ac961c797 Mon Sep 17 00:00:00 2001 From: Nathan Gardiner Date: Sun, 19 Feb 2017 03:31:31 -0500 Subject: [PATCH] Updated homeassistant template to fix netdiscover requirement --- INTEGRATION.md | 12 +++++ homeassistant/Makefile | 8 +++- homeassistant/README.md | 20 +++++++-- homeassistant/home-assistant@hass.service | 4 +- homeassistant/runonce.sh | 53 +++++++++++++++++++++-- 5 files changed, 88 insertions(+), 9 deletions(-) create mode 100644 INTEGRATION.md diff --git a/INTEGRATION.md b/INTEGRATION.md new file mode 100644 index 0000000..2306ccb --- /dev/null +++ b/INTEGRATION.md @@ -0,0 +1,12 @@ +# Integration with Automation and Orchestration tools + +## Introduction + +The purpose of this topic is to explore how the hooks and customization features offered could be used to provide tight integration with automation and orchestration tools. + +There are 3 ways in which automation and orchestration tools can hook into the containers created with this platform: +- Through post-deployment configuration, using tools such as ansible, chef, puppet. +- Through a call-back mechanism +- Through the on-demand instantiation of containers + +# Ansible diff --git a/homeassistant/Makefile b/homeassistant/Makefile index c70302c..5d380fe 100644 --- a/homeassistant/Makefile +++ b/homeassistant/Makefile @@ -7,7 +7,12 @@ all: info/init_ok bootstrap global finalize bootstrap: dab bootstrap - dab install python3-pip python3-dev python3-setuptools + # These are known packaged dependancies + dab install netdiscover python3-aiohttp + dab install python3-appdirs python3-chardet python3-dev python3-distro-info python3-fuzzywuzzy + dab install python3-jinja2 python3-mutagen python3-netifaces python3-pip python3-six python3-sqlalchemy + dab install python3-markupsafe python3-pyparsing python3-requests python3-setuptools + dab install python3-tz python3-voluptuous python3-xmltodict python3-yaml python3-zeroconf pip3 install -d . homeassistant install -m 0644 home-assistant@hass.service ${BASEDIR}/etc/systemd/system/home-assistant@hass.service install -m 0600 aiohttp-1.3.1.tar.gz ${BASEDIR}/tmp @@ -33,6 +38,7 @@ bootstrap: dab exec rm -f /tmp/*.whl dab exec rm -f /tmp/*.tar.gz install -m 0700 runonce.sh ${BASEDIR}/etc/init.d/firstboot + dab exec update-rc.d firstboot defaults install -m 0700 custom.sh ${BASEDIR}/tmp dab exec /bin/bash /tmp/custom.sh dab exec rm -f /tmp/custom.sh diff --git a/homeassistant/README.md b/homeassistant/README.md index 34c499b..04f5cbd 100644 --- a/homeassistant/README.md +++ b/homeassistant/README.md @@ -1,5 +1,19 @@ -# Homeassistant +# Home Assistant +- Creates a Ubuntu Xenial template with Python 3 and Home Assistant home automation system +- NOTE: Currently, this image will require some internet ac - Adds any customizations such as root login enabled or SSH keys from ../Makefile.global -- Total uncompressed image size is *700 MB* -- Total compressed image size is *257 MB* +- Total uncompressed image size is *709 MB* +- Total compressed image size is *259 MB* + +## How to use + +- Deploy the Home Assistant template as a Linux Container and wait for it to boot +- Point your web browser to http://[container ip]:8123/ to view the Web Interface + +## Development Notes + +- Home Assistant will try to install all unmet dependancies at startup + - This is an issue for isolated hosts as well as for Python modules which require compilation + - Every new release will need some work to identify dependancy versions that have changed and new dependancies are added to the template + - We first try to meet the dependancies with inbuilt Ubuntu packages, followed by diff --git a/homeassistant/home-assistant@hass.service b/homeassistant/home-assistant@hass.service index 79427df..f4fa965 100644 --- a/homeassistant/home-assistant@hass.service +++ b/homeassistant/home-assistant@hass.service @@ -4,8 +4,8 @@ After=network.target [Service] Type=simple -User=%i -ExecStart=/usr/bin/hass +User=hass +ExecStart=/usr/local/bin/hass [Install] WantedBy=multi-user.target diff --git a/homeassistant/runonce.sh b/homeassistant/runonce.sh index f967c35..10aeae4 100755 --- a/homeassistant/runonce.sh +++ b/homeassistant/runonce.sh @@ -1,6 +1,53 @@ #!/bin/bash +### BEGIN INIT INFO +# Provides: firstboot +# Required-Start: $local_fs +# Required-Stop: +# Should-Start: $network $portmap nfs-common udev-mtab +# Default-Start: S +# Default-Stop: +# Short-Description: First-boot system customization routines +# Description: Provides first-boot system customization for +# proxmox container templates. +# Removes itself entirely when done. +### END INIT INFO -# Once the script has completed execution, delete ourselves -rm $0 +case "$1" in + start) + + # Put first boot routines here + + # Create HASS user + useradd -m hass + + # Upgrade pip + pip3 install --upgrade pip + + # Install netdiscover + pip3 install netdisco + + # Enable the Home Assistant service + /bin/systemctl enable home-assistant@hass + + # Start the Home Assistant service (need to spawn or it will hold up this script) + /bin/systemctl start home-assistant@hass & + + # Once the script has completed execution, delete ourselves + update-rc.d firstboot disable + rm $0 + ;; + stop) + echo "Not Implemented" + ;; + status) + echo "Not Implemented" + ;; + restart|force-reload) + echo "Not Implemented" + ;; + *) + echo "Usage: /etc/init.d/$NAME {start}" >&2 + exit 1 + ;; +esac -exit 0