1
0
Fork 0
mirror of https://github.com/roles-ansible/role_akku_warning.git synced 2024-08-16 10:09:50 +02:00

introducing systemd timer

This commit is contained in:
L3D 2021-11-15 00:13:19 +01:00
parent 61d4dc0e96
commit 5b4af12078
Signed by: l3d
GPG key ID: CD08445BFF4313D1
6 changed files with 63 additions and 10 deletions

View file

@ -3,6 +3,14 @@
ansible role: akku warning ansible role: akku warning
========================== ==========================
# rewrite in progress!!!
```
cronjob is going to be removed!
systemd timer intruduces
variables may change!
```
This ansible role installs a bash script (per cronjob) which is executed every 3 minutes. This bash script checks if the battery level is below 25 percent and is currently not charging. If this is the case, the program [zenity](https://de.wikipedia.org/wiki/Zenity) installed by this role will generate a popup message stating that the battery is low. This ansible role installs a bash script (per cronjob) which is executed every 3 minutes. This bash script checks if the battery level is below 25 percent and is currently not charging. If this is the case, the program [zenity](https://de.wikipedia.org/wiki/Zenity) installed by this role will generate a popup message stating that the battery is low.
While the battery level is between 15 and 10 percent, it will also attempt to play a sound. But this does not (yet) work reliably. While the battery level is between 15 and 10 percent, it will also attempt to play a sound. But this does not (yet) work reliably.

18
handlers/main.yml Normal file
View file

@ -0,0 +1,18 @@
---
- name: systemctl daemon-reload
become: true
ansible.builtin.systemd:
daemon_reload: true
- name: systemctl start battery_check.service
become: true
ansible.builtin.systemd:
name: 'battery_check.service'
state: started
- name: systemctl enable battery_check.timer
become: true
ansible.builtin.systemd:
name: 'battery_check.timer'
enabled: true
state: started

View file

@ -1,12 +1,24 @@
--- ---
- name: Check akku every 3 minutes - name: setup battery_check.service
become: true become: true
ansible.builtin.cron: ansible.builtin.template:
name: check if akku still okay src: 'templates/battery_check.service.j2'
job: /opt/akku.sh dest: '/usr/lib/systemd/system/battery_check.service'
minute: '*/3' mode: 0755
user: '{{ akku_user }}' owner: root
cron_file: /etc/crontab group: root
state: absent notify:
failed_when: false - systemctl daemon-reload
- systemctl start battery_check.service
- name: setup battery_check.timer
become: true
ansible.builtin.template:
src: 'templates/battery_check.timer.j2'
dest: '/usr/lib/systemd/system/battery_check.timer'
mode: 0755
owner: root
group: root
notify:
- systemctl daemon-reload
- systemctl enable battery_check.timer

View file

@ -0,0 +1,10 @@
[Unit]
Description=Check battery charging status
[Service]
Type=simple
ExecStart=/opt/akku.sh
User={{ akku_user }}
[Install]
WantedBy=multi-user.target

View file

@ -0,0 +1,5 @@
[Unit]
Description=Check battery charging status every 3 Minutes
[Timer]
OnCalendar=*:0/3

View file

@ -1,3 +1,3 @@
--- ---
playbook_version_number: 8175 playbook_version_number: 8176
playbook_version_path: 'role-akku-warning_chaos-bodensee_github.com.version' playbook_version_path: 'role-akku-warning_chaos-bodensee_github.com.version'