diff --git a/files/hobbes/grafana-kiosk.service b/files/hobbes/grafana-kiosk.service new file mode 100644 index 0000000..09a32ce --- /dev/null +++ b/files/hobbes/grafana-kiosk.service @@ -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 diff --git a/host-hobbes.yml b/host-hobbes.yml index 7db081c..af2ec88 100644 --- a/host-hobbes.yml +++ b/host-hobbes.yml @@ -8,7 +8,6 @@ roles: - tasks: - name: Install packages needed for the system # This is a list of all packages, @@ -16,15 +15,9 @@ ansible.builtin.apt: state: present name: - # This is needed for the user-executed tasks - - acl - # Regular packages - - lightdm - - accountsservice - - unclutter - - lxde - - chromium-browser - - rng-tools + - mosquitto-clients + - fbi + - name: Remove the screensavers ansible.builtin.apt: @@ -53,50 +46,23 @@ ### Kiosk setup - # - # https://github.com/grafana/grafana-kiosk - - name: Ensure kiosk user is there ansible.builtin.user: name: "{{ kiosk_user }}" groups: audio,plugdev,input,netdev append: yes - - - name: Create bin directory - file: - path: "/home/{{ kiosk_user }}/bin" - owner: "{{ kiosk_user }}" + - name: Install Kiosk script + ansible.builtin.template: + src: templates/hobbes/kiosk.sh.j2 + dest: /usr/local/bin/kiosk.sh + owner: root + group: root 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 - ansible.builtin.template: - src: templates/hobbes/grafana-kiosk.service.j2 + ansible.builtin.copy: + src: files/hobbes/grafana-kiosk.service dest: /etc/systemd/system/grafana-kiosk.service owner: root group: root @@ -108,12 +74,4 @@ enabled: true 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: diff --git a/host-radon.yml b/host-radon.yml index 0a585e9..1648adf 100644 --- a/host-radon.yml +++ b/host-radon.yml @@ -209,6 +209,22 @@ tags: - 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: - name: restart mosquitto docker_container: diff --git a/host_vars/hobbes.n39.eu/vars.yml b/host_vars/hobbes.n39.eu/vars.yml index 2b64fb3..b0b622b 100644 --- a/host_vars/hobbes.n39.eu/vars.yml +++ b/host_vars/hobbes.n39.eu/vars.yml @@ -2,8 +2,6 @@ server_admin: "admin+hobbes@netz39.de" mac: "b8:27:eb:f9:43:43" kiosk_user: pi -kiosk_software_version: v1.0.6 -kiosk_software_arch: "armv7" -kiosk_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" +docker_data_root: "/srv/docker" diff --git a/host_vars/hobbes.n39.eu/vault b/host_vars/hobbes.n39.eu/vault index 5f4b386..6c9a336 100644 --- a/host_vars/hobbes.n39.eu/vault +++ b/host_vars/hobbes.n39.eu/vault @@ -1,9 +1,6 @@ $ANSIBLE_VAULT;1.1;AES256 -32313738636231313036633334333934643839636563646334336533316436653263623461643438 -6362343635626266313466643465343962663931623662320a316635613231313930343937363064 -33326164333137633039376363643539346463303934333430626431336637326638363233333234 -3132333533376134380a383837616331303536623665383735663531343538366332313236386137 -62306436663934383363616332316262313762633261396535663533636665633532316366386430 -65343830376634633365343337313433643465323662313563366463393664653766623338623635 -30653263303761316238396634346337636461643231303561353133643162633934323161663539 -66646364373034633334 +32343732363234396136616164383833316634373061376235656566303761646461626138363432 +3264633461383739393138396233303839363132343866370a306433306364666438623434383036 +63366634313937623736393636393030333961323335323762663538373631353331353162613362 +3661653539306365350a333263383537643738373939376563356566313732613766303931633630 +6462 diff --git a/host_vars/radon.n39.eu/vars.yml b/host_vars/radon.n39.eu/vars.yml index 36f7d92..e224d5c 100644 --- a/host_vars/radon.n39.eu/vars.yml +++ b/host_vars/radon.n39.eu/vars.yml @@ -4,3 +4,11 @@ pwr_meter_amqp_user: "pwr-meter" pwr_meter_amqp_pass: "{{ vault_pwr_meter_amqp_pass }}" pwr_meter_api_token: "{{ vault_pwr_meter_api_token }}" 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" + diff --git a/host_vars/radon.n39.eu/vault b/host_vars/radon.n39.eu/vault index 51ed17c..14c9a89 100644 --- a/host_vars/radon.n39.eu/vault +++ b/host_vars/radon.n39.eu/vault @@ -1,10 +1,14 @@ $ANSIBLE_VAULT;1.1;AES256 -61393134306361663861356132333135633566626136383536363763646134386338363362343830 -6339626232333037613437386634396138323438643037390a366338353862653439323961626532 -37393438326261363563323233333364323536373735383834383134653935383436356137396166 -3531326465363438310a663232306138333866373637336234326166666261333332386632316163 -61616339656436666233343339383835643934366661366333386363386639306631643366623333 -30666430623435633961613932323239343239623532316662323937346634656136396539303036 -63363365363861646333386364373263303037663266323832663761633633663136616338323362 -36326561623063646666373034333335373135343736633066393937653234313932363138643065 -38646231333564303861633231353535623436326135303463613738346231633962 +64396666646432653766656333333139613631333035393137363036633330336134383932663631 +6533326532333366633136346232306637306266343264380a616164643037393036383834313238 +32343437343466343262336137633436343935663465616364303961656565643134346563373461 +3337303534646563660a366562323065666630626331346266366139653533386238663361373930 +30623733336361353838373730316537623066326166366634643466386332396333613531613564 +38373363303466346639343563356339303037323261383034316439326237636565633462336462 +35313561356465393337616162323866393365613537333461656234313464653165333963343331 +32343634383335663764353831303864373637393833366333376635343665396366616363663033 +37323031316535636131333738633237383665323638613233666432316261376239636234626638 +33313230643563316662323937656338613362646466323335376363626163383233623831643565 +31393438363334653863363536373632333930616636323237336236353863616638616165303931 +63333639393665633537646665613933323632376162363139656632323166393264313333653163 +64333935356138336562366634636364346461356539363162616438613232306533 diff --git a/templates/hobbes/grafana-kiosk.service.j2 b/templates/hobbes/grafana-kiosk.service.j2 deleted file mode 100644 index 0712910..0000000 --- a/templates/hobbes/grafana-kiosk.service.j2 +++ /dev/null @@ -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 - diff --git a/templates/hobbes/kiosk.sh.j2 b/templates/hobbes/kiosk.sh.j2 new file mode 100755 index 0000000..e9c7944 --- /dev/null +++ b/templates/hobbes/kiosk.sh.j2 @@ -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