[SOLVED] Openhabian: move log file

Hi all,
I am using openhabian with pi3 booting from an USB key.
I noticed that the led indicating access to the USB key is almost always on, meaning that the system is continuously writing to the usb key.
So I tried to move the log files to RAM (tmpfs) modifying the file /etc/fstab as follows:

proc            /proc           proc    defaults          0       0
PARTUUID=4f82b826-01  /boot           vfat    defaults          0       2
PARTUUID=4f82b826-02  /               ext4    defaults,noatime  0       1
# a swapfile is not a swap partition, no line here
#   use  dphys-swapfile swap[on|off]  for that
#
# FOLLOWING TWO LINES ADDED BY ME:
tmpfs           /var/log                tmpfs   nodev,nosuid,size=50M,mode=1777 0 0
tmpfs           /tmp                    tmpfs   nodev,nosuid,size=30M,mode=1777 0 0
#
/usr/share/openhab2          /srv/openhab2-sys           none bind 0 0
/etc/openhab2                /srv/openhab2-conf          none bind 0 0
/var/lib/openhab2            /srv/openhab2-userdata      none bind 0 0
/var/log/openhab2            /srv/openhab2-logs          none bind 0 0
/usr/share/openhab2/addons   /srv/openhab2-addons        none bind 0 0

But unfortunately after this change openhab does not start. I can start the pi3 and login but the status of openhab2 service is as follows:

[22:07:13] openhabian@openHABianPi:~$ systemctl status openhab2
● openhab2.service - openHAB 2 - empowering the smart home
   Loaded: loaded (/usr/lib/systemd/system/openhab2.service; enabled)
   Active: deactivating (stop) (Result: exit-code) since Mon 2017-09-11 22:07:19 CEST; 84ms ago
     Docs: http://docs.openhab.org
           https://community.openhab.org
  Process: 5828 ExecStart=/usr/share/openhab2/start.sh server (code=exited, status=255)
 Main PID: 5828 (code=exited, status=255);         : 5981 (stop)
   CGroup: /system.slice/openhab2.service
           └─control
             ├─5981 /bin/sh /usr/share/openhab2/runtime/bin/stop
             ├─5997 /bin/sh /usr/share/openhab2/runtime/bin/stop
             ├─5998 /bin/sh /usr/share/openhab2/runtime/bin/stop
             ├─5999 /bin/sh /usr/share/openhab2/runtime/bin/stop
             ├─6008 /bin/sh /usr/share/openhab2/runtime/bin/stop
             ├─6012 /bin/sh /usr/share/openhab2/runtime/bin/stop
             ├─6015 /bin/sh /usr/share/openhab2/runtime/bin/stop
             └─6016 basename /usr/lib/jvm

any idea?

thanks

Does the openhab user have permission to write to the tmpfs? By default, I think it will mount with only root having write permission.

Hi, how can i give to user openhabian the permission to write to tmpfs?

Not the openhabian user, the openhab user. openhabian is the user you use to log into the Pi. openhab is the user that openHAB runs under.

You can set the owner, group, and mode of the tmpfs mount in fstab, though it looks like you are already using 777.

What do you get when you ls -ld /var/log?

I don’t know if you are allowed to mount some other file system into a tmpfs (you are mounting /srv/openhab2-logs to /var/log/openhab2 and above you set /var/log to be a tmpfs). You might try commenting out that /var/log/openhab2 line and see if that makes a difference.

User openhab, ok. I understand. thanks.

with the original fstab (without tmpfs):

drwxr-xr-x 9 root root 4096 Sep 11 22:13 /var/log

I don’t care about the original, I care about now after the tmpfs.

The problem is that when OH installs it creates an openhab2 folder in /var/log. But the install has permission to create that folder because the install is running as root. When you created the tmpfs version of /var/log there is now NOTHING in /var/log (that is what a tmpfs means). So openHAB is trying to create an openhab2 folder to write its log files to and doesn’t have permission because only root has permission to write anything to /var/log.

You need to give OH permission to write to that folder, or somehow make sure that an openhab2 folder exists in /var/log before OH tries to start that the openhab user has permission to write to.

Hi,
same after tmpfs:

[23:26:30] openhabian@openHABianPi:~$ ls -ld /var/log
drwxr-xr-x 2 root root 220 Sep 11 23:24 /var/log

Understood. But, how can I do that?

Solved:

tmpfs	 	/var/log 		tmpfs 	nodev,nosuid,size=50M,mode=1777 0 0
tmpfs	 	/var/log/openhab2	tmpfs 	nodev,nosuid,size=50M,mode=1777 0 0
tmpfs 		/tmp 			tmpfs 	nodev,nosuid,size=30M,mode=1777	0 0 

Seems to work