homeassistant-portainer icon indicating copy to clipboard operation
homeassistant-portainer copied to clipboard

[Feature]Add servicies to start/stop/restart

Open Rihan9 opened this issue 11 months ago • 4 comments

Is your feature request related to a problem? Please describe.

Hi, I would like to start/stop but mostly restart my containers. This is because it sometimes happens, for example, that Zigbee2mqtt needs a restart when some devices stop responding correctly.

The best thing would be if the "recreate" function were also included, allowing updates to the containers directly from Home Assistant.

Describe the solution you'd like

a bunch of services:

  • portainer.start
  • portainer.stop
  • portainer.restart
  • portainer.recreate

all of them should accept the sensor entity created by this integration to know which container should be the target.

Additional context

portainer documentation: https://app.swaggerhub.com/apis/portainer/portainer-ce/2.19.4 the docker endpoints shold be wrapped in this portainer endpoint: https://[[HOSTNAME]]/api/endpoints/2/docker/containers/

  • portainer.start documentation: https://docs.docker.com/engine/api/v1.41/#tag/Container/operation/ContainerStart
  • portainer.stop documentation: https://docs.docker.com/engine/api/v1.41/#tag/Container/operation/ContainerStop
  • portainer.restart documentation: https://docs.docker.com/engine/api/v1.41/#tag/Container/operation/ContainerRestart
  • portainer.start documentation: https://docs.docker.com/engine/api/v1.41/#tag/Container/operation/ContainerStart
  • portainer.recreate: this is not a direct api call but a pipeline of it. Following an example:
    • POST: https://[[HOSTNAME]]/api/endpoints/2/docker/images/create?fromImage=lscr.io%2Flinuxserver%2Fduckdns:latest payload: {"fromImage":"lscr.io/linuxserver/duckdns:latest"}
    • POST: https://[[HOSTNAME]]/api/endpoints/2/docker/containers/0c2e56f5a2541ef1a4967fdc98d10c5770779511b1e54edce2fe4ee85ba02a01/stop payload: empty
    • POST: https://[[HOSTNAME]]/api/endpoints/2/docker/containers/0c2e56f5a2541ef1a4967fdc98d10c5770779511b1e54edce2fe4ee85ba02a01/rename?name=%2FDuckDns-old payload: {}
    • POST: https://[[HOSTNAME]]/api/endpoints/2/docker/containers/create?name=DuckDns payload: way too long. I think is the dump of the current image. I think this payload can be derived from the "config" section of this service: https://docs.docker.com/engine/api/v1.41/#tag/Container/operation/ContainerInspect. response: { "Id": "54f592b3e7ce49afe649bb0cf7aafbb0a00113233e6eb0535b2abbc7e5c55305", "Portainer": { "ResourceControl": { "Id": 294, "ResourceId": "54f592b3e7ce49afe649bb0cf7aafbb0a00113233e6eb0535b2abbc7e5c55305", "SubResourceIds": [], "Type": 1, "UserAccesses": [ { "UserId": 1, "AccessLevel": 1 } ], "TeamAccesses": [], "Public": false, "AdministratorsOnly": false, "System": false } }, "Warnings": [] }
    • POST: https://[[HOSTNAME]]/api/endpoints/2/docker/networks/my-bridge/connect payload: {"Container":"54f592b3e7ce49afe649bb0cf7aafbb0a00113233e6eb0535b2abbc7e5c55305"}
    • POST: https://[[HOSTNAME]]/api/endpoints/2/docker/containers/54f592b3e7ce49afe649bb0cf7aafbb0a00113233e6eb0535b2abbc7e5c55305/start payload: {}

Rihan9 avatar Mar 03 '24 10:03 Rihan9

That would be amazing. I was looking for a creating a script to restart a container and found this integration. Very good for monitoring but stop/start/restart can be perfect

Thanks

anktababa avatar Mar 08 '24 14:03 anktababa

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

github-actions[bot] avatar Mar 23 '24 01:03 github-actions[bot]

This issue was closed because it has been stalled for 5 days with no activity.

github-actions[bot] avatar Mar 31 '24 01:03 github-actions[bot]

Hi, is this still a work in progress or has development stopped?

jghaanstra avatar Sep 12 '24 06:09 jghaanstra