Browse Source

init

tags/v1.0.0^0
Robin Thoni 5 years ago
commit
a51624c737
16 changed files with 164 additions and 0 deletions
  1. 4
    0
      .gitignore
  2. 7
    0
      README
  3. 22
    0
      docker-compose.yml
  4. 5
    0
      env
  5. 1
    0
      misc/90-nut-ups.rules
  6. 27
    0
      nut/Dockerfile
  7. 41
    0
      nut/common.sh
  8. 1
    0
      nut/config/nut.conf
  9. 19
    0
      nut/config/ssmtp.conf
  10. 4
    0
      nut/config/ups.conf
  11. 1
    0
      nut/config/upsd.conf
  12. 4
    0
      nut/config/upsd.users
  13. 11
    0
      nut/run.sh
  14. 5
    0
      nut/vars-files
  15. 5
    0
      nut/vars-vars
  16. 7
    0
      update_vars.sh

+ 4
- 0
.gitignore View File

@@ -0,0 +1,4 @@
1
+data
2
+*.swp
3
+docker-compose.override.yml
4
+env_override

+ 7
- 0
README View File

@@ -0,0 +1,7 @@
1
+```
2
+add group nut
3
+cp /90-nut-ups.rules /etc/udev/rules.d
4
+udevadm control --reload-rules && udevadm trigger
5
+```
6
+
7
+set host `nut` group id in docker-compose.yml

+ 22
- 0
docker-compose.yml View File

@@ -0,0 +1,22 @@
1
+version: '2'
2
+
3
+services:
4
+    nut:
5
+        build:
6
+            context: ./nut
7
+            args:
8
+                NUT_GROUP_UID: 1001
9
+        container_name: nut-nut
10
+        privileged: true
11
+#        restart: unless-stopped
12
+        networks:
13
+            nut.internal.docker:
14
+                aliases:
15
+                    - nut.nut.internal.docker
16
+        ports:
17
+            - "127.0.0.1:3493:3493"
18
+        env_file:
19
+            - env
20
+
21
+networks:
22
+    nut.internal.docker:

+ 5
- 0
env View File

@@ -0,0 +1,5 @@
1
+SSMTP_ROOT=root@rthoni.com
2
+SSMTP_MAILHUB=172.17.0.1:10025
3
+SSMTP_MAILDOMAIN=rthoni.com
4
+
5
+NUT_ROOT_PASSWD=change_it

+ 1
- 0
misc/90-nut-ups.rules View File

@@ -0,0 +1 @@
1
+ACTION=="add", SUBSYSTEM=="usb", ATTR{idVendor}=="0463", ATTR{idProduct}=="ffff", MODE="0660", GROUP="nut"

+ 27
- 0
nut/Dockerfile View File

@@ -0,0 +1,27 @@
1
+FROM robinthoni/debian-multiarch:jessie
2
+
3
+ARG CONFIG_DIR=/etc/default/config-files/
4
+ARG NUT_GROUP_UID=1001
5
+
6
+RUN addgroup --gid "${NUT_GROUP_UID}" nut
7
+
8
+RUN apt-get update &&\
9
+    apt-get install -y ssmtp nut &&\
10
+    apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* && \
11
+    rm /etc/cron.*/*
12
+
13
+RUN mkdir -p /var/run/nut/; touch /var/run/nut/upsd.pid; chown nut:nut /etc/nut/*; ls -al /etc/nut
14
+
15
+COPY ./vars-vars /etc/vars-vars
16
+
17
+COPY ./vars-files /etc/vars-files
18
+
19
+COPY ./common.sh /common.sh
20
+
21
+COPY run.sh /run.sh
22
+
23
+RUN mkdir "${CONFIG_DIR}"
24
+
25
+COPY ./config "${CONFIG_DIR}"
26
+
27
+CMD ["/run.sh"]

+ 41
- 0
nut/common.sh View File

@@ -0,0 +1,41 @@
1
+export CONFIG_DIR="/etc/default/config-files/"
2
+
3
+resolv_host()
4
+{
5
+  hostname="${1}"
6
+  ip=$(getent hosts "${hostname}" | cut -d' ' -f1)
7
+  echo "${ip}"
8
+}
9
+
10
+replace_var()
11
+{
12
+  file="${1}"
13
+  var="${2}"
14
+  sed -e "s?${var}?${!var}?g" -i "${file}"
15
+}
16
+
17
+replace_vars()
18
+{
19
+  file="${1}"
20
+  for var in $(cat /etc/vars-vars)
21
+  do
22
+    replace_var "${file}" "${var}"
23
+  done
24
+}
25
+
26
+replace_files()
27
+{
28
+  cat /etc/vars-files | while read line
29
+  do
30
+    filesrc="${CONFIG_DIR}$(echo "${line}" | awk '{print $1}')"
31
+    filedst=$(echo "${line}" | awk '{print $2}')
32
+    if [ -f "${filesrc}" ]
33
+    then
34
+      echo "Expanding file ${filesrc} to ${filedst}"
35
+      cp "${filesrc}" "${filedst}"
36
+      replace_vars "${filedst}"
37
+    else
38
+      echo "File ${filesrc} does not exist. Skipping."
39
+    fi
40
+  done
41
+}

+ 1
- 0
nut/config/nut.conf View File

@@ -0,0 +1 @@
1
+MODE=standalone

+ 19
- 0
nut/config/ssmtp.conf View File

@@ -0,0 +1,19 @@
1
+# Configuartion file for sSMTP sendmail
2
+
3
+# The person who gets all mail for userids < 1000
4
+# Make this empty to disable rewriting.
5
+root=SSMTP_ROOT
6
+
7
+# We want to use this with an exim container. Link these
8
+# so that that container will be reachable as 'exim' in
9
+# this container.
10
+mailhub=SSMTP_MAILHUB
11
+
12
+# Where will the mail seem to come from?
13
+rewriteDomain=SSMTP_MAILDOMAIN
14
+
15
+# The full hostname
16
+#hostname=
17
+
18
+# Are users allowed to set their own From: address? (YES/NO)
19
+FromLineOverride=YES

+ 4
- 0
nut/config/ups.conf View File

@@ -0,0 +1,4 @@
1
+[ups]
2
+driver = usbhid-ups
3
+port = auto
4
+desc = "Eaton Ellipse Pro 650"

+ 1
- 0
nut/config/upsd.conf View File

@@ -0,0 +1 @@
1
+LISTEN 0.0.0.0 3493

+ 4
- 0
nut/config/upsd.users View File

@@ -0,0 +1,4 @@
1
+[admin]
2
+password = NUT_ROOT_PASSWD
3
+upsmon master
4
+

+ 11
- 0
nut/run.sh View File

@@ -0,0 +1,11 @@
1
+#! /usr/bin/env bash
2
+
3
+. /common.sh
4
+
5
+replace_files
6
+
7
+upsdrvctl start
8
+
9
+upsd -D
10
+
11
+sleep 3600

+ 5
- 0
nut/vars-files View File

@@ -0,0 +1,5 @@
1
+ssmtp.conf /etc/ssmtp/ssmtp.conf
2
+nut.conf /etc/nut/nut.conf
3
+ups.conf /etc/nut/ups.conf
4
+upsd.conf /etc/nut/upsd.conf
5
+upsd.users /etc/nut/upsd.users

+ 5
- 0
nut/vars-vars View File

@@ -0,0 +1,5 @@
1
+SSMTP_ROOT
2
+SSMTP_MAILHUB
3
+SSMTP_MAILDOMAIN
4
+
5
+NUT_ROOT_PASSWD

+ 7
- 0
update_vars.sh View File

@@ -0,0 +1,7 @@
1
+#! /usr/bin/env sh
2
+
3
+vars=$(cat env | cut -d= -f1)
4
+for docker in nut
5
+do
6
+  echo "${vars}" > "./${docker}/vars-vars"
7
+done

Loading…
Cancel
Save