openHAB HABpanel configuration gets destroyed, HABpanel stays blank

Posted by ads' corner on Wednesday, 2020-04-08
Posted in [Openhab][Software]

openHAB is a stream of pure joy when it comes to debugging. Especially when all I want is a small display in the kitchen, working autonomous and without the need to restart it all the time or login to fix issues.

The latest installment of that endeavor was a black screen in the browser, with no way to even get to the usual HABpanel controls. After some debugging, it turns out that the file habpanel.config (/var/lib/openhab2/config/org/openhab/habpanel.config) on the openHAB server was destroyed, or more accurate: shortened to 4829 bytes. Lucky me I have this file in my Ansible playbooks, and whenever there is a change, a copy of this file is fetched to my Ansible host. From there it goes into my backups, and I can restore a couple dozen versions back, if needed. So not all is bad, but still something is not working as expected. First I installed a copy of this file from my backups - but turns out shortly later the file is shortened again. Later I figured that the file is always shortened when the openHAB service restarts. This particular instance was still running openHAB 2.4, and I used this opportunity to upgrade to 2.5, test my Playbooks (and exclude the one config file from everything) and see if the problem persists. It does. Except that after upgrading to 2.5 the file is no longer shortened to 4829 bytes, but to 4875 bytes.

Every time that happens, the file ends somewhere in the middle of the HABpanel panel configuration - and naturally the HABpanel service can no longer read that file and shows a blank screen. I would wish that it rather shows an error message, or does something useful here, but oh well.

For a while (and mostly because I was busy with other tasks) I helped myself by changing the owner of habpanel.config and the directory this files lives in to root:root. This threw a couple other errors into the logfile, but helped somewhat because the config file got no longer destroyed when the service restarted.

After more debugging and testing I posted on the openHAB Community forum, and one user pointed me into the right direction. The Apache Felix stuff seems to be at fault, and I had to remove this from the file. I also had to wipe another config file (/var/lib/openhab2/etc/org.openhab.habpanel.cfg), which turned out to be more complicated: the file is recreated at some point. I poured everything into my Ansible Playbook, and this specific part is now:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
- block:
  # remove Felix from add-ons
  - name: Remove add-ons
    lineinfile:
      dest: /var/lib/openhab2/config/org/openhab/addons.config
      regexp: "{{ item.regexp }}"
      line: "{{ item.line }}"
      state: "{{ item.state }}"
      create: no
    loop:
      - { regexp: '^misc=', line: 'misc=""', state: present }
    notify:
      - restart openhab2

  # remove buggy "felix" code
  - name: Remove buggy "felix" code
    lineinfile:
      dest: /var/lib/openhab2/config/org/openhab/habpanel.config
      regexp: "{{ item.regexp }}"
      line: "{{ item.line }}"
      state: "{{ item.state }}"
      insertafter: "{{ item.insertafter }}"
      create: no
    loop:
      - { regexp: '^felix.fileinstall.filename=', line: '', state: absent, insertafter: EOF }
    notify:
      - restart openhab2

  - name: Remove habpanel.cfg
    file:
      path: /var/lib/openhab2/etc/org.openhab.habpanel.cfg
      state: absent

First “Felix” is removed from packages, then the felix line is removed from habpanel.config. And finally the habpanel.cfg is removed. Restart the openHAB service. After that I had to reinstall the panel configuration once from my backups, but ever since then this is stable. No more configuration damages.


Categories: [Openhab] [Software]