copy from official addon

This commit is contained in:
john
2026-02-19 21:26:09 +01:00
commit cde15848b4
49 changed files with 1496 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
#!/command/with-contenv bashio
# shellcheck shell=bash
# ==============================================================================
# Home Assistant Community Add-on: Grafana
# Take down the S6 supervision tree when Grafana fails
# ==============================================================================
declare exit_code
readonly exit_code_container=$(</run/s6-linux-init-container-results/exitcode)
readonly exit_code_service="${1}"
readonly exit_code_signal="${2}"
readonly service="Grafana"
bashio::log.info \
"Service ${service} exited with code ${exit_code_service}" \
"(by signal ${exit_code_signal})"
if [[ "${exit_code_service}" -eq 256 ]]; then
if [[ "${exit_code_container}" -eq 0 ]]; then
echo $((128 + $exit_code_signal)) > /run/s6-linux-init-container-results/exitcode
fi
[[ "${exit_code_signal}" -eq 15 ]] && exec /run/s6/basedir/bin/halt
elif [[ "${exit_code_service}" -ne 0 ]]; then
if [[ "${exit_code_container}" -eq 0 ]]; then
echo "${exit_code_service}" > /run/s6-linux-init-container-results/exitcode
fi
exec /run/s6/basedir/bin/halt
fi

View File

@@ -0,0 +1,41 @@
#!/command/with-contenv bashio
# shellcheck shell=bash
# ==============================================================================
# Home Assistant Community Add-on: Grafana
# Runs the Grafana Server
# ==============================================================================
declare -a options
declare -a unsigned_plugins
declare name
declare value
# Wait for Memcached to become available
bashio::net.wait_for 11211
bashio::log.info 'Starting Grafana...'
options+=(--config="/etc/grafana/grafana.ini")
options+=(--homepath="/usr/share/grafana")
# Load custom environment variables
for var in $(bashio::config 'env_vars|keys'); do
name=$(bashio::config "env_vars[${var}].name")
value=$(bashio::config "env_vars[${var}].value")
bashio::log.info "Setting ${name} to ${value}"
export "${name}=${value}"
done
# Verify if we have unsigned custom plugins to load
if bashio::config.has_value 'custom_plugins'; then
for plugin in $(bashio::config 'custom_plugins|keys'); do
name=$(bashio::config "custom_plugins[${plugin}].name")
if bashio::config.true "custom_plugins[${plugin}].unsigned"; then
unsigned_plugins+="${name},"
fi
done
export "GF_PLUGINS_ALLOW_LOADING_UNSIGNED_PLUGINS=${unsigned_plugins}"
fi
# Run Grafana
exec grafana-server "${options[@]}"

View File

@@ -0,0 +1 @@
longrun

View File

@@ -0,0 +1,69 @@
#!/command/with-contenv bashio
# shellcheck shell=bash
# ==============================================================================
# Home Assistant Community Add-on: Grafana
# Configures Grafana
# ==============================================================================
readonly CONFIG="/etc/grafana/grafana.ini"
declare ingress_entry
declare log_level
# Symlink the new style config directory to the old one. People might have
# configurations for Grafana that access the database via the old path.
ln -s "/homeassistant" "/config" \
|| bashio::log.warning "Failed linking Home Assistant configuration alias"
# Configures Grafana with the add-on log level
log_level="Info"
if bashio::config.exists 'log_level'; then
case "$(bashio::string.lower "$(bashio::config 'log_level')")" in
all|trace)
log_level="Trace"
;;
debug)
log_level="Debug"
;;
info|notice)
log_level="Info"
;;
warning)
log_level="Warn"
;;
error)
log_level="Error"
;;
fatal|off)
log_level="Critical"
;;
esac
fi
sed -i "s/level = Info/level = ${log_level}/g" "${CONFIG}"
# Sets unique secret key used for signing cookies.
if ! bashio::fs.file_exists "/data/secret"; then
echo "${SUPERVISOR_TOKEN}" > /data/secret
fi
secret=$(</data/secret)
sed -i "s/secret_key.*/secret_key = ${secret}/g" "${CONFIG}"
ingress_entry=$(bashio::addon.ingress_entry)
sed -i "s#%%ingress_entry%%#${ingress_entry}#g" "${CONFIG}"
# Install user configured/requested Grafana plugins
if bashio::config.has_value 'plugins'; then
for plugin in $(bashio::config 'plugins'); do
grafana-cli plugins install "$plugin" \
|| bashio::exit.nok "Failed installing Grafana plugin: ${plugin}"
done
fi
# Install user configured/requested Grafana custom plugins (from URL)
if bashio::config.has_value 'custom_plugins'; then
for plugin in $(bashio::config 'custom_plugins|keys'); do
name=$(bashio::config "custom_plugins[${plugin}].name")
url=$(bashio::config "custom_plugins[${plugin}].url")
bashio::log.debug "Installing custom plugin ${name} from ${url}"
grafana-cli --pluginUrl ${url} plugins install $name \
|| bashio::exit.nok "Failed installing Grafana custom plugin: ${name} from: ${url}"
done
fi

View File

@@ -0,0 +1 @@
oneshot

View File

@@ -0,0 +1 @@
/etc/s6-overlay/s6-rc.d/init-grafana/run

View File

@@ -0,0 +1,38 @@
#!/command/with-contenv bashio
# shellcheck shell=bash
# ==============================================================================
# Home Assistant Community Add-on: grafana
# Configures NGINX
# ==============================================================================
declare port
declare certfile
declare grafana_user
declare ingress_entry
declare ingress_interface
declare keyfile
port=$(bashio::addon.port 80)
if bashio::var.has_value "${port}"; then
bashio::config.require.ssl
if bashio::config.true 'ssl'; then
certfile=$(bashio::config 'certfile')
keyfile=$(bashio::config 'keyfile')
mv /etc/nginx/servers/direct-ssl.disabled /etc/nginx/servers/direct.conf
sed -i "s#%%certfile%%#${certfile}#g" /etc/nginx/servers/direct.conf
sed -i "s#%%keyfile%%#${keyfile}#g" /etc/nginx/servers/direct.conf
else
mv /etc/nginx/servers/direct.disabled /etc/nginx/servers/direct.conf
fi
ingress_entry=$(bashio::addon.ingress_entry)
sed -i "s#%%ingress_entry%%#${ingress_entry}#g" /etc/nginx/servers/direct.conf
fi
grafana_user='admin'
if bashio::config.has_value 'grafana_ingress_user'; then
grafana_user=$(bashio::config 'grafana_ingress_user')
fi
sed -i "s/%%grafana_user%%/${grafana_user}/g" /etc/nginx/servers/ingress.conf

View File

@@ -0,0 +1 @@
oneshot

View File

@@ -0,0 +1 @@
/etc/s6-overlay/s6-rc.d/init-nginx/run

View File

@@ -0,0 +1,27 @@
#!/command/with-contenv bashio
# shellcheck shell=bash
# ==============================================================================
# Home Assistant Community Add-on: Grafana
# Take down the S6 supervision tree when memcached fails
# ==============================================================================
declare exit_code
readonly exit_code_container=$(</run/s6-linux-init-container-results/exitcode)
readonly exit_code_service="${1}"
readonly exit_code_signal="${2}"
readonly service="memcached"
bashio::log.info \
"Service ${service} exited with code ${exit_code_service}" \
"(by signal ${exit_code_signal})"
if [[ "${exit_code_service}" -eq 256 ]]; then
if [[ "${exit_code_container}" -eq 0 ]]; then
echo $((128 + $exit_code_signal)) > /run/s6-linux-init-container-results/exitcode
fi
[[ "${exit_code_signal}" -eq 15 ]] && exec /run/s6/basedir/bin/halt
elif [[ "${exit_code_service}" -ne 0 ]]; then
if [[ "${exit_code_container}" -eq 0 ]]; then
echo "${exit_code_service}" > /run/s6-linux-init-container-results/exitcode
fi
exec /run/s6/basedir/bin/halt
fi

View File

@@ -0,0 +1,15 @@
#!/command/with-contenv bashio
# shellcheck shell=bash
# ==============================================================================
# Home Assistant Community Add-on: Grafana
# Runs the memcached Server
# ==============================================================================
declare -a options
bashio::log.info 'Starting Memcached...'
options+=(-l 127.0.0.1)
options+=(-m 32)
# Run Memcached
exec s6-setuidgid memcache /usr/bin/memcached "${options[@]}"

View File

@@ -0,0 +1 @@
longrun

View File

@@ -0,0 +1,26 @@
#!/command/with-contenv bashio
# ==============================================================================
# Home Assistant Community Add-on: grafana
# Take down the S6 supervision tree when NGINX fails
# ==============================================================================
declare exit_code
readonly exit_code_container=$(</run/s6-linux-init-container-results/exitcode)
readonly exit_code_service="${1}"
readonly exit_code_signal="${2}"
readonly service="NGINX"
bashio::log.info \
"Service ${service} exited with code ${exit_code_service}" \
"(by signal ${exit_code_signal})"
if [[ "${exit_code_service}" -eq 256 ]]; then
if [[ "${exit_code_container}" -eq 0 ]]; then
echo $((128 + $exit_code_signal)) > /run/s6-linux-init-container-results/exitcode
fi
[[ "${exit_code_signal}" -eq 15 ]] && exec /run/s6/basedir/bin/halt
elif [[ "${exit_code_service}" -ne 0 ]]; then
if [[ "${exit_code_container}" -eq 0 ]]; then
echo "${exit_code_service}" > /run/s6-linux-init-container-results/exitcode
fi
exec /run/s6/basedir/bin/halt
fi

View File

@@ -0,0 +1,12 @@
#!/command/with-contenv bashio
# ==============================================================================
# Home Assistant Community Add-on: grafana
# Runs the Nginx daemon
# ==============================================================================
# Wait for grafana to become available
bashio::net.wait_for 3000
bashio::log.info "Starting NGINX..."
exec nginx

View File

@@ -0,0 +1 @@
longrun