mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-31 15:12:06 +00:00 
			
		
		
		
	Migrate old-style S6 scripts to s6-rc.d (#4311)
This commit is contained in:
		
							
								
								
									
										26
									
								
								docker/ha-addon-rootfs/etc/s6-overlay/s6-rc.d/esphome/finish
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										26
									
								
								docker/ha-addon-rootfs/etc/s6-overlay/s6-rc.d/esphome/finish
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,26 @@ | ||||
| #!/command/with-contenv bashio | ||||
| # shellcheck shell=bash | ||||
| # ============================================================================== | ||||
| # Home Assistant Community Add-on: ESPHome | ||||
| # Take down the S6 supervision tree when ESPHome dashboard 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}" | ||||
|  | ||||
| bashio::log.info \ | ||||
|   "Service ESPHome dashboard 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 | ||||
							
								
								
									
										45
									
								
								docker/ha-addon-rootfs/etc/s6-overlay/s6-rc.d/esphome/run
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										45
									
								
								docker/ha-addon-rootfs/etc/s6-overlay/s6-rc.d/esphome/run
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,45 @@ | ||||
| #!/command/with-contenv bashio | ||||
| # shellcheck shell=bash | ||||
| # ============================================================================== | ||||
| # Community Hass.io Add-ons: ESPHome | ||||
| # Runs the ESPHome dashboard | ||||
| # ============================================================================== | ||||
| readonly pio_cache_base=/data/cache/platformio | ||||
|  | ||||
| export ESPHOME_IS_HA_ADDON=true | ||||
| export PLATFORMIO_GLOBALLIB_DIR=/piolibs | ||||
|  | ||||
| # we can't set core_dir, because the settings file is stored in `core_dir/appstate.json` | ||||
| # setting `core_dir` would therefore prevent pio from accessing | ||||
| export PLATFORMIO_PLATFORMS_DIR="${pio_cache_base}/platforms" | ||||
| export PLATFORMIO_PACKAGES_DIR="${pio_cache_base}/packages" | ||||
| export PLATFORMIO_CACHE_DIR="${pio_cache_base}/cache" | ||||
|  | ||||
| if bashio::config.true 'leave_front_door_open'; then | ||||
|     export DISABLE_HA_AUTHENTICATION=true | ||||
| fi | ||||
|  | ||||
| if bashio::config.true 'streamer_mode'; then | ||||
|     export ESPHOME_STREAMER_MODE=true | ||||
| fi | ||||
|  | ||||
| if bashio::config.true 'status_use_ping'; then | ||||
|     export ESPHOME_DASHBOARD_USE_PING=true | ||||
| fi | ||||
|  | ||||
| if bashio::config.has_value 'relative_url'; then | ||||
|     export ESPHOME_DASHBOARD_RELATIVE_URL=$(bashio::config 'relative_url') | ||||
| fi | ||||
|  | ||||
| if bashio::config.has_value 'default_compile_process_limit'; then | ||||
|     export ESPHOME_DEFAULT_COMPILE_PROCESS_LIMIT=$(bashio::config 'default_compile_process_limit') | ||||
| else | ||||
|     if grep -q 'Raspberry Pi 3' /proc/cpuinfo; then | ||||
|         export ESPHOME_DEFAULT_COMPILE_PROCESS_LIMIT=1; | ||||
|     fi | ||||
| fi | ||||
|  | ||||
| mkdir -p "${pio_cache_base}" | ||||
|  | ||||
| bashio::log.info "Starting ESPHome dashboard..." | ||||
| exec esphome dashboard /config/esphome --socket /var/run/esphome.sock --ha-addon | ||||
| @@ -0,0 +1 @@ | ||||
| longrun | ||||
							
								
								
									
										63
									
								
								docker/ha-addon-rootfs/etc/s6-overlay/s6-rc.d/init-nginx/run
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										63
									
								
								docker/ha-addon-rootfs/etc/s6-overlay/s6-rc.d/init-nginx/run
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,63 @@ | ||||
| #!/command/with-contenv bashio | ||||
| # shellcheck shell=bash | ||||
| # ============================================================================== | ||||
| # Community Hass.io Add-ons: ESPHome | ||||
| # Configures NGINX for use with ESPHome | ||||
| # ============================================================================== | ||||
| declare certfile | ||||
| declare direct_port | ||||
| declare ingress_interface | ||||
| declare ingress_port | ||||
| declare keyfile | ||||
|  | ||||
| mkdir -p /var/log/nginx | ||||
|  | ||||
| direct_port=$(bashio::addon.port 6052) | ||||
| if bashio::var.has_value "${direct_port}"; then | ||||
|     # Check SSL requirements, if enabled | ||||
|     if bashio::config.true 'ssl'; then | ||||
|         if ! bashio::config.has_value 'certfile'; then | ||||
|             bashio::log.fatal 'SSL is enabled, but no certfile was specified.' | ||||
|             bashio::exit.nok | ||||
|         fi | ||||
|  | ||||
|         if ! bashio::config.has_value 'keyfile'; then | ||||
|             bashio::log.fatal 'SSL is enabled, but no keyfile was specified' | ||||
|             bashio::exit.nok | ||||
|         fi | ||||
|  | ||||
|         certfile="/ssl/$(bashio::config 'certfile')" | ||||
|         keyfile="/ssl/$(bashio::config 'keyfile')" | ||||
|  | ||||
|         if ! bashio::fs.file_exists "/ssl/${certfile}"; then | ||||
|             if ! bashio::fs.file_exists "/ssl/${keyfile}"; then | ||||
|                 # Both files are missing, let's print a friendlier error message | ||||
|                 bashio::log.fatal 'You enabled encrypted connections using the "ssl": true option.' | ||||
|                 bashio::log.fatal "However, the SSL files '${certfile}' and '${keyfile}'" | ||||
|                 bashio::log.fatal "were not found. If you're using Hass.io on your local network and don't want" | ||||
|                 bashio::log.fatal 'to encrypt connections to the ESPHome dashboard, you can manually disable' | ||||
|                 bashio::log.fatal 'SSL by setting "ssl" to false."' | ||||
|                 bashio::exit.nok | ||||
|             fi | ||||
|             bashio::log.fatal "The configured certfile '/ssl/${certfile}' was not found." | ||||
|             bashio::exit.nok | ||||
|         fi | ||||
|  | ||||
|         if ! bashio::fs.file_exists "/ssl/${keyfile}"; then | ||||
|             bashio::log.fatal "The configured keyfile '/ssl/${keyfile}' was not found." | ||||
|             bashio::exit.nok | ||||
|         fi | ||||
|         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 | ||||
|  | ||||
|     sed -i "s/%%port%%/${direct_port}/g" /etc/nginx/servers/direct.conf | ||||
| fi | ||||
|  | ||||
| ingress_port=$(bashio::addon.ingress_port) | ||||
| ingress_interface=$(bashio::addon.ip_address) | ||||
| sed -i "s/%%port%%/${ingress_port}/g" /etc/nginx/servers/ingress.conf | ||||
| sed -i "s/%%interface%%/${ingress_interface}/g" /etc/nginx/servers/ingress.conf | ||||
| @@ -0,0 +1 @@ | ||||
| oneshot | ||||
| @@ -0,0 +1 @@ | ||||
| /etc/s6-overlay/s6-rc.d/init-nginx/run | ||||
							
								
								
									
										25
									
								
								docker/ha-addon-rootfs/etc/s6-overlay/s6-rc.d/nginx/finish
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										25
									
								
								docker/ha-addon-rootfs/etc/s6-overlay/s6-rc.d/nginx/finish
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,25 @@ | ||||
| #!/command/with-contenv bashio | ||||
| # ============================================================================== | ||||
| # Community Hass.io Add-ons: ESPHome | ||||
| # 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}" | ||||
|  | ||||
| bashio::log.info \ | ||||
|   "Service NGINX 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 | ||||
							
								
								
									
										15
									
								
								docker/ha-addon-rootfs/etc/s6-overlay/s6-rc.d/nginx/run
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										15
									
								
								docker/ha-addon-rootfs/etc/s6-overlay/s6-rc.d/nginx/run
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,15 @@ | ||||
| #!/command/with-contenv bashio | ||||
| # shellcheck shell=bash | ||||
| # ============================================================================== | ||||
| # Community Hass.io Add-ons: ESPHome | ||||
| # Runs the NGINX proxy | ||||
| # ============================================================================== | ||||
|  | ||||
| bashio::log.info "Waiting for ESPHome dashboard to come up..." | ||||
|  | ||||
| while [[ ! -S /var/run/esphome.sock ]]; do | ||||
|   sleep 0.5 | ||||
| done | ||||
|  | ||||
| bashio::log.info "Starting NGINX..." | ||||
| exec nginx | ||||
							
								
								
									
										1
									
								
								docker/ha-addon-rootfs/etc/s6-overlay/s6-rc.d/nginx/type
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								docker/ha-addon-rootfs/etc/s6-overlay/s6-rc.d/nginx/type
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1 @@ | ||||
| longrun | ||||
		Reference in New Issue
	
	Block a user