apcupsd clusterfähig gemacht

This commit is contained in:
Michael Grote 2021-02-07 12:46:03 +01:00
parent 8c9f7fa79f
commit 0bea8f7340
13 changed files with 352 additions and 71 deletions

View File

@ -111,6 +111,23 @@
- qemu-guest-agent
- open-vm-tools
### mgrote.apcupsd
apcupsd_master_onbatterydelay: 10
apcupsd_master_batterylevel_for_shutdown: 50
apcupsd_master_minutes_for_shutdown: 10
apcupsd_master_nologon_when_active: disable
apcupsd_slave_onbatterydelay: 10
apcupsd_slave_batterylevel_for_shutdown: 50
apcupsd_slave_minutes_for_shutdown: 10
apcupsd_slave_nologon_when_active: disable
apcupsd_nis_master: on
# apcupsd_nis_master_hostname: pve2.grote.lan # wird pro host gesetzt
apcupsd_nis_master_listen_ip: 0.0.0.0
apcupsd_nis_master_listen_port: 3551
apcupsd_ups_name: APC-BX950U-GR
# apcupsd_nis_master: false # wird pro host gesetzt
# Ansible Variablen
### User
ansible_user: "ansible-user"

View File

@ -45,11 +45,6 @@
tmux_conf_destination: "/root/.tmux.conf"
tmux_bashrc_destination: "/root/.bashrc"
tmux_standardsession_name: "default"
### mgrote.apcupsd
ONBATTERYDELAY: 10
BATTERYLEVEL: 50
MINUTES: 10
NOLOGON: disable
### mgrote.zfs_tools_cron
zfs_arc_max: "12884901888"
zfs_pools:

View File

@ -0,0 +1,32 @@
---
### mgrote.zfs_manage_datasets
# "Daten"-Datasets verwalte ich händisch!
# zfs create -o encryption=aes-256-gcm -o keyformat=passphrase hdd_data_raidz/data_crypt
# zfs create hdd_data_raidz/videos
# Pools müssen vorher erstellt sein!
# SSD_VM_MIRROR
# zpool create -f -o ashift=12 ssd_vm_mirror mirror /dev/disk/by-id/ata-ADATA_SU650_2J4420001210 /dev/disk/by-id/ata-ADATA_SU650_2J4420001241
# HDD_VM_MIRROR
# zpool create -f -o ashift=12 hdd_vm_mirror mirror /dev/disk/by-id/ata-WDC_WD20EACS-11BHUB0_WD-WCAZA3124223 /dev/disk/by-id/ata-WDC_WD20EZRX-00D8PB0_WD-WMC4M1682516 mirror /dev/disk/by-id/ata-WDC_WD30EZRX-00DC0B0_WD-WMC1T3979908 /dev/disk/by-id/ata-TOSHIBA_DT01ACA300_83M2DRAKS
# HDD_DATA_RAIDZ
# zpool create -f -o ashift=12 hdd_data_raidz raidz /dev/disk/by-id/ata-WDC_WD80EZAZ-11TDBA0_2SG991TJ /dev/disk/by-id/ata-WDC_WD80EZAZ-11TDBA0_2SGA23EJ /dev/disk/by-id/ata-ST8000DM004-2CX188_ZCT1AK0F
zfs_datasets:
- dataset: ssd_vm_mirror/vm
state: present
compression: lz4
sync: disabled
xattr: sa
dnodesize: auto
atime: on
snapdir: hidden
- dataset: hdd_vm_mirror/vm
state: present
compression: lz4
sync: disabled
xattr: sa
dnodesize: auto
atime: on
snapdir: hidden
### mgrote.apcupsd
apcupsd_nis_master: true
apcupsd_nis_master_hostname: pve-test.grote.lan

View File

@ -1,29 +1,32 @@
---
### mgrote.zfs_manage_datasets
# "Daten"-Datasets verwalte ich händisch!
# zfs create -o encryption=aes-256-gcm -o keyformat=passphrase hdd_data_raidz/data_crypt
# zfs create hdd_data_raidz/videos
# Pools müssen vorher erstellt sein!
# SSD_VM_MIRROR
# zpool create -f -o ashift=12 ssd_vm_mirror mirror /dev/disk/by-id/ata-ADATA_SU650_2J4420001210 /dev/disk/by-id/ata-ADATA_SU650_2J4420001241
# HDD_VM_MIRROR
# zpool create -f -o ashift=12 hdd_vm_mirror mirror /dev/disk/by-id/ata-WDC_WD20EACS-11BHUB0_WD-WCAZA3124223 /dev/disk/by-id/ata-WDC_WD20EZRX-00D8PB0_WD-WMC4M1682516 mirror /dev/disk/by-id/ata-WDC_WD30EZRX-00DC0B0_WD-WMC1T3979908 /dev/disk/by-id/ata-TOSHIBA_DT01ACA300_83M2DRAKS
# HDD_DATA_RAIDZ
# zpool create -f -o ashift=12 hdd_data_raidz raidz /dev/disk/by-id/ata-WDC_WD80EZAZ-11TDBA0_2SG991TJ /dev/disk/by-id/ata-WDC_WD80EZAZ-11TDBA0_2SGA23EJ /dev/disk/by-id/ata-ST8000DM004-2CX188_ZCT1AK0F
zfs_datasets:
- dataset: ssd_vm_mirror/vm
state: present
compression: lz4
sync: disabled
xattr: sa
dnodesize: auto
atime: on
snapdir: hidden
- dataset: hdd_vm_mirror/vm
state: present
compression: lz4
sync: disabled
xattr: sa
dnodesize: auto
atime: on
snapdir: hidden
### mgrote.zfs_manage_datasets
# "Daten"-Datasets verwalte ich händisch!
# zfs create -o encryption=aes-256-gcm -o keyformat=passphrase hdd_data_raidz/data_crypt
# zfs create hdd_data_raidz/videos
# Pools müssen vorher erstellt sein!
# SSD_VM_MIRROR
# zpool create -f -o ashift=12 ssd_vm_mirror mirror /dev/disk/by-id/ata-ADATA_SU650_2J4420001210 /dev/disk/by-id/ata-ADATA_SU650_2J4420001241
# HDD_VM_MIRROR
# zpool create -f -o ashift=12 hdd_vm_mirror mirror /dev/disk/by-id/ata-WDC_WD20EACS-11BHUB0_WD-WCAZA3124223 /dev/disk/by-id/ata-WDC_WD20EZRX-00D8PB0_WD-WMC4M1682516 mirror /dev/disk/by-id/ata-WDC_WD30EZRX-00DC0B0_WD-WMC1T3979908 /dev/disk/by-id/ata-TOSHIBA_DT01ACA300_83M2DRAKS
# HDD_DATA_RAIDZ
# zpool create -f -o ashift=12 hdd_data_raidz raidz /dev/disk/by-id/ata-WDC_WD80EZAZ-11TDBA0_2SG991TJ /dev/disk/by-id/ata-WDC_WD80EZAZ-11TDBA0_2SGA23EJ /dev/disk/by-id/ata-ST8000DM004-2CX188_ZCT1AK0F
zfs_datasets:
- dataset: ssd_vm_mirror/vm
state: present
compression: lz4
sync: disabled
xattr: sa
dnodesize: auto
atime: on
snapdir: hidden
- dataset: hdd_vm_mirror/vm
state: present
compression: lz4
sync: disabled
xattr: sa
dnodesize: auto
atime: on
snapdir: hidden
### mgrote.apcupsd
apcupsd_nis_master: true
apcupsd_nis_master_hostname: pve2.grote.lan

View File

@ -1,25 +1,68 @@
## mgrote.apcupsd
### Beschreibung
Installiert APCUPSD fuer eine APC UPS mit USB Verbindung.
Benoetigt mgrote.postfix.
https://linux.die.net/man/5/apcupsd.conf
* Installiert apcupsd.
* Auf einem PC als "Master", hier ist die USV per USB angeschlossen.
* Auf allen anderen PCs als "Slave", diese OCs pollen alle n Sekunden den Master.
* Benoetigt mgrote.postfix.
* Getestet mit: APC-BX950U-GR
### Links
* http://www.apcupsd.org/manual/#checking-your-configuration-file
* https://linux.die.net/man/5/apcupsd.conf
### Funktioniert auf
- [x] ProxMox 6.1
### Variablen + Defaults
##### Wohin gehen die Benachrichtigungsmails bei Stromausfall
empfaenger_mail: michael.grote@posteo.de
##### Zeitspanne in Sekunden, ab der der Systemdienst einen Stromausfall annimmt. Nuetzlich, um sehr kurze Ausfaelle ignorieren zu koennen. Jeweils Master und Slave.
```yaml
apcupsd_master_onbatterydelay: 10
apcupsd_slave_onbatterydelay: 10
```
##### Durch die USV gemeldete Restkapazitaet in Prozent, ab der der Rechner heruntergefahren wird. Jeweils Master und Slave.
```yaml
apcupsd_master_batterylevel_for_shutdown: 50
apcupsd_slave_batterylevel_for_shutdown: 60
```
##### apcupsd will shutdown the system during a power failure when the remaining runtime on batteries as internally calculated by the UPS falls below the specified minutes. Jeweils Master und Slave.
```yaml
apcupsd_master_minutes_for_shutdown: 10
apcupsd_slave_minutes_for_shutdown: 11
```
##### Specifies when apcupsd should create the NOLOGON file to prevent users from logging on to the system. Jeweils Master und Slave.
```yaml
apcupsd_master_nologon_when_active: always
apcupsd_slave_nologon_when_active: always
```
##### Zeitspanne in Sekunden, ab der der Systemdienst einen Stromausfall annimmt. Nuetzlich, um sehr kurze Ausfaelle ignorieren zu koennen.
ONBATTERYDELAY: 10
##### Ist der Server MASTER, also ist die USV an diesem Computer angeschlossen, kann nur für einen PC "true" sein. Jeweils Master und Slave.
```yaml
apcupsd_nis_master: "true"
```
##### Durch die USV gemeldete Restkapazitaet in Prozent, ab der der Rechner heruntergefahren wird
BATTERYLEVEL: 50
##### Wenn "true" ist dieser Host master, für alle anderen "false", das muss nicht explizit gesetzt werden.
```yaml
apcupsd_nis_master: on
```
##### apcupsd will shutdown the system during a power failure when the remaining runtime on batteries as internally calculated by the UPS falls below the specified minutes.
MINUTES: 10
##### FQDN oder IP des "master"
```yaml
apcupsd_nis_master_hostname: pve2.grote.lan
```
##### Specifies when apcupsd should create the nologon file to prevent users from logging on to the system.
NOLOGON: always
##### Interface auf dem der "Master" erreichbar ist.
```yaml
apcupsd_nis_master_listen_ip: 0.0.0.0
```
##### Post auf dem der "Master" erreichbar ist.
```yaml
apcupsd_nis_master_listen_port: 3551
```
##### Name der USV
```yaml
apcupsd_ups_name: APC-BX950U-GR
```

View File

@ -1,5 +1,16 @@
---
ONBATTERYDELAY: 10
BATTERYLEVEL: 50
MINUTES: 10
NOLOGON: always
apcupsd_master_onbatterydelay: 10
apcupsd_master_batterylevel_for_shutdown: 50
apcupsd_master_minutes_for_shutdown: 10
apcupsd_master_nologon_when_active: always
apcupsd_slave_onbatterydelay: 10
apcupsd_slave_batterylevel_for_shutdown: 60
apcupsd_slave_minutes_for_shutdown: 11
apcupsd_slave_nologon_when_active: always
apcupsd_nis_master: on
apcupsd_nis_master_hostname: pve2.grote.lan
apcupsd_nis_master_listen_ip: 0.0.0.0
apcupsd_nis_master_listen_port: 3551
apcupsd_ups_name: APC-BX950U-GR

View File

@ -1,4 +1,5 @@
- name: apcupsd installieren
---
- name: install apcupsd packages
ansible.builtin.package:
name:
- apcupsd
@ -8,13 +9,25 @@
become: yes
notify: apc_access_mail
- name: apcupsd kopieren
- name: create master config
include_tasks: master.yml
when:
- apcupsd_nis_master
- apcupsd_nis_master is defined
- name: create slave config
include_tasks: slave.yml
when:
- not apcupsd_nis_master
- apcupsd_nis_master is defined
- name: copy apcupsd file
become: yes
ansible.builtin.template:
src: "apcupsd"
dest: "/etc/default/apcupsd"
- name: empfaenger_mail_setzen
- name: set mail recipient
become: yes
ansible.builtin.lineinfile:
path: /etc/apcupsd/apccontrol #wo
@ -22,9 +35,8 @@
line: export SYSADMIN={{ empfaenger_mail }} #ersetze durch...
backrefs: yes #verhindert das die zeile bei "nicht zutreffen" am ende der datei angefuegt wird: https://docs.ansible.com/ansible/latest/modules/lineinfile_module.html#parameters
- name: apcupsd.conf_kopieren
- name: copy test script
become: yes
ansible.builtin.template:
src: "apcupsd.conf"
dest: "/etc/apcupsd/apcupsd.conf"
notify: restart_apcupsd #benachrichtigt handlers/main.yml-restart-apcupsd_restart um den dient neuzustarten, nur wenn hier status "changed" ausgeworfen wird"
src: "apccontrol.save"
dest: "/etc/apcupsd/apccontrol.save"

View File

@ -0,0 +1,7 @@
---
- name: templating master_apcupsd.conf
become: yes
ansible.builtin.template:
src: "master_apcupsd.conf"
dest: "/etc/apcupsd/apcupsd.conf"
notify: restart_apcupsd #benachrichtigt handlers/main.yml-restart-apcupsd_restart um den dient neuzustarten, nur wenn hier status "changed" ausgeworfen wird"

View File

@ -0,0 +1,7 @@
---
- name: templating slave_apcupsd.conf
become: yes
ansible.builtin.template:
src: "slave_apcupsd.conf"
dest: "/etc/apcupsd/apcupsd.conf"
notify: restart_apcupsd #benachrichtigt handlers/main.yml-restart-apcupsd_restart um den dient neuzustarten, nur wenn hier status "changed" ausgeworfen wird"

View File

@ -0,0 +1,137 @@
#!@SCRIPTSHELL@
#
# Safe apccontrol for testing.
#
# This apccontrol can be used for testing without fear
# that it will bring your system down
# @configure_input@
#
prefix=@prefix@
exec_prefix=@exec_prefix@
APCUPSD=@sbindir@/apcupsd
SHUTDOWN=@SHUTDOWN@
SCRIPTDIR=@sysconfdir@
#
case "$1" in
killpower)
wall <<EOF
apccontrol: ${APCUPSD} --killpower would have been.
EOF
;;
commfailure)
wall <<EOF
apccontrol: Communications with UPS lost.
EOF
;;
commok)
wall <<EOF
apccontrol: Communciations with UPS restored.
EOF
;;
powerout)
wall <<EOF
apccontrol: Warning power loss detected.
EOF
;;
onbattery)
wall <<EOF
apccontrol: Power failure. Running on UPS batteries.
EOF
;;
offbattery)
wall <<EOF
apccontrol: Off battery. Mains returned.
EOF
;;
failing)
wall <<EOF
apccontrol: UPS battery power exhausted. Doing shutdown.
EOF
;;
timeout)
wall <<EOF
apccontrol: UPS battery runtime limit exceeded. Doing shutdown.
EOF
;;
loadlimit)
wall <<EOF
apccontrol: UPS battery discharge limit reached. Doing shutdown.
EOF
;;
runlimit)
wall <<EOF
apccontrol: UPS battery runtime percent reached. Doing shutdown.
EOF
;;
doreboot)
wall <EOF
apccontrol: ${SHUTDOWN} for reboot would have been called.
EOF
;;
doshutdown)
wall <<EOF
apccontrol: ${SHUTDOWN} for halt would have been called.
EOF
;;
mainsback)
wall <<EOF
apccontrol: Power has returned...
EOF
;;
annoyme)
wall <<EOF
apccontrol: Power problems please logoff.
EOF
;;
emergency)
wall <<EOF
apccontrol: ${SHUTDOWN} for emergency halt would have been called.
EOF
;;
changeme)
wall <<EOF
apccontrol: Emergency! UPS batteries have failed.
Change them NOW !
EOF
;;
remotedown)
wall <<EOF
apccontrol: ${SHUTDOWN} for remote halt would have been called.
EOF
;;
startselftest)
wall <<EOF
apccontrol: start self test would have been called.
EOF
;;
endselftest)
wall <<EOF
apccontrol: end self test would have been called.
EOF
;;
*) echo "Usage: ${0##*/} command"
echo " warning: this script is intended to be launched by"
echo " apcupsd and should never be launched by users."
exit 1
;;
esac

View File

@ -1,14 +0,0 @@
## apcupsd.conf v1.1 ##
UPSCABLE usb
UPSTYPE usb
DEVICE
UPSNAME APC-BX950U-GR
ONBATTERYDELAY {{ ONBATTERYDELAY }}
BATTERYLEVEL {{ BATTERYLEVEL }}
MINUTES {{ MINUTES }}
NOLOGON {{ NOLOGON }}

View File

@ -0,0 +1,16 @@
## apcupsd.conf v1.1 ##
UPSCABLE usb
UPSTYPE usb
DEVICE
UPSNAME {{ apcupsd_ups_name }}
NETSERVER ON
NISIP {{ apcupsd_nis_master_listen_ip }}
NISPORT {{ apcupsd_nis_master_listen_port }}
ONBATTERYDELAY {{ apcupsd_master_onbatterydelay }}
BATTERYLEVEL {{ apcupsd_master_batterylevel_for_shutdown }}
MINUTES {{ apcupsd_master_minutes_for_shutdown }}
NOLOGON {{ apcupsd_master_nologon_when_active }}

View File

@ -0,0 +1,15 @@
## apcupsd.conf v1.1 ##
UPSCABLE ether
UPSTYPE net
DEVICE {{ apcupsd_nis_master_hostname }}:{{ apcupsd_nis_master_listen_port }}
LOCKFILE /var/lock
UPSCLASS standalone
UPSMODE disable
POLLTIME 10
ONBATTERYDELAY {{ apcupsd_slave_onbatterydelay }}
BATTERYLEVEL {{ apcupsd_slave_batterylevel_for_shutdown }}
MINUTES {{ apcupsd_slave_minutes_for_shutdown }}
NOLOGON {{ apcupsd_slave_nologon_when_active }}