Logging on PI3 tmpfs

I’ve installed an openhab2 to pi3 (Raspbian)

As openhab writes a lot of info into the logs i decided to move logs into ram. So following the guide simply added to fstab

tmpfs /var/log tmpfs defaults,noatime,nosuid,mode=0775,size=100m 0 0

Openhab2 started complaining on the absence of openhab directory. So thinking that openhab user doesn’t have enough permissions i changed the fstab entry to
tmpfs /var/log tmpfs defaults,noatime,nosuid,mode=0777,size=100m 0 0

But with no luck. So what is the correct way than?

I guess openHAB expects the /var/log/openhab directory to already exist. I’m not sure whether the logging framework in OH2 is able to create the full path to the log file it wants to write to.

Did you try to create /var/log/openhab after mounting the file system and then to start OH2?

Will try that. But i thought that tmpfs is a ram only system so everything gets flushed after reboot?

What about logging to syslog? As OH2 doesn’t use the logback anymore is there a way to forward openhab.log to the syslog?

I’m using a combination of ramfs and aufs on my installation. I moved /var/log to /var/LOG and /var/lib to /var/LIB respectively (/var/lib is where the rrds are stored on the system installed from debian packages).

This is what I added to my /etc/fstab:

ramfs /media/ramdisk1 ramfs defaults,nofail 0 0
none /var/lib aufs br=/media/ramdisk1=rw:/var/LIB=ro,nofail 0 0

ramfs /media/ramdisk2 ramfs defaults,nofail 0 0
none /var/log aufs br=/media/ramdisk2=rw:/var/LOG=ro,nofail 0 0

Using aufs gives me the benefit that all files and directories are already present on the overlayed filesystem. To save the data from the ram disk from time to time I use this crontab entry:

0 */4 * * * /usr/bin/rsync -a --delete /var/log/ /var/LOG/ && /usr/bin/rsync -a --delete /var/lib/ /var/LIB/

This setup works for me for quite some time now.

I had to enable aufs in the kernel source and recompile the kernel modules for this to work.

Did you create the dirs yourself?
So is it as simple as…
cp -r /var/log /var/logs
cp -r /var/libs /var/libss

Than add the fstab entries. Reboot.
Than copy back just to make sure the dirs are created
cp -r /var/logs /var/log
cp -r /var/libss /var/libs

And that’s it? After reboot it will stay that way?
This seems the best way to go from what i’ve read so far.

I just did it like this:

cd /var
mv log LOG
mv lib LIB
mkdir log
mkdir lib

Then add fstab entries and

mount /var/lib
mount /var/log

When you have mounted everything and check the mount output afterwards it should look like this;

ramfs on /media/ramdisk1 type ramfs (rw,_netdev)
ramfs on /media/ramdisk2 type ramfs (rw,_netdev)
none on /var/lib type aufs (rw,relatime,si=92f9bed1)
none on /var/log type aufs (rw,relatime,si=93845ed1)

Initially /media/ramdisk1 should be (nearly) empty when you list the directory.
It fills over time when you write to files as each file that is written to will be written to /media/ramdiskX and the respective subdirectory. To persist the files in the ramdisk I run an rsync every 4 hrs. That way I loose at most 4hrs worth of logs and rrd data.

Hope that helps getting you started.

Almost did. Except that raspbian jessie seems doesn’t have support for aufs
mount: unknown filesystem type 'aufs'
Installing aufs-tools didn’t help

As I wrote in my first post, I had to enable aufs in the kernel.

In order to do this you have to install kernel sources. My odroid currently runs on kernel 3.10.92.
When I start make menuconfig in the top level source directory, aufs is located in

File Systems -> Misc Filesystems -> Aufs

I configured Aufs to be compiled as a module, enabled the “Ramfs as an aufs branch” option and disabled the “detect direct branch access”.

After exiting the kernel konfig compile and install the modules:

make moidules
make modules_install
depmod -a
modprobe aufs

Well aufs way didn’t work for me - so the simple solution i found on the net was editing the rc.local adding the following

#list the dirs to be created
for dir in openhab2 mpd;
  if [ ! -e /var/log/$dir ] ; then
mkdir /var/log/$dir

# Set owners for the newly created log directories
chown openhab:openhab /var/log/openhab2
chown mpd:mpd /var/log/mpd

Have someone a solution for the rrdj files ?
With oh1 I have a tmpfs for that .