17使用systemd方式开机自动启动Home Assistant服务


2018-03-20 15:48:36

转移自网易博客!

首先使用编写文件hass@homeassistant.service,文件内容如下

# 这个文件用于systemd方式自动启动hass服务。
# 这个文件实际是/usr/lib/systemd/system/hass@homeassistant.service,使用下面的命令创建开机自动启动服务。
# sudo systemctl --system daemon-reload
# sudo systemctl enable hass@homeassistant
# sudo systemctl disable hass@homeassistant
# sudo systemctl start hass@homeassistant
#
#
# 参考http://www.ruanyifeng.com/blog/2016/03/systemd-tutorial-commands.html教程建立,更符合linux的常规做法。
# 文件内的命令参考以下内容编写
# 使用手动安装Home Assistant 0.64(树莓派2017-11-29-raspbian-stretch版本,采用PYTHON VIRTUAL ENVIRONMENT虚拟环境)
# Home Assistant 0.64安装方法见https://home-assistant.io/docs/installation/raspberry-pi/
# Home Assistant安装位置/srv/homeassistant,配置文件位置/home/homeassistant/.homeassistant。
# 官方教程systemd启动建立方法 https://home-assistant.io/docs/autostart/systemd/

[Unit]
Description=Home Assistant
After=network-online.target

[Service]
Type=simple
User=%i
ExecStart=/srv/homeassistant/bin/hass -c "/home/homeassistant/.homeassistant"

[Install]
WantedBy=multi-user.target

可以使用nano编辑器新建文件hass@homeassistant.service,如下命令,然后复制上面的内容,再按下Ctrl+O,Y,Ctrl+X。

sudo nano -w /etc/systemd/system/hass@homeassistant.service

或者使用SCP方式将已创建好的文件放置到/usr/lib/systemd/system/下,使用下面的命令启用开机自动启动

sudo systemctl --system daemon-reload

sudo systemctl enable hass@homeassistant

以后使用下面的命令停止stop或者重新启动restart,查看状态status

sudo systemctl stop hass@homeassistant