OH2 daemon fails when /var/log is on tmpfs

In order not to destroy the SD card on my RPi running OH2, I mount /var/log on tmpfs instead of a persistent filesystem (with the obvious drawback of not being able to keep logs across reboots).

When changing this, I had the problem of the OH2 daemon not starting up, even if the init.d script says startup was successful. By strace:ing /usr/share/openhab2/runtime/karaf/bin/start, I tracked down the error to the /var/log/openhab2 directory not existing (I assume it was created during package install - I run from the CI APT channel, (deb https://openhab.ci.cloudbees.com/job/openHAB-Distribution/ws/distributions/openhab-offline/target/apt-repo/) ).

To work around the problem, I added the following lines to /etc/rc.local

mkdir -p /var/log/openhab2
chown openhab /var/log/openhab2

I don’t know if this is a desired/supported configuration and if this is to be treated as a bug. One way to help doing what I try to do would be to `mkdir -p´ the log path at daemon start instead of package install (assuming that is the case)

Hi @rickard,
I didn’t try for openhab, but for other applications which suffer from the same issue (e.g. mpd) I put this as ExecStartPre into the .service file.

for openhab2, the file is /usr/lib/systemd/system/openhab2.service

ExecStartPre=-/bin/mkdir -p /var/log/openhab2 

(but I didn’t try this myself for OH2)

Thanks, that’s more or less exactly what I do (except I don’t use systemd). However as it took me a good 30 minutes to track down, I thought that it would be of general interest to know the proper solution (if there is any), as I wouldn’t recommend anyone to run for a longer period of time with a R/W mounted SD card (untless they want to spend time reinstalling).