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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM