Files
hassio-addons/portainer_agent
Alexandre 7cd844ac9f fix(templates): populate /run/s6/container_environment when the entrypoint is PID 1 (#3013)
Add-ons that override the base image's ENTRYPOINT ["/init"] with
ENTRYPOINT ["/usr/bin/env"] plus CMD ["/ha_entrypoint.sh"] never run s6-overlay's
stage 1, so nothing creates /run/s6/container_environment. `with-contenv` empties
the environment and repopulates it from that directory, which means every script
carrying a #!/usr/bin/with-contenv shebang outside the three globs whose shebang
ha_entrypoint.sh rewrites either exits non-zero before its first line of logic
(directory missing: s6-envdir errors) or runs against whatever a cont-init script
happened to leave there.

Measured in a running add-on of this repo whose PID 1 is /ha_entrypoint.sh: a
with-contenv script saw 16 environment variables where the entrypoint has 110, with
SUPERVISOR_TOKEN among the missing. Neither failure prints anything, so all that
surfaces is whatever the caller makes of a non-zero exit — a Docker HEALTHCHECK
reading "unhealthy" for eight months, in the case that prompted this. Cron jobs,
user-facing CLI wrappers and the user's own script.sh share the blind spot.

Dump the environment here instead, with s6-dumpenv, which is what stage 1 would
have done. Guarded on being PID 1 and on with-contenv existing, so it neither runs
under /init — where stage 1 already wrote the directory — nor warns in images that
have no with-contenv to fix.

Filled in a sibling directory and renamed into place rather than written live. A
half-populated envdir is worse than an absent one: s6-envdir accepts it, so a
with-contenv script starts and runs against an environment quietly missing
SUPERVISOR_TOKEN, where an absent one stops it at its shebang. A HEALTHCHECK can run
alongside PID 1, and rename(2) means such a reader sees the directory either absent
or complete. Measured with a racing poller over 664 samples: only 0 or 110 entries,
never a partial count.

The directory is cleared first rather than written over. /run is not a tmpfs in
these containers, so an image layer could persist entries there, and merging into
them would leave variables PID 1 does not have, including a stale SUPERVISOR_TOKEN.
A failed rm aborts the attempt, since mkdir -p accepts a surviving
symlink-to-directory and would let the dump follow it.

A failed seed leaves the directory absent, which is how this already fails today, so
the failure mode is unchanged rather than newly degraded — but it now says so.

Placed after the shebang probe on purpose. The probe's first candidate is
"/command/with-contenv bashio" and it fails today in exactly these add-ons, so the
probe falls through to "/usr/bin/env bashio". Seeding earlier would make that first
candidate start succeeding and flip the shebang of every cont-init and service
script that lands here, which is a much larger change than this fixes.

Refs #3006

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-08-24 14:30:13 +02:00
..
2025-11-19 21:35:05 +01:00
2025-09-07 23:05:45 +00:00
2025-09-07 23:05:45 +00:00
2026-08-23 23:24:39 +00:00

Home assistant add-on: Portainer_agent

I maintain this and other Home Assistant add-ons in my free time: keeping up with upstream changes, HA changes, and testing on real hardware takes a lot of time (and some money). I use around 5-10 of my >110 addons so regularly I install test machines (and purchase some test services such as vpn) that I don't use myself to troubleshoot and improve the addons

If this add-on saves you time or makes your setup easier, I would be very grateful for your support!

Buy me a coffee Donate via PayPal

Addon informations

Version Ingress Arch

Codacy Badge GitHub Super-Linter Builder

Thanks to everyone having starred my repo! To star it click on the image below, then it will be on top right. Thanks!

Stargazers repo roster for @alexbelgium/hassio-addons

downloads evolution

About


The Portainer Agent is a workaround for a Docker API limitation when using the Docker API to manage a Docker environment. The user interactions with specific resources (containers, networks, volumes and images) are limited to those available on the node targeted by the Docker API request.

This container is based on the official docker image (https://github.com/portainer/agent) and modified using @homecentr logic (https://github.com/homecentr/docker-portainer-agent) to use in the homeassistant base images.

WARNING

The portainer_agent add-on is really powerful and gives you virtually access to your whole system. While this add-on is created and maintained with care and with security in mind, in the wrong or inexperienced hands, it could damage your system.

Installation


The installation of this add-on is pretty straightforward and not different in comparison to installing any other add-on.

  1. Add my add-ons repository to your home assistant instance (in supervisor addons store at top right, or click button below if you have configured my HA) Open your Home Assistant instance and show the add add-on repository dialog with a specific repository URL pre-filled.
  2. Install this add-on.
  3. Click the Save button to store your configuration.
  4. Set the add-on options to your preferences
  5. Start the add-on.
  6. Check the logs of the add-on to see if everything went well.
  7. Open the webUI and adapt the software options

Instructions (thanks @Mincka) : Disable protection mode, then from the other Portainer cluster, add a new environment of type "Agent" with the IP address of HA and port 9001

image

Configuration

Use the add-on env_vars option to pass extra environment variables (uppercase or lowercase names). See https://github.com/alexbelgium/hassio-addons/wiki/Add-Environment-variables-to-your-Addon-2 for details.


Main options :

    "PORTAINER_AGENT_ARGS": Command line arguments to the portainer-agent executable

Other options : see https://github.com/portainer/agent#deployment-options

Support

Create an issue on github