Using Fedora Atomic with Home Assistant
The Hackerspace Eastermundigen
This blog post contains the details of the setup. They may be useful for others as well. Our new system is running Fedora 27 from Project Atomic
The installation process of an Atomic host is pretty much the same as for Fedora Server or Fedora Workstation. Either create a Live USB device or use PXE to get the installation going. E.g., lauch iPXE and chainload netboot.yxzchain --autofree https://boot.netboot.xyz
. Then let anaconda
guide you through the setup.
After the first boot, copy the SSH keys, use visudo
to add users and perform the usual steps you do for a new system. We only allow SSH with keys, are enforcing the usage of sudo
, need special network settings and a couple of other things. But those configuration settings are irrelevant for a setup in a local network.
If the system is up and running then check if you are using the latest release.
$ sudo atomic host status
State: idle; auto updates disabled
Deployments:
● ostree://fedora-atomic:fedora/27/x86_64/atomic-host
Version: 27.100 (2018-03-13 17:19:44)
Commit: 326f62b93a5cc836c97d31e73a71b6b6b6955c0f225f7651b52a693718e6aa91
GPGSignature: Valid signature by 860E19B0AFA800A1751881A6F55E7430F5282EE4
The release is 27.100. The latest is 27.105. So, let’s update the host and reboot it.
sudo atomic host upgrade
sudo systemctl reboot
You can also see that Docker is already running. No installation needed.
$ sudo systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
Active: active (running) since Thu 2018-03-28 15:44:04 CEST; 35min ago
...
Further we will cover how it works for Home Assistant and Mosquittosystemd
.
Instead of docker
we can use the command-line tool atomic
sudo atomic install docker.io/homeassistant/home-assistant
sudo atomic install docker.io/eclipse-mosquitto
Both containers need additional directories for persistent storage.
sudo mkdir -p /opt/home-assistant
sudo mkdir -p /opt/mosquitto/{config,data,log}
We need a copy of mosquitto.conf
to run Mosquitto later:
sudo curl -o /opt/mosquitto/config/mosquitto.conf \
https://raw.githubusercontent.com/eclipse/mosquitto/master/mosquitto.conf
To handle the containers we created service unit files for the Home AssistantExecStart
line can be found in the documentation about a Docker setup. For Home Assistant
$ su
# cat <<'EOF' >> /etc/systemd/system/home-assistant.service
[Unit]
Description=Home Assistant
Requires=docker.service
Wants=docker.service
After=docker.service
[Service]
Restart=on-failure
RestartSec=10
ExecStart=/usr/bin/docker run --rm --name %p -v /opt/home-assistant:/config:Z -v /etc/localtime:/etc/localtime:ro --network host homeassistant/home-assistant
ExecStop=-/usr/bin/docker stop -t 30 %p
[Install]
WantedBy=multi-user.target
EOF
and for Mosquitto.
# cat <<'EOF' >> /etc/systemd/system/mosquitto.service
[Unit]
Description=Mosquitto MQTT docker container
Requires=docker.service
Wants=docker.service
After=docker.service
[Service]
Restart=on-failure
RestartSec=10
ExecStart=/usr/bin/docker run --name %p -v mosquitto.conf:/opt/mosquitto/config/mosquitto.conf -v /opt/mosquitto/data:/opt/mosquitto/data -v /opt/mosquitto/log:/mosquitto/log -p 1883:1883 -p 9001:9001 eclipse-mosquitto
ExecStop=/usr/bin/docker stop -t 2 %p
ExecStopPost=/usr/bin/docker rm -f %p
[Install]
WantedBy=multi-user.target
EOF
Exit to be not longer root
.
# exit
Reload systemd
to make it aware of the new configurations.
sudo systemctl daemon-reload
Now, both container can be controlled by systemctl
.
sudo systemctl enable home-assistant.service --now
sudo systemctl enable mosquitto.service --now
Check with $ sudo systemctl status [name].service
if there are error or the services are running.
The deployment of NGINX