fix shutdown

This commit is contained in:
Paolo Asperti 2018-11-22 13:10:16 +01:00
parent f515a9ecf9
commit f6a905f44f
5 changed files with 47 additions and 7 deletions

View File

@ -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" ]

View File

@ -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

View File

@ -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"
}
}
}

View File

@ -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

3
upsmon/shutdown.sh Normal file
View File

@ -0,0 +1,3 @@
#!/bin/sh
curl -H "X-HASSIO-KEY: $HASSIO_TOKEN" -X POST http://hassio/host/shutdown