Config file updates aren't recognized by gitlab/rsync deployment

Hello,

acutally i am setting up a new openhab instance.
For automatic deployment of configuration files i want to use my gitlab instance.
Until now i triggered a ansible-playbook (also with rsync task) but now i want to handle the sync process completely in the gitlab-ci.yml

The sync of the files is working fine, but file updates aren’t recognized by openhab - i have to restart the openhab service to take effect of changes.

My “old” ansible playbook:

---
- name: Deploy openhab config
  hosts: openhab.home.domain.de
  gather_facts: false
  tasks:
  - name: Clone openhab config from gitlab repo
    ansible.builtin.git:
      repo: git@gitlab.home.domain.de:homelab/openhab.git # noqa: latest
      dest: /tmp/openhab-config
      clone: true
      update: true
    delegate_to: localhost
    run_once: true

  - name: Synchronize and delete files in dest on the remote host that are not found in src of localhost.
    ansible.posix.synchronize:
      src: /tmp/openhab-config/
      dest: /etc/openhab
#       rsync_opts:
#         - "--chmod=F755"
      delete: true
      recursive: true

  - name: Recursively remove directory
    ansible.builtin.file:
      path: /tmp/openhab-config
      state: absent
    delegate_to: localhost
    run_once: true

This is my “new” gitlab-ci.yml:

stages:
  - deploy

deploy:
  stage: deploy
  image: alpine:latest
  before_script:
    - apk update && apk add openssh-client rsync sudo
    - eval $(ssh-agent -s)
    - cat "$SSH_PRIVATE_KEY" | ssh-add -
    - mkdir -p ~/.ssh
    - echo "openhab.home.domain.de ssh-ed25519 xxxx" > ~/.ssh/known_hosts
  script:
    - rsync -atv --delete --progress --rsync-path="sudo rsync" --chmod=775 ./etc/ gitlab-cicd@openhab.home.domain.de:/etc/openhab/
    - rsync -atv --delete --progress --rsync-path="sudo rsync" --chmod=775 ./addons/ gitlab-cicd@openhab.home.domain.de:/usr/share/openhab/addons/

When i update the files by sftp or ssh/nano the changes are recognized immediately.

Any ideas or hints for that?

PS: Running actual OH4M3

Thanks in advance,
Alex

Can you double check file ownership? Its first thing which comes to my mind when some files are not picked up.

File ownership is root/root.
Same at rsync & sftp transfer.

Unless you installed openhab in its own way from root account this is not going to fly. As far I remember openHAB rpm/deb/apt package uses its own user - openhab. Make sure these files are readable by user account used by openhab process.

this was my first thought, too.
its correct, that the files/folders after installation had “openhab” as owner and group.
but the files are readable for openhab, because after a restart of the service they are recognized.
Even when i upload a file as root user the update works.
So i think there has to be another reason why the config isnt updated immediately…

If permissions are fine maybe file modified/changed time is not amended? I think that file monitoring works based on modified time, so if your script keeps all attributes intact, but changes contents, monitors will be blind for updated content until restart.

The timestamp of the files change, too. Its really strange.

In the logs of Openhab i get sometimes this error - but i am not quite sure if its related to the file updates?

java.lang.NullPointerException: null
        at java.util.concurrent.ConcurrentHashMap.putVal(ConcurrentHashMap.java:1011) ~[?:?]
        at java.util.concurrent.ConcurrentHashMap.put(ConcurrentHashMap.java:1006) ~[?:?]
        at org.openhab.core.internal.service.WatchServiceImpl.notifyListeners(WatchServiceImpl.java:256) ~[?:?]
        at org.openhab.core.internal.service.WatchServiceImpl.lambda$4(WatchServiceImpl.java:231) ~[?:?]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539) ~[?:?]
        at java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[?:?]
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304) ~[?:?]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) ~[?:?]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) ~[?:?]
        at java.lang.Thread.run(Thread.java:833) ~[?:?]

It is for sure related, WatchServiceImpl is a filesystem watch. Which OH version are you using?

Openhab4 M3 (4.4.3)

Guilty code branch is here:

I am not quite sure why it fails. It is related to this PR: Prevent unnecessary MODIFY events in WatchServiceImpl by J-N-K · Pull Request #3524 · openhab/openhab-core · GitHub which come into 4…0 M3

IMO this is a bug in the watcher library. Neither path() nor hash() should return null. I’ll implement a check for that.

I guess the reason is that the watch service can’t read the file content, but not sure about that.

Thanks for your replies!

I am not sure what that means for me.
Because its working on the “manual” way, i think there has to be a difference on the “automated” way, but i can’t figure out what the difference is…

Can someone explain, whats the difference on both ways?

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.