ualex73 / monitor_docker

Monitor Docker containers from Home Assistant
Apache License 2.0
268 stars 34 forks source link

Can you send a restart command to a container? #45

Closed ndwalters closed 2 years ago

ndwalters commented 3 years ago

Not sure if I'm missing something but was looking for a way to send a restart command to a container (such as home assistant itself)

On a completely unrelated note, I had issues getting it going on a Synology NAS as every time I tried to add the volume /var/run/docker.sock it would disappear on a container restart. I decided to use the TCP socket instead but it is unsupported on Synology's inbuilt docker package. I eventually found the solution was to SSH in to my sonology and edit: /var/packages/Docker/etc/dockerd.json by including the line: "hosts": ["unix:///var/run/docker.sock", "tcp://0.0.0.0:2376"]

Morphy99 commented 3 years ago

I use both this version to monitor and Docker Monitor just for sending a restart command as I didn't figure it out with this.

ualex73 commented 3 years ago

Just released v1.7, so should be soon available in HACS. This adds the service "monitor_docker.restart" to restart a monitored container.

ndwalters commented 3 years ago

Just released v1.7, so should be soon available in HACS. This adds the service "monitor_docker.restart" to restart a monitored container.

Love your work

Morphy99 commented 3 years ago

Just released v1.7, so should be soon available in HACS. This adds the service "monitor_docker.restart" to restart a monitored container.

This is great news. Could you please add start and stop as well? I can bin off Docker Monitor altogether then!

EDIT: I just remembered there's a switch to start/stop! Great work!

milkplus27 commented 3 years ago

Just released v1.7, so should be soon available in HACS. This adds the service "monitor_docker.restart" to restart a monitored container.

Sorry for the noob question but what do I put into 'service data' when calling the monitor_docker.restart service to restart a container?

Any chance of a config example?

Alfiegerner commented 2 years ago

Hi - I'm seeing this error using the restart service:


Logger: custom_components.monitor_docker.switch
Source: custom_components/monitor_docker/switch.py:56
Integration: Monitor Docker (documentation, issues)
First occurred: 16:13:14 (1 occurrences)
Last logged: 16:13:14

Service restart failed, container 'homeassistant' is not configured

And my config:

monitor_docker:
  - name: homemediasystems
    url: tcp://192.168.86.106:2375
    containers:
      - homeassistant
      - mosquitto
      - zigbee2mqtt
    monitored_conditions:
      - version
      - containers_running
      - containers_total
      - state
      - status
      - memory
  - name: storage
    url: tcp://192.168.86.50:2375
    containers:
      - wyze-bridge
      - frigate
    monitored_conditions:
      - version
      - containers_running
      - containers_total
      - state
      - status
      - memory
  - name: piblack_zwave
    url: tcp://192.168.86.44:2375
    containers:
      - zwavejs2mqtt
    monitored_conditions:
      - version
      - containers_running
      - containers_total
      - state
      - status
      - memory
      - allinone

Switches on and off work fine, and error on restart error is same for other services, e.g. zigbee2mqtt.

Alfiegerner commented 2 years ago

Doing some debugging I can see CONF_CONTAINERS] doesn't have all the containers, .e.g it reports zwavejsmqtt for my config.

So it looks like this would work fine with only one docker instance, but not for multiple. I tried rejigging my config to place the ones I'm really in last (i.e. homeassistant docker instance) but the config ordering doesn't solve it.

Alfiegerner commented 2 years ago

hi @ualex73 I've added a PR to fix the restart service for those with multiple hosts, thanks.

ualex73 commented 2 years ago

It is merged, so I will close this one ;-)