HomeAssistant Core 자동 시작 설정

먼저 systemd 서비스 파일인 ha@homeassistant.service를 생성합니다. 파일 내용은 다음과 같습니다

# 이 파일은 systemd를 사용하여 ha 서비스를 자동으로 시작하기 위함입니다.
# 실제 파일 경로는 /etc/systemd/system/ha@homeassistant.service 이며, 다음 명령어를 사용하여 부팅 시 자동 시작 서비스를 설정할 수 있습니다.
# sudo systemctl --system daemon-reload
# sudo systemctl enable ha@homeassistant
# sudo systemctl disable ha@homeassistant
# sudo systemctl start ha@homeassistant
#
#
# http://www.ruanyifeng.com/blog/2016/03/systemd-tutorial-commands.html 튜토리얼을 참고하여 리눅스 표준 방식으로 구성합니다.
# 파일 내 명령어는 다음 내용을 참고하여 작성되었습니다
# 수동 설치 방식의 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 설치 위치: /opt/homeassistant, 설정 파일 위치: /home/pi/.homeassistant
# 공식 systemd 시작 방법: https://home-assistant.io/docs/autostart/systemd/

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

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

[Install]
WantedBy=multi-user.target

nano 편집기를 사용하여 ha@homeassistant.service 파일을 새로 생성할 수 있습니다. 다음 명령어를 실행한 후 위 내용을 복사하여 붙여넣고 Ctrl+O, Y, Ctrl+X를 순서대로 누릅니다.sudo nano -w /etc/systemd/system/ha@homeassistant.service

또는 SCP 방식으로 미리 생성된 파일을 /etc/systemd/system/ 디렉토리에 배치할 수 있습니다. 다음 명령어를 사용하여 부팅 시 자동 시작을 활성화합니다sudo systemctl --system daemon-reload

sudo systemctl enable ha@homeassistant

이후에는 stop(중지), restart(재시작), status(상태 확인) 명령어를 사용할 수 있습니다sudo systemctl stop ha@homeassistant

https://www.hachina.io/03.%E9%9D%9E%E5%85%B8%E5%9E%8B%E5%AE%89%E8%A3%85(%E9%AB%98%E7%BA%A7%E7%94%A8%E6%88%B7)/HomeAssistant%20Core%EC%9D%98%20%EC%9E%90%EB%8F%99%20%EC%8B%9C%EC%9E%91/

  • 자동 시작 서비스 관련 명령어 (ha@user 서비스 예시)

  • 서비스 설정 재로드: sudo systemctl --system daemon-reload

  • 서비스 부팅 시 자동 시작 활성화: sudo systemctl enable ha@user

  • 서비스 부팅 시 자동 시작 비활성화: sudo systemctl disable ha@user

  • 서비스 수동 시작: sudo systemctl start ha@user

  • 서비스 수동 중지: sudo systemctl stop ha@user

  • 서비스 수동 재시작: sudo systemctl restart ha@user

  • 서비스 로그 확인: sudo journalctl -f -u ha@user

  • 사용자 정의 명령어 추가

mkdir ~/bin/
echo sudo systemctl restart ha@user > ~/bin/ha-restart
echo sudo systemctl start ha@user > ~/bin/ha-start
echo sudo systemctl stop ha@user > ~/bin/ha-stop
echo sudo journalctl -fu ha@user > ~/bin/ha-log
chmod +x ~/bin/*ha-*

태그: Home Assistant systemd 자동 시작 리눅스 서비스 관리

7월 21일 00:52에 게시됨