Merge pull request 'Rebuild our Dashboard on hobbes' (#295) from hobbes-rebuild into master
Reviewed-on: Netz39_Admin/netz39-infra-ansible#295 Reviewed-by: dkdent <dkdent@netz39.de>
This commit is contained in:
commit
bb013fe97e
9 changed files with 121 additions and 111 deletions
17
files/hobbes/grafana-kiosk.service
Normal file
17
files/hobbes/grafana-kiosk.service
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
[Unit]
|
||||||
|
Description=Grafana Kiosk
|
||||||
|
After=network.target
|
||||||
|
Wants=network.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
User=root
|
||||||
|
|
||||||
|
ExecStart=/usr/local/bin/kiosk.sh
|
||||||
|
|
||||||
|
Restart=always
|
||||||
|
|
||||||
|
PIDFile=/run/kiosk.pid
|
||||||
|
ExecStop=/bin/kill -s SIGTERM $MAINPID
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
|
@ -8,7 +8,6 @@
|
||||||
|
|
||||||
roles:
|
roles:
|
||||||
|
|
||||||
|
|
||||||
tasks:
|
tasks:
|
||||||
- name: Install packages needed for the system
|
- name: Install packages needed for the system
|
||||||
# This is a list of all packages,
|
# This is a list of all packages,
|
||||||
|
@ -16,15 +15,9 @@
|
||||||
ansible.builtin.apt:
|
ansible.builtin.apt:
|
||||||
state: present
|
state: present
|
||||||
name:
|
name:
|
||||||
# This is needed for the user-executed tasks
|
- mosquitto-clients
|
||||||
- acl
|
- fbi
|
||||||
# Regular packages
|
|
||||||
- lightdm
|
|
||||||
- accountsservice
|
|
||||||
- unclutter
|
|
||||||
- lxde
|
|
||||||
- chromium-browser
|
|
||||||
- rng-tools
|
|
||||||
|
|
||||||
- name: Remove the screensavers
|
- name: Remove the screensavers
|
||||||
ansible.builtin.apt:
|
ansible.builtin.apt:
|
||||||
|
@ -53,50 +46,23 @@
|
||||||
|
|
||||||
|
|
||||||
### Kiosk setup
|
### Kiosk setup
|
||||||
#
|
|
||||||
# https://github.com/grafana/grafana-kiosk
|
|
||||||
|
|
||||||
- name: Ensure kiosk user is there
|
- name: Ensure kiosk user is there
|
||||||
ansible.builtin.user:
|
ansible.builtin.user:
|
||||||
name: "{{ kiosk_user }}"
|
name: "{{ kiosk_user }}"
|
||||||
groups: audio,plugdev,input,netdev
|
groups: audio,plugdev,input,netdev
|
||||||
append: yes
|
append: yes
|
||||||
|
|
||||||
|
- name: Install Kiosk script
|
||||||
- name: Create bin directory
|
ansible.builtin.template:
|
||||||
file:
|
src: templates/hobbes/kiosk.sh.j2
|
||||||
path: "/home/{{ kiosk_user }}/bin"
|
dest: /usr/local/bin/kiosk.sh
|
||||||
owner: "{{ kiosk_user }}"
|
owner: root
|
||||||
|
group: root
|
||||||
mode: '0755'
|
mode: '0755'
|
||||||
state: directory
|
|
||||||
|
|
||||||
- name: Download grafana-kiosk
|
|
||||||
ansible.builtin.get_url:
|
|
||||||
url: "https://github.com/grafana/grafana-kiosk/releases/download/{{ kiosk_software_version }}/grafana-kiosk.linux.{{ kiosk_software_arch }}"
|
|
||||||
dest: "/home/{{ kiosk_user }}/bin/grafana-kiosk"
|
|
||||||
mode: '0755'
|
|
||||||
force: no
|
|
||||||
|
|
||||||
|
|
||||||
- name: Setup autologin in lightdm
|
|
||||||
ansible.builtin.blockinfile:
|
|
||||||
path: /etc/lightdm/lightdm.conf
|
|
||||||
block: |
|
|
||||||
[Seat:seat0]
|
|
||||||
autologin-user = pi
|
|
||||||
autologin-user-timeout = 0
|
|
||||||
autologin-in-background = False
|
|
||||||
|
|
||||||
- name: Remove autostart
|
|
||||||
# None of the things in autostart are needed or wanted
|
|
||||||
ansible.builtin.file:
|
|
||||||
path: /etc/xdg/lxsession/LXDE/autostart
|
|
||||||
state: absent
|
|
||||||
|
|
||||||
|
|
||||||
- name: Add systemd service
|
- name: Add systemd service
|
||||||
ansible.builtin.template:
|
ansible.builtin.copy:
|
||||||
src: templates/hobbes/grafana-kiosk.service.j2
|
src: files/hobbes/grafana-kiosk.service
|
||||||
dest: /etc/systemd/system/grafana-kiosk.service
|
dest: /etc/systemd/system/grafana-kiosk.service
|
||||||
owner: root
|
owner: root
|
||||||
group: root
|
group: root
|
||||||
|
@ -108,12 +74,4 @@
|
||||||
enabled: true
|
enabled: true
|
||||||
state: started
|
state: started
|
||||||
|
|
||||||
- name: Set default systemd target to graphical
|
|
||||||
ansible.builtin.file:
|
|
||||||
src: /lib/systemd/system/graphical.target
|
|
||||||
dest: /etc/systemd/system/default.target
|
|
||||||
state: link
|
|
||||||
force: yes
|
|
||||||
|
|
||||||
|
|
||||||
handlers:
|
handlers:
|
||||||
|
|
|
@ -209,6 +209,22 @@
|
||||||
tags:
|
tags:
|
||||||
- labelprinter
|
- labelprinter
|
||||||
|
|
||||||
|
- name: Setup docker container for Grafana Screenshots
|
||||||
|
docker_container:
|
||||||
|
name: grafana-screenshot
|
||||||
|
image: mrtux/grafana-screenshot:latest
|
||||||
|
pull: true
|
||||||
|
restart_policy: unless-stopped
|
||||||
|
detach: yes
|
||||||
|
env:
|
||||||
|
MQTT_BROKER_URL: "{{ kiosk_mqtt_host }}"
|
||||||
|
MQTT_TOPIC: "{{ kiosk_mqtt_topic }}"
|
||||||
|
GRAFANA_DASHBOARD_URL: "{{ kiosk_grafana_url }}"
|
||||||
|
GRAFANA_USERNAME: "{{ kiosk_grafana_user }}"
|
||||||
|
GRAFANA_PASSWORD: "{{ kiosk_grafana_pass }}"
|
||||||
|
tags:
|
||||||
|
- grafana-screenshot
|
||||||
|
|
||||||
handlers:
|
handlers:
|
||||||
- name: restart mosquitto
|
- name: restart mosquitto
|
||||||
docker_container:
|
docker_container:
|
||||||
|
|
|
@ -2,8 +2,6 @@
|
||||||
server_admin: "admin+hobbes@netz39.de"
|
server_admin: "admin+hobbes@netz39.de"
|
||||||
mac: "b8:27:eb:f9:43:43"
|
mac: "b8:27:eb:f9:43:43"
|
||||||
kiosk_user: pi
|
kiosk_user: pi
|
||||||
kiosk_software_version: v1.0.6
|
kiosk_mqtt_host: "mqtt.n39.eu"
|
||||||
kiosk_software_arch: "armv7"
|
kiosk_mqtt_topic: "Netz39/Things/HackingDashboard/Screenshot"
|
||||||
kiosk_url: "https://grafana.n39.eu/d/xpLj6UD4z/hobbes-space-monitor?orgId=1"
|
docker_data_root: "/srv/docker"
|
||||||
kiosk_grafana_user: "{{ vault_kiosk_grafana_user }}"
|
|
||||||
kiosk_grafana_pass: "{{ vault_kiosk_grafana_pass }}"
|
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
$ANSIBLE_VAULT;1.1;AES256
|
$ANSIBLE_VAULT;1.1;AES256
|
||||||
32313738636231313036633334333934643839636563646334336533316436653263623461643438
|
32343732363234396136616164383833316634373061376235656566303761646461626138363432
|
||||||
6362343635626266313466643465343962663931623662320a316635613231313930343937363064
|
3264633461383739393138396233303839363132343866370a306433306364666438623434383036
|
||||||
33326164333137633039376363643539346463303934333430626431336637326638363233333234
|
63366634313937623736393636393030333961323335323762663538373631353331353162613362
|
||||||
3132333533376134380a383837616331303536623665383735663531343538366332313236386137
|
3661653539306365350a333263383537643738373939376563356566313732613766303931633630
|
||||||
62306436663934383363616332316262313762633261396535663533636665633532316366386430
|
6462
|
||||||
65343830376634633365343337313433643465323662313563366463393664653766623338623635
|
|
||||||
30653263303761316238396634346337636461643231303561353133643162633934323161663539
|
|
||||||
66646364373034633334
|
|
||||||
|
|
|
@ -4,3 +4,11 @@ pwr_meter_amqp_user: "pwr-meter"
|
||||||
pwr_meter_amqp_pass: "{{ vault_pwr_meter_amqp_pass }}"
|
pwr_meter_amqp_pass: "{{ vault_pwr_meter_amqp_pass }}"
|
||||||
pwr_meter_api_token: "{{ vault_pwr_meter_api_token }}"
|
pwr_meter_api_token: "{{ vault_pwr_meter_api_token }}"
|
||||||
brotherql_printer_host: "brotherql-720nw.n39.eu"
|
brotherql_printer_host: "brotherql-720nw.n39.eu"
|
||||||
|
|
||||||
|
# URL for the grafana kiosk in our Bastelbereich
|
||||||
|
kiosk_grafana_url: "https://grafana.n39.eu/d/xpLj6UD4z/hobbes-space-monitor?orgId=1"
|
||||||
|
kiosk_grafana_user: "{{ vault_kiosk_grafana_user }}"
|
||||||
|
kiosk_grafana_pass: "{{ vault_kiosk_grafana_pass }}"
|
||||||
|
kiosk_mqtt_host: "mqtt.n39.eu"
|
||||||
|
kiosk_mqtt_topic: "Netz39/Things/HackingDashboard/Screenshot"
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,14 @@
|
||||||
$ANSIBLE_VAULT;1.1;AES256
|
$ANSIBLE_VAULT;1.1;AES256
|
||||||
61393134306361663861356132333135633566626136383536363763646134386338363362343830
|
64396666646432653766656333333139613631333035393137363036633330336134383932663631
|
||||||
6339626232333037613437386634396138323438643037390a366338353862653439323961626532
|
6533326532333366633136346232306637306266343264380a616164643037393036383834313238
|
||||||
37393438326261363563323233333364323536373735383834383134653935383436356137396166
|
32343437343466343262336137633436343935663465616364303961656565643134346563373461
|
||||||
3531326465363438310a663232306138333866373637336234326166666261333332386632316163
|
3337303534646563660a366562323065666630626331346266366139653533386238663361373930
|
||||||
61616339656436666233343339383835643934366661366333386363386639306631643366623333
|
30623733336361353838373730316537623066326166366634643466386332396333613531613564
|
||||||
30666430623435633961613932323239343239623532316662323937346634656136396539303036
|
38373363303466346639343563356339303037323261383034316439326237636565633462336462
|
||||||
63363365363861646333386364373263303037663266323832663761633633663136616338323362
|
35313561356465393337616162323866393365613537333461656234313464653165333963343331
|
||||||
36326561623063646666373034333335373135343736633066393937653234313932363138643065
|
32343634383335663764353831303864373637393833366333376635343665396366616363663033
|
||||||
38646231333564303861633231353535623436326135303463613738346231633962
|
37323031316535636131333738633237383665323638613233666432316261376239636234626638
|
||||||
|
33313230643563316662323937656338613362646466323335376363626163383233623831643565
|
||||||
|
31393438363334653863363536373632333930616636323237336236353863616638616165303931
|
||||||
|
63333639393665633537646665613933323632376162363139656632323166393264313333653163
|
||||||
|
64333935356138336562366634636364346461356539363162616438613232306533
|
||||||
|
|
|
@ -1,36 +0,0 @@
|
||||||
[Unit]
|
|
||||||
Description=Grafana Kiosk
|
|
||||||
Documentation=https://github.com/grafana/grafana-kiosk
|
|
||||||
Documentation=https://grafana.com/blog/2019/05/02/grafana-tutorial-how-to-create-kiosks-to-display-dashboards-on-a-tv
|
|
||||||
After=network.target
|
|
||||||
Wants=graphical.target
|
|
||||||
After=graphical.target
|
|
||||||
|
|
||||||
[Service]
|
|
||||||
User={{ kiosk_user }}
|
|
||||||
Environment="DISPLAY=:0"
|
|
||||||
Environment="XAUTHORITY=/home/{{ kiosk_user }}/.Xauthority"
|
|
||||||
|
|
||||||
# These should work according to the docs, but are nowhere in the code?
|
|
||||||
#Environment="KIOSK_MODE=full"
|
|
||||||
#Environment="KIOSK_AUTOFIT=false"
|
|
||||||
#Environment="KIOSK_LXDE_ENABLED=true"
|
|
||||||
#Environment="KIOSK_LXDE_HOME=/home/{{ kiosk_user }}"
|
|
||||||
#Environment="KIOSK_URL={{ kiosk_url }}"
|
|
||||||
#Environment="KIOSK_LOGIN_METHOD=local"
|
|
||||||
#Environment="KIOSK_LOGIN_USER={{ kiosk_grafana_user }}"
|
|
||||||
#Environment="KIOSK_LOGIN_PASSWORD={{ kiosk_grafana_pass }}"
|
|
||||||
|
|
||||||
# Disable screensaver etc.
|
|
||||||
ExecStartPre=xset s off
|
|
||||||
ExecStartPre=xset -dpms
|
|
||||||
ExecStartPre=xset s noblank
|
|
||||||
|
|
||||||
ExecStart=/home/{{ kiosk_user }}/bin/grafana-kiosk -kiosk-mode=full -autofit=false -lxde-home=/home/{{ kiosk_user }} -URL="{{ kiosk_url }}" -login-method=local -username={{ kiosk_grafana_user }} --password={{ kiosk_grafana_pass }}
|
|
||||||
|
|
||||||
Restart=on-failure
|
|
||||||
RestartSec=30s
|
|
||||||
|
|
||||||
[Install]
|
|
||||||
WantedBy=graphical.target
|
|
||||||
|
|
48
templates/hobbes/kiosk.sh.j2
Executable file
48
templates/hobbes/kiosk.sh.j2
Executable file
|
@ -0,0 +1,48 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Check if the script is run by root
|
||||||
|
if [ "$EUID" -ne 0 ]
|
||||||
|
then echo "Please run as root"
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
# MQTT broker details
|
||||||
|
BROKER="{{ kiosk_mqtt_host }}"
|
||||||
|
TOPIC="{{ kiosk_mqtt_topic }}"
|
||||||
|
|
||||||
|
# Variable to store the PID of the fbi process
|
||||||
|
fbi_pid=0
|
||||||
|
|
||||||
|
# Function to be executed on SIGTERM
|
||||||
|
on_sigterm() {
|
||||||
|
echo "SIGTERM received, exiting..."
|
||||||
|
# Kill the fbi process with the stored PID
|
||||||
|
if [ $fbi_pid -ne 0 ]; then
|
||||||
|
sudo kill $fbi_pid
|
||||||
|
fi
|
||||||
|
# Remove the temporary file
|
||||||
|
rm -f /tmp/grafana.png
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
|
||||||
|
# Trap SIGTERM and call on_sigterm() when it is received
|
||||||
|
trap 'on_sigterm' SIGTERM
|
||||||
|
|
||||||
|
while true
|
||||||
|
do
|
||||||
|
# Subscribe to the topic and save received data to a file
|
||||||
|
mosquitto_sub -h $BROKER -t $TOPIC -C 1 > /tmp/grafana.png
|
||||||
|
|
||||||
|
# Kill the previous fbi process
|
||||||
|
if [ $fbi_pid -ne 0 ]; then
|
||||||
|
sudo kill $fbi_pid
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Display the image using fbi
|
||||||
|
fbi -T 1 -noverbose -a /tmp/grafana.png &
|
||||||
|
fbi_pid=$!
|
||||||
|
|
||||||
|
# Wait to avoid a race condition between
|
||||||
|
# fbi starting and mosquitto truncating the file
|
||||||
|
sleep 1
|
||||||
|
done
|
Loading…
Reference in a new issue