U5 리눅스 펌웨어 IOT 첫걸음 : Home Assistant 설치하기

category 컴퓨터.전자기기/U5PVR 가이드 2018.08.26 15:56

안녕하세요.


최근에 샤오미 공기청정기 음성 명령이 가능해짐에 따라 시도해보고 있는 IOT 삽질입니다.


일단 저는 설치부터 해보자 ! 이런 느낌으로 설치기 부터 작성하고 있습니다.


http://blog.djjproject.com/433


상기 방식은 구글 어시스턴트 설정 -> 홈컨트롤 에서 설정을 하는 것인데요. 저도 정규적인 방식을 원하기 때문에 IFTTT 등의 방식은 좋아하지 않습니다.


한편, HomeAssistant 플랫폼을 통해서 실제로 다른 기종 (이기종) 간 연동을 지원하고 있고.. 샤오미와도 연동이 되는 것으로 알고 있습니다. 추가적으로 구글 어시스턴트 연동까지 됩니다.


그래서 일단 달려보도록 하겠습니다.






1. 파이썬 3.6 설치


아쉽게도 데비안8 에서는 파이썬 3.4 가 설치할 수 있는 최대 버전입니다.


제가 리눅스 펌웨어를 데비안9 용으로 만들 계획을 하고 있지만, 데비안8 이미지로 2017년 2월 부터 와온터라.. 변경이 쉽지가 않네요. 적용할것도 많고..


일단은 데비안8로 가기로 결정합니다. (가이드도 모두 수정이 되어야 해서 힘이 듭니다.)


파이썬 소스코드를 받고 압축을 풀어줍니다.


root@AOL-Debian:~# wget https://www.python.org/ftp/python/3.6.3/Python-3.6.3.tgz

--2018-08-26 15:23:59--  https://www.python.org/ftp/python/3.6.3/Python-3.6.3.tgz

Resolving www.python.org (www.python.org)... 151.101.0.223, 151.101.64.223, 151.101.128.223, ...

Connecting to www.python.org (www.python.org)|151.101.0.223|:443... connected.

HTTP request sent, awaiting response... 200 OK

Length: 22673115 (22M) [application/octet-stream]

Saving to: ‘Python-3.6.3.tgz’


Python-3.6.3.tgz           100%[========================================>]  21.62M  7.94MB/s   in 2.7s   


2018-08-26 15:24:02 (7.94 MB/s) - ‘Python-3.6.3.tgz’ saved [22673115/22673115]


FINISHED --2018-08-26 15:24:02--

Total wall clock time: 3.2s


root@AOL-Debian:~# tar xf Python-3.6.3.tgz


빌드할 때 필요한 추가 패키지를 설치합니다.


root@AOL-Debian:~# apt-get install build-essential libpq-dev libssl-dev openssl libffi-dev zlib1g-dev libsqlite3-dev

Reading package lists... Done

Building dependency tree       

Reading state information... Done

build-essential is already the newest version.

openssl is already the newest version.

openssl set to manually installed.

The following extra packages will be installed:

  comerr-dev krb5-multidev libgssrpc4 libkadm5clnt-mit9 libkadm5srv-mit9 libkdb5-7 libpq5 libssl-doc

Suggested packages:

  doc-base krb5-doc krb5-user postgresql-doc-9.4 sqlite3-doc

The following NEW packages will be installed:

  comerr-dev krb5-multidev libffi-dev libgssrpc4 libkadm5clnt-mit9 libkadm5srv-mit9 libkdb5-7 libpq-dev

  libpq5 libsqlite3-dev libssl-dev libssl-doc zlib1g-dev

0 upgraded, 13 newly installed, 0 to remove and 4 not upgraded.

Need to get 3,866 kB of archives.

After this operation, 10.3 MB of additional disk space will be used.

Do you want to continue? [Y/n]


압축푼 폴더로 이동합니다.


그리고 MakeFile 을 만들어 주기 위한 명령어를 입력합니다.


root@AOL-Debian:~# cd Python-3.6.3


root@AOL-Debian:~/Python-3.6.3# ls

aclocal.m4    configure.ac  install-sh Makefile.pre.in  Parser    pyconfig.h.in  Tools

config.guess  Doc     Lib Misc PC    Python

config.sub    Grammar     LICENSE Modules PCbuild   README.rst

configure     Include     Mac Objects Programs  setup.py



root@AOL-Debian:~/Python-3.6.3# ./configure --enable-optimizations --enable-loadable-sqlite-extensions

checking build system type... armv7l-unknown-linux-gnueabihf

checking host system type... armv7l-unknown-linux-gnueabihf

checking for python3.6... no

checking for python3... no

checking for python... python

checking for --enable-universalsdk... no

checking for --with-universal-archs... no

checking MACHDEP... linux

checking for --without-gcc... no

.....................................................................................................
checking for ensurepip... upgrade
checking if the dirent structure of a d_type field... yes
checking for the Linux getrandom() syscall... no
checking for the getrandom() function... no
configure: creating ./config.status
config.status: creating Makefile.pre
config.status: creating Modules/Setup.config
config.status: creating Misc/python.pc
config.status: creating Misc/python-config.sh
config.status: creating Modules/ld_so_aix
config.status: creating pyconfig.h
creating Modules/Setup
creating Modules/Setup.local
creating Makefile


컴파일을 진행하고 설치까지 진행합니다.


root@AOL-Debian:~/Python-3.6.3# make -j 4 && make install

Building with support for profile generation:

make clean

make[1]: Entering directory '/root/Python-3.6.3'

find . -depth -name '__pycache__' -exec rm -rf {} ';'

find . -name '*.py[co]' -exec rm -f {} ';'

find . -name '*.[oa]' -exec rm -f {} ';'

find . -name '*.s[ol]' -exec rm -f {} ';'

find . -name '*.so.[0-9]*.[0-9]*' -exec rm -f {} ';'

find build -name 'fficonfig.h' -exec rm -f {} ';' || true

find: `build': No such file or directory

find build -name '*.py' -exec rm -f {} ';' || true

find: `build': No such file or directory

find build -name '*.py[co]' -exec rm -f {} ';' || true

find: `build': No such file or directory

rm -f pybuilddir.txt

rm -f Lib/lib2to3/*Grammar*.pickle

rm -f Programs/_testembed Programs/_freeze_importlib

find build -type f -a ! -name '*.gc??' -exec rm -f {} ';'

find: `build': No such file or directory

Makefile:1626: recipe for target 'clean' failed

make[1]: [clean] Error 1 (ignored)

rm -f Include/pydtrace_probes.h

............................................................................................................................


컴파일한 바이너리가 잘 작동되는지 체크합니다.




컴파일이 싫지만, 컴파일 합니다. 빨리 데비안9 로 rootfs 를 만들고 싶네요. 이왕 갈꺼 우분투 최신버전으로 다음에 생각해야겠습니다.





2. 홈 어시스턴트를 설치 (virtualenv)


virtualenv 모듈을 설치합니다. 


root@AOL-Debian:~# pip3 install virtualenv

Collecting virtualenv

  Downloading https://files.pythonhosted.org/packages/b6/30/96a02b2287098b23b875bc8c2f58071c35d2efe84f747b64d523721dc2b5/virtualenv-16.0.0-py2.py3-none-any.whl (1.9MB)

    100% |????????????????????????????????| 1.9MB 128kB/s 

Installing collected packages: virtualenv

Successfully installed virtualenv-16.0.0

You are using pip version 9.0.1, however version 18.0 is available.

You should consider upgrading via the 'pip install --upgrade pip' command.


그리고 /home 으로 이동하여 homeassistant 가상환경을 만들어줍니다.


wheel 모듈이 필요함으로 설치를 해줍니다.


root@AOL-Debian:~# cd /home/

root@AOL-Debian:/home# python3 -m venv homeassistant

root@AOL-Debian:/home# cd homeassistant/

root@AOL-Debian:/home/homeassistant# ls

bin  include  lib  pyvenv.cfg

root@AOL-Debian:/home/homeassistant# source ./bin/activate

(homeassistant) root@AOL-Debian:/home/homeassistant# pip3 install wheel

Collecting wheel

  Downloading https://files.pythonhosted.org/packages/81/30/e935244ca6165187ae8be876b6316ae201b71485538ffac1d718843025a9/wheel-0.31.1-py2.py3-none-any.whl (41kB)

    100% |████████████████████████████████| 51kB 551kB/s 

Installing collected packages: wheel

Successfully installed wheel-0.31.1

You are using pip version 9.0.1, however version 18.0 is available.

You should consider upgrading via the 'pip install --upgrade pip' command.\


다음으로 홈 어시스턴트를 설치합니다.


(homeassistant) root@AOL-Debian:/home/homeassistant# pip3 install homeassistant

Collecting homeassistant

  Downloading https://files.pythonhosted.org/packages/19/66/3b08be373e7c89ba18c95f383bb201354d12298f13a29f487f1fa377538e/homeassistant-0.76.2-py3-none-any.whl (2.8MB)

    100% |████████████████████████████████| 2.8MB 91kB/s 

Collecting attrs==18.1.0 (from homeassistant)

  Downloading https://files.pythonhosted.org/packages/41/59/cedf87e91ed541be7957c501a92102f9cc6363c623a7666d69d51c78ac5b/attrs-18.1.0-py2.py3-none-any.whl

Collecting astral==1.6.1 (from homeassistant)

  Downloading https://files.pythonhosted.org/packages/01/2b/0b60f1cef7d2a7a863cd06bae5fc7e3553803739c4834e921b4996920f76/astral-1.6.1-py2.py3-none-any.whl

Collecting pytz>=2018.04 (from homeassistant)

  Downloading https://files.pythonhosted.org/packages/30/4e/27c34b62430286c6d59177a0842ed90dc789ce5d1ed740887653b898779a/pytz-2018.5-py2.py3-none-any.whl (510kB)

    100% |████████████████████████████████| 512kB 175kB/s 

Collecting jinja2>=2.10 (from homeassistant)

  Downloading https://files.pythonhosted.org/packages/7f/ff/ae64bacdfc95f27a016a7bed8e8686763ba4d277a78ca76f32659220a731/Jinja2-2.10-py2.py3-none-any.whl (126kB)

    100% |████████████████████████████████| 133kB 1.3MB/s 

Collecting cryptography==2.3.1 (from homeassistant)

  Downloading https://files.pythonhosted.org/packages/22/21/233e38f74188db94e8451ef6385754a98f3cad9b59bedf3a8e8b14988be4/cryptography-2.3.1.tar.gz (449kB)

    100% |████████████████████████████████| 450kB 550kB/s 

Requirement already satisfied: pip>=8.0.3 in ./lib/python3.6/site-packages (from homeassistant)

Collecting voluptuous==0.11.5 (from homeassistant)

  Downloading https://files.pythonhosted.org/packages/59/95/fa6218477c6999c9b7fdfab7c12c1bd4da2d5930f5eb2b232ec74eb344e7/voluptuous-0.11.5-py2.py3-none-any.whl

Collecting async-timeout==3.0.0 (from homeassistant)

  Downloading https://files.pythonhosted.org/packages/96/0f/e6357458c87fb4ed8f3df215773f3caad40968f10e05552cbd8bd28415e4/async_timeout-3.0.0-py3-none-any.whl

Collecting aiohttp==3.3.2 (from homeassistant)

  Downloading https://files.pythonhosted.org/packages/72/6a/5bbf3544fe8de525f4521506b372dc9c3b13070fe34e911c976aa95631d7/aiohttp-3.3.2.tar.gz (771kB)

    100% |████████████████████████████████| 778kB 319kB/s 

Collecting pyyaml<4,>=3.13 (from homeassistant)

  Downloading https://files.pythonhosted.org/packages/9e/a3/1d13970c3f36777c583f136c136f804d70f500168edc1edea6daa7200769/PyYAML-3.13.tar.gz (270kB)

    100% |████████████████████████████████| 276kB 614kB/s 

Collecting certifi>=2018.04.16 (from homeassistant)

  Downloading https://files.pythonhosted.org/packages/df/f7/04fee6ac349e915b82171f8e23cee63644d83663b34c539f7a09aed18f9e/certifi-2018.8.24-py2.py3-none-any.whl (147kB)

    100% |████████████████████████████████| 153kB 954kB/s 

Collecting PyJWT==1.6.4 (from homeassistant)

  Downloading https://files.pythonhosted.org/packages/93/d1/3378cc8184a6524dc92993090ee8b4c03847c567e298305d6cf86987e005/PyJWT-1.6.4-py2.py3-none-any.whl

Collecting requests==2.19.1 (from homeassistant)

  Downloading https://files.pythonhosted.org/packages/65/47/7e02164a2a3db50ed6d8a6ab1d6d60b69c4c3fdf57a284257925dfc12bda/requests-2.19.1-py2.py3-none-any.whl (91kB)

    100% |████████████████████████████████| 92kB 1.9MB/s 

Collecting MarkupSafe>=0.23 (from jinja2>=2.10->homeassistant)

  Downloading https://files.pythonhosted.org/packages/4d/de/32d741db316d8fdb7680822dd37001ef7a448255de9699ab4bfcbdf4172b/MarkupSafe-1.0.tar.gz

Collecting idna>=2.1 (from cryptography==2.3.1->homeassistant)

  Downloading https://files.pythonhosted.org/packages/4b/2a/0276479a4b3caeb8a8c1af2f8e4355746a97fab05a372e4a2c6a6b876165/idna-2.7-py2.py3-none-any.whl (58kB)

    100% |████████████████████████████████| 61kB 1.1MB/s 

Collecting asn1crypto>=0.21.0 (from cryptography==2.3.1->homeassistant)

  Downloading https://files.pythonhosted.org/packages/ea/cd/35485615f45f30a510576f1a56d1e0a7ad7bd8ab5ed7cdc600ef7cd06222/asn1crypto-0.24.0-py2.py3-none-any.whl (101kB)

    100% |████████████████████████████████| 102kB 1.3MB/s 

Collecting six>=1.4.1 (from cryptography==2.3.1->homeassistant)

  Downloading https://files.pythonhosted.org/packages/67/4b/141a581104b1f6397bfa78ac9d43d8ad29a7ca43ea90a2d863fe3056e86a/six-1.11.0-py2.py3-none-any.whl

Collecting cffi!=1.11.3,>=1.7 (from cryptography==2.3.1->homeassistant)

  Downloading https://files.pythonhosted.org/packages/e7/a7/4cd50e57cc6f436f1cc3a7e8fa700ff9b8b4d471620629074913e3735fb2/cffi-1.11.5.tar.gz (438kB)

    100% |████████████████████████████████| 440kB 549kB/s 

Collecting chardet<4.0,>=2.0 (from aiohttp==3.3.2->homeassistant)

  Downloading https://files.pythonhosted.org/packages/bc/a9/01ffebfb562e4274b6487b4bb1ddec7ca55ec7510b22e4c51f14098443b8/chardet-3.0.4-py2.py3-none-any.whl (133kB)

    100% |████████████████████████████████| 143kB 1.1MB/s 

Collecting multidict<5.0,>=4.0 (from aiohttp==3.3.2->homeassistant)

  Downloading https://files.pythonhosted.org/packages/9d/b9/3cf1b908d7af6530209a7a16d71ab2734a736c3cdf0657e3a06d0209811e/multidict-4.3.1.tar.gz (137kB)

    100% |████████████████████████████████| 143kB 1.1MB/s 

Collecting yarl<2.0,>=1.0 (from aiohttp==3.3.2->homeassistant)

  Downloading https://files.pythonhosted.org/packages/43/b8/057c3e5b546ff4b24263164ecda13f6962d85c9dc477fcc0bcdcb3adb658/yarl-1.2.6.tar.gz (159kB)

    100% |████████████████████████████████| 163kB 1.4MB/s 

Collecting idna-ssl>=1.0 (from aiohttp==3.3.2->homeassistant)

  Downloading https://files.pythonhosted.org/packages/46/03/07c4894aae38b0de52b52586b24bf189bb83e4ddabfe2e2c8f2419eec6f4/idna-ssl-1.1.0.tar.gz

Collecting urllib3<1.24,>=1.21.1 (from requests==2.19.1->homeassistant)

  Downloading https://files.pythonhosted.org/packages/bd/c9/6fdd990019071a4a32a5e7cb78a1d92c53851ef4f56f62a3486e6a7d8ffb/urllib3-1.23-py2.py3-none-any.whl (133kB)

    100% |████████████████████████████████| 143kB 1.6MB/s 

Collecting pycparser (from cffi!=1.11.3,>=1.7->cryptography==2.3.1->homeassistant)

  Downloading https://files.pythonhosted.org/packages/8c/2d/aad7f16146f4197a11f8e91fb81df177adcc2073d36a17b1491fd09df6ed/pycparser-2.18.tar.gz (245kB)

    100% |████████████████████████████████| 256kB 682kB/s 

Building wheels for collected packages: cryptography, aiohttp, pyyaml, MarkupSafe, cffi, multidict, yarl, idna-ssl, pycparser

  Running setup.py bdist_wheel for cryptography ... -

.............................................................................................................................


설치가 완료되었으면 한번 실행을 해봅니다.


(homeassistant) root@AOL-Debian:/home/homeassistant# hass --open-ui

Unable to find configuration. Creating default one in /root/.homeassistant

Config directory: /root/.homeassistant

2018-08-27 07:38:07 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_registered[L]: domain=homeassistant, service=turn_off>

2018-08-27 07:38:07 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_registered[L]: domain=homeassistant, service=turn_on>

2018-08-27 07:38:07 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_registered[L]: domain=homeassistant, service=toggle>

2018-08-27 07:38:07 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_registered[L]: domain=homeassistant, service=stop>

2018-08-27 07:38:07 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_registered[L]: domain=homeassistant, service=restart>

2018-08-27 07:38:07 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_registered[L]: domain=homeassistant, service=check_config>

2018-08-27 07:38:07 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_registered[L]: domain=homeassistant, service=reload_core_config>

2018-08-27 07:38:07 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_registered[L]: domain=persistent_notification, service=create>

2018-08-27 07:38:07 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_registered[L]: domain=persistent_notification, service=dismiss>

2018-08-27 07:38:07 INFO (MainThread) [homeassistant.bootstrap] Home Assistant core initialized

2018-08-27 07:38:07 INFO (MainThread) [homeassistant.loader] Loaded frontend from homeassistant.components.frontend

2018-08-27 07:38:07 INFO (MainThread) [homeassistant.loader] Loaded api from homeassistant.components.api

2018-08-27 07:38:07 INFO (MainThread) [homeassistant.loader] Loaded http from homeassistant.components.http

2018-08-27 07:38:07 INFO (MainThread) [homeassistant.loader] Loaded websocket_api from homeassistant.components.websocket_api

2018-08-27 07:38:07 INFO (MainThread) [homeassistant.loader] Loaded system_log from homeassistant.components.system_log

2018-08-27 07:38:07 INFO (MainThread) [homeassistant.loader] Loaded auth from homeassistant.components.auth

2018-08-27 07:38:07 INFO (MainThread) [homeassistant.loader] Loaded onboarding from homeassistant.components.onboarding

2018-08-27 07:38:07 INFO (MainThread) [homeassistant.loader] Loaded history from homeassistant.components.history

2018-08-27 07:38:07 INFO (MainThread) [homeassistant.loader] Loaded recorder from homeassistant.components.recorder

2018-08-27 07:38:07 INFO (MainThread) [homeassistant.loader] Loaded introduction from homeassistant.components.introduction

2018-08-27 07:38:07 INFO (MainThread) [homeassistant.setup] Setting up introduction

2018-08-27 07:38:07 INFO (MainThread) [homeassistant.components.introduction] 


    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


        Hello, and welcome to Home Assistant!


        We'll hope that we can make all your dreams come true.


        Here are some resources to get started:


         - Configuring Home Assistant:

           https://home-assistant.io/getting-started/configuration/


         - Available components:

           https://home-assistant.io/components/


         - Troubleshooting your configuration:

           https://home-assistant.io/getting-started/troubleshooting-configuration/


         - Getting help:

           https://home-assistant.io/help/


        This message is generated by the introduction component. You can

        disable it in configuration.yaml.


    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    

2018-08-27 07:38:07 INFO (MainThread) [homeassistant.loader] Loaded persistent_notification from homeassistant.components.persistent_notification

2018-08-27 07:38:07 INFO (MainThread) [homeassistant.setup] Setup of domain introduction took 0.0 seconds.

2018-08-27 07:38:07 INFO (MainThread) [homeassistant.core] Bus:Handling <Event component_loaded[L]: component=introduction>

2018-08-27 07:38:07 INFO (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: domain=persistent_notification, service=create, service_data=title=Welcome Home!, message=

Here are some resources to get started:


 - [Configuring Home Assistant](https://home-assistant.io/getting-started/configuration/)

 - [Available components](https://home-assistant.io/components/)

 - [Troubleshooting your configuration](https://home-assistant.io/docs/configuration/troubleshooting/)

 - [Getting help](https://home-assistant.io/help/)


To not see this card popup in the future, edit your config in

`configuration.yaml` and disable the `introduction` component.

>

2018-08-27 07:38:07 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=persistent_notification.notification, old_state=None, new_state=<state persistent_notification.notification=notifying; title=Welcome Home!, message=Here are some resources to get started:


 - [Configuring Home Assistant](https://home-assistant.io/getting-started/configuration/)

 - [Available components](https://home-assistant.io/components/)

 - [Troubleshooting your configuration](https://home-assistant.io/docs/configuration/troubleshooting/)

 - [Getting help](https://home-assistant.io/help/)


To not see this card popup in the future, edit your config in

`configuration.yaml` and disable the `introduction` component. @ 2018-08-26T22:38:07.663797+00:00>>

2018-08-27 07:38:07 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_executed[L]>

2018-08-27 07:38:07 INFO (SyncWorker_0) [homeassistant.util.package] Attempting install of aiohttp_cors==0.7.0


WebUI 로 접근해 봅니다.


초기 실행까지 시간이 조금 걸립니다. 초기에는 필요한 모듈도 같이 설치하는 부분이 있기 때문에 조금 기다려 주시면 될것 같습니다.






3. 부팅 시 자동실행 설정하기


일단 초기에 그냥 한번 실행하여 설정파일들이 /root/.homeassistant 에 생성되었습니다. 이 파일을 /home/homeassistant/.homeassistant 로 옮기고 시작합니다.


(homeassistant) root@AOL-Debian:/home/homeassistant# mv /root/.homeassistant/ .



root@AOL-Debian:~# nano /etc/init.d/hass


#!/bin/sh

### BEGIN INIT INFO

# Provides:          hass

# Required-Start:    $local_fs $network $named $time $syslog

# Required-Stop:     $local_fs $network $named $time $syslog

# Default-Start:     2 3 4 5

# Default-Stop:      0 1 6

# Description:       Home\ Assistant

### END INIT INFO


# /etc/init.d Service Script for Home Assistant

# Created with: https://gist.github.com/naholyr/4275302#file-new-service-sh

PRE_EXEC="cd /home/homeassistant; python3 -m venv .; source bin/activate;"

# Typically /usr/bin/hass

HASS_BIN="hass"

RUN_AS="root"

PID_DIR="/var/run/hass"

PID_FILE="$PID_DIR/hass.pid"

CONFIG_DIR="/home/homeassistant/.homeassistant"

LOG_DIR="/var/log/homeassistant"

LOG_FILE="$LOG_DIR/home-assistant.log"

FLAGS="-v --config $CONFIG_DIR --pid-file $PID_FILE --log-file $LOG_FILE --daemon"


start() {

  create_piddir

  if [ -f $PID_FILE ] && kill -0 $(cat $PID_FILE) 2> /dev/null; then

    echo 'Service already running' >&2

    return 1

  fi

  echo -n 'Starting service… ' >&2

  local CMD="$PRE_EXEC $HASS_BIN $FLAGS;"

  su -s /bin/bash -c "$CMD" $RUN_AS

  if [ $? -ne 0 ]; then

    echo "Failed" >&2

  else

    echo 'Done' >&2

  fi

}


stop() {

  if [ ! -f "$PID_FILE" ] || ! kill -0 $(cat "$PID_FILE") 2> /dev/null; then

    echo 'Service not running' >&2

    return 1

  fi

  echo -n 'Stopping service… ' >&2

  kill $(cat "$PID_FILE")

  while ps -p $(cat "$PID_FILE") > /dev/null 2>&1; do sleep 1;done;

  rm -f $PID_FILE

  echo 'Done' >&2

}


install() {

  echo "Installing Home Assistant Daemon (hass-daemon)"

  update-rc.d hass-daemon defaults

  create_piddir

  mkdir -p $CONFIG_DIR

  chown $RUN_AS $CONFIG_DIR

  mkdir -p $LOG_DIR

  chown $RUN_AS $LOG_DIR

}


uninstall() {

  echo "Are you really sure you want to uninstall this service? The INIT script will"

  echo -n "also be deleted! That cannot be undone. [yes|No] "

  local SURE

  read SURE

  if [ "$SURE" = "yes" ]; then

    stop

    remove_piddir

    echo "Notice: The config directory has not been removed"

    echo $CONFIG_DIR

    echo "Notice: The log directory has not been removed"

    echo $LOG_DIR

    update-rc.d -f hass-daemon remove

    rm -fv "$0"

    echo "Home Assistant Daemon has been removed. Home Assistant is still installed."

  fi

}


create_piddir() {

  if [ ! -d "$PID_DIR" ]; then

    mkdir -p $PID_DIR

    chown $RUN_AS "$PID_DIR"

  fi

}


remove_piddir() {

  if [ -d "$PID_DIR" ]; then

    if [ -e "$PID_FILE" ]; then

      rm -fv "$PID_FILE"

    fi

    rmdir -fv "$PID_DIR"

  fi

}


case "$1" in

  start)

    start

    ;;

  stop)

    stop

    ;;

  install)

    install

    ;;

  uninstall)

    uninstall

    ;;

  restart)

    stop

    start

    ;;

  *)

    echo "Usage: $0 {start|stop|restart|install|uninstall}"

esac


root@AOL-Debian:~# chmod a+x /etc/init.d/hass


root@AOL-Debian:~# service hass start

Starting service… Done


root@AOL-Debian:~# update-rc.d hass defaults


설치가 정상적으로 되었습니다.





4. 간단히 둘러보기 및 다음 기회에..


요즘 시간이 너무 없어서 일단 설치 방법만 올려드리고 이 플랫폼을 잘 써먹을 방법은 짬짬히 봐야겠습니다. ㅎㅎ






항상 새로운것을 접하려면, 그 만한 공부가 필요합니다.


카페에 와서 ARM 기반 NAS / 인텔기반 NAS / 트랜스코딩 / KODI / 리눅스  등등의 활용 기술을 배우면서, 여러방면으로 문을 두들기고 있습니다. 


요즘에는 이걸 붙잡고 있을 시간이 크게 많지 않아서, 시간날때, 생각날때, 갑자기 심심할때,... 들여다보고 있습니다.


일단 설치는 쉽게 되었기 때문에 다른 기기와 연동은 금방일듯 합니다.







댓글을 달아 주세요