Skip to content

Commit 5984058

Browse files
authored
Issue #108 and issue #206 - nut-upsd enhancements (#227)
1 parent 387a986 commit 5984058

7 files changed

Lines changed: 52 additions & 5 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,5 +121,6 @@ Thank you to the following contributors!
121121
* [Devin Bayer](https://github.com/akvadrako)
122122
* [Daniel Muller](https://github.com/DanielMuller)
123123
* [Brian Hechinger](https://github.com/bhechinger)
124+
* [David Powers](https://github.com/dapowers87)
124125

125126
Contents created 2017-25 under [Apache 2.0 License](https://www.apache.org/licenses/LICENSE-2.0) by Rich Braun.

images/nut-upsd/Dockerfile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@ LABEL org.opencontainers.image.authors="Rich Braun docker@instantlinux.net" \
88
org.label-schema.vcs-ref=$VCS_REF \
99
org.label-schema.vcs-url=https://github.com/instantlinux/docker-tools
1010
ARG NUT_VERSION=2.8.3-r2
11-
ENV API_USER=upsmon \
11+
ENV ACTIONS= \
12+
API_USER=upsmon \
1213
API_PASSWORD= \
1314
DESCRIPTION=UPS \
1415
DRIVER=usbhid-ups \
1516
GROUP=nut \
17+
INSTCMDS= \
1618
MAXAGE=15 \
1719
NAME=ups \
20+
NOTIFYCMD= \
1821
NUT_DEBUG_LEVEL=0 \
1922
NUT_QUIET_INIT_SSL=true \
2023
NUT_QUIET_INIT_UPSNOTIFY=true \
@@ -34,7 +37,7 @@ RUN echo '@edge http://dl-cdn.alpinelinux.org/alpine/edge/community' \
3437
>>/etc/apk/repositories && \
3538
apk add --no-cache dash && \
3639
apk add --update --no-cache nut@edge=$NUT_VERSION \
37-
busybox linux-pam \
40+
busybox curl linux-pam \
3841
libcrypto3 libssl3 \
3942
libusb musl net-snmp-libs util-linux
4043

images/nut-upsd/README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,16 @@ These variables can be passed to the image from kubernetes.yaml or docker-compos
3838

3939
Variable | Default | Description |
4040
-------- | ------- | ----------- |
41+
ACTIONS | | One or more user actions allowed (`set`, `fsd`)
4142
API_USER | upsmon| API user
4243
API_PASSWORD | | API password, if not using secret
4344
DESCRIPTION | UPS | user-assigned description
4445
DRIVER | usbhid-ups | driver (see [compatibility list](http://networkupstools.org/stable-hcl.html))
4546
GROUP | nut | local group
47+
INSTCMDS | | `all` or list of allowed commands, see [cmdvartab](https://github.com/networkupstools/nut/blob/master/data/cmdvartab) `CMDDESC` values
4648
MAXAGE | 15 | seconds before declaring driver non-responsive
4749
NAME | ups | user-assigned config name
50+
NOTIFYCMD | | full path of script to run upon notification
4851
NUT_DEBUG_LEVEL | 0 | verbosity of debug messages
4952
NUT_QUIET_INIT_SSL | true | inhibit superfluous startup warning
5053
NUT_QUIET_INIT_UPSNOTIFY | true | inhibit superfluous startup warning
@@ -59,6 +62,8 @@ USER | nut | local user
5962
VENDORID | | vendor ID for ups.conf
6063
### Notes
6164

65+
To define a notify script, volume-mount it via your docker-compose file under /usr/local/bin and set the NOTIFYCMD environment variable. (*Don't* mount any executable scripts under /etc/nut, put them under /usr/local).
66+
6267
If you need a driver other than `usbhid-ups`, the full list of supported drivers can be listed as follows:
6368
```
6469
docker run --rm --entrypoint /bin/ls instantlinux/nut-upsd /usr/lib/nut
@@ -121,9 +126,16 @@ udevadm control --reload-rules && udevadm trigger
121126

122127
When starting up under Debian trixie, an out-of-memory error can be prevented by setting the nofile ulimit to a smaller value than system default: see [issue #1672](https://github.com/networkupstools/nut/issues/1672). The default is set here to 2048.
123128

129+
If you see this error message on startup:
130+
```
131+
Unable to use old-style MONITOR line without a username
132+
Convert it and add a username to upsd.users - see the documentation
133+
```
134+
the most likely cause is a missing or empty secret (`nut-upsd-password`).
135+
124136
### Secrets
125137

126-
If the API user needs a password, you have two ways to specify it: pass the value itself as environment variable API_PASSWORD, or define a Docker secret as follows:
138+
If the API user needs a password, you have two ways to specify it: pass the value itself as environment variable API_PASSWORD (which isn't secure), or define a Docker secret as follows:
127139

128140
| Secret | Description |
129141
| ------ | ----------- |

images/nut-upsd/entrypoint.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,13 @@ EOF
4747
[$API_USER]
4848
password = $API_PASSWORD
4949
upsmon $SERVER
50-
instcmds = ALL
5150
EOF
51+
for ACTION in ${ACTIONS//,/ }; do
52+
echo " actions = $ACTION" >> /etc/nut/upsd.users
53+
done
54+
for CMD in ${INSTCMDS//,/ }; do
55+
echo " instcmds = $CMD" >> /etc/nut/upsd.users
56+
done
5257
fi
5358
if [ -e /etc/nut/local/upsmon.conf ]; then
5459
cp /etc/nut/local/upsmon.conf /etc/nut/upsmon.conf
@@ -57,6 +62,7 @@ EOF
5762
MONITOR $NAME@localhost 1 $API_USER $API_PASSWORD $SERVER
5863
RUN_AS_USER $USER
5964
EOF
65+
[ -z "$NOTIFYCMD" ] || echo "NOTIFYCMD \"$NOTIFYCMD\"" >> /etc/nut/upsmon.conf
6066
fi
6167
touch /etc/nut/.setup
6268
fi

images/nut-upsd/helm/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ sources:
66
- https://github.com/instantlinux/docker-tools
77
- https://github.com/networkupstools/nut
88
type: application
9-
version: 0.1.9
9+
version: 0.1.10
1010
appVersion: "2.8.3-r2"
1111
dependencies:
1212
- name: chartlib

images/nut-upsd/helm/templates/app.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
{{- include "chartlib.configmap" . }}
2+
---
13
{{- include "chartlib.deployment" . }}
24
---
35
{{- include "chartlib.hpa" . }}

images/nut-upsd/helm/values.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
# Default values for nut-upsd.
22
deployment:
33
env:
4+
actions:
45
driver: usbhid-ups
6+
instcmds:
57
maxage: 15
8+
notifycmd:
69
nut_debug_level: 0
710
serial: mustbeset
811
securityContext:
@@ -20,13 +23,25 @@ volumeMounts:
2023
# TODO make this work with pod security policies instead of securityContext
2124
# - name: usb
2225
# mountpath: /dev/ttyUSB0
26+
27+
# To define a notify script, add this in your value overrides, set
28+
# configmap.enabled, and add script under configmap.data.notify
29+
# - name: notifycmd
30+
# mountPath: /usr/local/bin/notify
31+
# readOnly: true
32+
# subPath: notify
2333
- name: secret
2434
mountPath: /run/secrets/nut-upsd-password
2535
readOnly: true
2636
subPath: nut-upsd-password
2737
volumes:
2838
# - name: usb
2939
# hostPath: { path: /dev/ttyUSB0 }
40+
41+
# - name: notifycmd
42+
# configMap:
43+
# name: nut-upsd
44+
# defaultMode: 0555
3045
- name: secret
3146
secret:
3247
secretName: nut-upsd-password
@@ -50,3 +65,11 @@ service:
5065
targetPort: 3493
5166
autoscaling:
5267
enabled: false
68+
69+
configmap:
70+
enabled: false
71+
name: nut-upsd
72+
data: {}
73+
# data:
74+
# notify: |
75+
# your script here

0 commit comments

Comments
 (0)