#!/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: [url=https://gist.github.com/naholyr/4275302#file-new-service-sh]https://gist.github.com/naholyr/4275302#file-new-service-sh[/url]
PRE_EXEC="cd /srv/homeassistant; source /srv/homeassistant/homeassistant_venv/bin/activate;" #预备运行命令
# Typically /usr/bin/hass
HASS_BIN="hass"
RUN_AS="homeassistant" #用户名
PID_DIR="/var/run/hass"
PID_FILE="$PID_DIR/hass.pid"
CONFIG_DIR="/home/$RUN_AS/.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() {
if [ ! -d "$PID_DIR" ]; then
echo "It seems you did not run"
echo -e "\tservice hass-daemon install"
return 1
fi
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
脚本测试下
#离开子系统debian
exit
#脚本安装下,就是更新到rc.xd
chroot /mnt/sda3/debian /bin/bash service hass-daemon install
#返回如下
Installing Home Assistant Daemon (hass-daemon)
#脚本启动
chroot /mnt/sda3/debian /bin/bash service hass-daemon start
网页测试下,路由器ip:8123,ok下一步。 4. 真开机启动
还需要把启动脚本放到我们的lede x86里,
[/indent][indent]#退出debian,然后
cd /etc
#编辑rc.local文件,可以用vi,也可以用winscp
vi rc.local
在exit 0 前添加一行
chroot /debian/debian service hass-daemon start
rc.local文件如下
# Put your custom commands here that should be executed once[/indent][indent]# the system init finished. By default this file does nothing.
chroot /debian/debian service hass-daemon start
exit 0