From f6a905f44fcf8596e604a4693bf4e5d85cfb0bd0 Mon Sep 17 00:00:00 2001 From: paspo Date: Thu, 22 Nov 2018 13:10:16 +0100 Subject: [PATCH] fix shutdown --- upsmon/Dockerfile | 2 ++ upsmon/README.md | 37 +++++++++++++++++++++++++++++++++++++ upsmon/config.json | 9 ++++----- upsmon/run.sh | 3 +-- upsmon/shutdown.sh | 3 +++ 5 files changed, 47 insertions(+), 7 deletions(-) create mode 100644 upsmon/shutdown.sh diff --git a/upsmon/Dockerfile b/upsmon/Dockerfile index 950130f..621082e 100644 --- a/upsmon/Dockerfile +++ b/upsmon/Dockerfile @@ -12,6 +12,8 @@ RUN chmod 770 /var/run/nut # Copy data for add-on COPY run.sh / +COPY shutdown.sh / RUN chmod a+x /run.sh +RUN chmod a+x /shutdown.sh CMD [ "/run.sh" ] diff --git a/upsmon/README.md b/upsmon/README.md index e5497a2..0a7136a 100644 --- a/upsmon/README.md +++ b/upsmon/README.md @@ -2,3 +2,40 @@ [Network UPS Tools](http://networkupstools.org/) is used to connect to another machine running the same software. You just need to specify some connection parameters. You can also configure the shutdown delay (in minutes). + + + + +SHUTDOWNCMD "/sbin/shutdown -h +0" +"delay": "5" non va bene, perchè è solo per master mode. E' il master che decide quando fare SHUTDOWN + +- in batteria +- master manda NOTIFY_SHUTDOWN +- master aspetta FINALDELAY seconds +- master esegue SHUTDOWNCMD + +usare hassio api + +POST /host/shutdown + +On error / Code 400: + +{ + "result": "error", + "message": "" +} +On success / Code 200: + +{ + "result": "ok", + "data": { } +} + +For access to API you need set the X-HASSIO-KEY they will be available for Add-ons/HomeAssistant with envoriment HASSIO_TOKEN. +https://github.com/home-assistant/hassio/blob/master/API.md + +https://developers.home-assistant.io/docs/en/hassio_addon_communication.html + +aggiungere dipendenza curl + +curl -H "X-HASSIO-KEY: $HASSIO_TOKEN" -X POST http://hassio/host/shutdown \ No newline at end of file diff --git a/upsmon/config.json b/upsmon/config.json index bb4f8ca..cbc4475 100644 --- a/upsmon/config.json +++ b/upsmon/config.json @@ -1,7 +1,7 @@ { "name": "Network UPS Tools - netclient", "url": "https://git.asperti.com/paspo/hassio-addons", - "version": "0.1.5", + "version": "0.1.6", "slug": "upsmon", "description": "Connect to a remote NUT server", "startup": "before", @@ -12,6 +12,7 @@ "armhf", "i386" ], + "hassio_api": true, "options": { "credentials": { "user": "monuser", @@ -20,8 +21,7 @@ "ups": { "upsname": "ups", "host": "IPADDR" - }, - "delay": "5" + } }, "schema": { "credentials": { @@ -31,7 +31,6 @@ "ups": { "upsname": "str", "host": "str" - }, - "delay": "int" + } } } diff --git a/upsmon/run.sh b/upsmon/run.sh index dca4c4f..353e36d 100644 --- a/upsmon/run.sh +++ b/upsmon/run.sh @@ -12,7 +12,7 @@ DELAY=$(jq --raw-output ".delay" $CONFIG_PATH) echo " MONITOR ${UPSNAME}@${HOST} 1 ${USER} ${PASS} slave MINSUPPLIES 1 -SHUTDOWNCMD \"/sbin/shutdown -h +0\" +SHUTDOWNCMD \"/shutdown.sh\" POLLFREQ 5 POLLFREQALERT 5 HOSTSYNC 15 @@ -20,7 +20,6 @@ DEADTIME 15 POWERDOWNFLAG /etc/killpower RBWARNTIME 43200 NOCOMMWARNTIME 300 -FINALDELAY ${DELAY} " > /etc/nut/upsmon.conf echo "MODE=netclient" > /etc/nut/nut.conf diff --git a/upsmon/shutdown.sh b/upsmon/shutdown.sh new file mode 100644 index 0000000..063f9d2 --- /dev/null +++ b/upsmon/shutdown.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +curl -H "X-HASSIO-KEY: $HASSIO_TOKEN" -X POST http://hassio/host/shutdown