init home-assistant
This commit is contained in:
28
home-assistant/rootfs/etc/services.d/home-assistant/finish
Executable file
28
home-assistant/rootfs/etc/services.d/home-assistant/finish
Executable file
@@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env bashio
|
||||
# ==============================================================================
|
||||
# Take down the S6 supervision tree when Home Assistant fails
|
||||
# ==============================================================================
|
||||
declare RESTART_EXIT_CODE=100
|
||||
declare SIGNAL_EXIT_CODE=256
|
||||
declare SIGTERM=15
|
||||
declare APP_EXIT_CODE=${1}
|
||||
declare SIGNAL_NO=${2}
|
||||
declare NEW_EXIT_CODE=
|
||||
|
||||
bashio::log.info "Home Assistant Core finish process exit code ${APP_EXIT_CODE}"
|
||||
|
||||
if [[ ${APP_EXIT_CODE} -eq ${RESTART_EXIT_CODE} ]]; then
|
||||
exit 0
|
||||
elif [[ ${APP_EXIT_CODE} -eq ${SIGNAL_EXIT_CODE} ]]; then
|
||||
bashio::log.info "Home Assistant Core finish process received signal ${SIGNAL_NO}"
|
||||
|
||||
NEW_EXIT_CODE=$((128 + SIGNAL_NO))
|
||||
echo ${NEW_EXIT_CODE} > /run/s6-linux-init-container-results/exitcode
|
||||
else
|
||||
bashio::log.info "Home Assistant Core service shutdown"
|
||||
|
||||
echo ${APP_EXIT_CODE} > /run/s6-linux-init-container-results/exitcode
|
||||
fi
|
||||
|
||||
# Make sure to stop the container
|
||||
/run/s6/basedir/bin/halt
|
||||
13
home-assistant/rootfs/etc/services.d/home-assistant/run
Executable file
13
home-assistant/rootfs/etc/services.d/home-assistant/run
Executable file
@@ -0,0 +1,13 @@
|
||||
#!/usr/bin/with-contenv bashio
|
||||
# ==============================================================================
|
||||
# Start Home Assistant service
|
||||
# ==============================================================================
|
||||
|
||||
cd /config || bashio::exit.nok "Can't find config folder!"
|
||||
|
||||
# Enable mimalloc for Home Assistant Core, unless disabled
|
||||
if [[ -z "${DISABLE_JEMALLOC+x}" ]]; then
|
||||
export LD_PRELOAD="/usr/local/lib/libjemalloc.so.2"
|
||||
export MALLOC_CONF="background_thread:true,metadata_thp:auto,dirty_decay_ms:20000,muzzy_decay_ms:20000"
|
||||
fi
|
||||
exec python3 -m homeassistant --config /config
|
||||
49
home-assistant/rootfs/init
Executable file
49
home-assistant/rootfs/init
Executable file
@@ -0,0 +1,49 @@
|
||||
#!/bin/sh -e
|
||||
|
||||
# This is the first program launched at container start.
|
||||
# We don't know where our binaries are and we cannot guarantee
|
||||
# that the default PATH can access them.
|
||||
# So this script needs to be entirely self-contained until it has
|
||||
# at least /command, /usr/bin and /bin in its PATH.
|
||||
|
||||
addpath () {
|
||||
x="$1"
|
||||
IFS=:
|
||||
set -- $PATH
|
||||
IFS=
|
||||
while test "$#" -gt 0 ; do
|
||||
if test "$1" = "$x" ; then
|
||||
return
|
||||
fi
|
||||
shift
|
||||
done
|
||||
PATH="${x}:$PATH"
|
||||
}
|
||||
|
||||
if test -z "$PATH" ; then
|
||||
PATH=/bin
|
||||
fi
|
||||
|
||||
addpath /bin
|
||||
addpath /usr/bin
|
||||
addpath /command
|
||||
export PATH
|
||||
|
||||
# Now we're good: s6-overlay-suexec is accessible via PATH, as are
|
||||
# all our binaries.
|
||||
|
||||
# Skip further init if the user has a given CMD.
|
||||
# This is to prevent Home Assistant from starting twice if the user
|
||||
# decided to override/start via the CMD.
|
||||
if test $# -ne 0 ; then
|
||||
exec "$@"
|
||||
fi
|
||||
|
||||
# Run preinit as root, then run stage0 as the container's user (can be
|
||||
# root, can be a normal user).
|
||||
|
||||
exec s6-overlay-suexec \
|
||||
' /package/admin/s6-overlay/libexec/preinit' \
|
||||
'' \
|
||||
/package/admin/s6-overlay/libexec/stage0 \
|
||||
"$@"
|
||||
Reference in New Issue
Block a user