Cool cool cool. In case its useful for anyone else here’s my /usr/local/bin/openmount:
case $1 in start) /bin/mount -t tmpfs tmpfs /var/lib/openhab/persistence -o defaults,size=70M /bin/chmod 777 /var/lib/openhab/persistence /bin/cp -Rpu /home/openhab/openhab_save/persistence_save/* /var/lib/openhab/persistence /bin/mount -t tmpfs tmpfs /var/lib/openhab/workspace -o defaults,size=70M /bin/chmod 777 /var/lib/openhab/workspace /bin/cp -Rpu /home/openhab/openhab_save/workspace_save/* /var/lib/openhab/workspace /bin/mount -t tmpfs tmpfs /usr/share/openhab/webapps -o defaults,size=70M /bin/chmod 777 /usr/share/openhab/webapps /bin/cp -Rpu /home/openhab/openhab_save/webapps_save/* /usr/share/openhab/webapps ;; stop) /bin/rm -fr /home/openhab/openhab_save/persistence_save /bin/cp -Rp /var/lib/openhab/persistence /home/openhab/openhab_save/persistence_save /bin/rm -fr /home/openhab/openhab_save/workspace_save /bin/cp -Rp /var/lib/openhab/workspace /home/openhab/openhab_save/workspace_save /bin/rm -fr /home/openhab/openhab_save/webapps_save /bin/cp -Rp /usr/share/openhab/webapps /home/openhab/openhab_save/webapps_save ;; esac exit 0
I pretty much used @Spaceman_Spiff’s varlog and both service files and they work great. I used ‘crontab -e’ while logged into the root user (sudo su) and added:
0 * * * * /usr/local/bin/varlog stop
1 * * * * /usr/local/bin/openhabmount stop
and the crontab is firing at the correct times i.e. /var/log/syslog and everything seems to be saving correctly. Thanks again!
Now on to moving everything to a USB stick!
Sorry to bump an old thread, but does anyone have suggestions for which folders to put into tmpfs in OH2?
edit: after looking at the openhabmount it seems I could reduce these 3 folders down to using just /var/lib/openhab2 inclusive. Any foreseeable issues with this? And, if anyone is kind enough to respond (@Spaceman_Spiff are you still out there:)?) Do i need to still mount the folders in fstab? or will the scripts take care of them. (I noticed i had commented out the tmpfs mount commands in my fstab, but I don’t remember if I did that when I upgraded to OH2 or before) All help is greatly appreciated.
I think you only need to put OH2/userdata into tmpfs.
Make sure to persist at least the folders “etc”, “openhabcloud”, “zwave” and the uuid -file (if they exist)
No - the scripts have a “mount” command in them.
to clarify the OH2/userdata folder on an apt installation would be the /var/lib/openhab2/ folder, right? the one with cache, config, etc, jsondb, kar, openhabcloud, persistence, tmp and uuid …?
And I’m sorry for what is almost certainly a dumb question, but what does the verb ‘persist’ mean in this context? (e.g. Make sure you persist at least these folders)
Gotcha, thanks for the clarification.
That means backup and restore. Otherwise it will be gone after reboot.
If you use the script that’s what it does.
Sorry to bump the thread again, but I’ve been trying to get this to work since I upgraded to openhab2 to no avail. the varlog script and accompanying service work fine but openhab doesn’t even launch if I enable the tmpfs mount for any specific openhab folder. And for the record, I’m ONLY attempting to mount /var/lib/openhab2. One thing to note is that I get a permissions error if I run /usr/local/bin/openhabmount2 without sudo.
Have you checked permissions read, write, execute to make sure openhab is allowed to execute your script? ls -al /var/lib/openhab2 will give you owner, user, and whats allowed for the openhab2 file.
I think this is the file in question /usr/local/bin/openhabmount2
Make sure its accessible by openhab
So when you say the script, do you mean the actual openhab2mount script or the systemd service. The script, as is the old one, is owned by root:root but with 777 permissions. I’m near positive the /var/lib folder is wholly owned by openhab:openhab but I’ll check again tonight.
Is there a script that fixes/changes permission on openhab start like openhab1?
Script may have been the wrong word, I don’t know what openhabmiunt2 is. In /usr/local/bin there is the openhabian-config file with a softlink to /opt/openhabian/openhabian-setup.sh
Also in /usr/local/bin are chardetect, FireMotD, and tzupdate, all with owner as root and user as staff. What output do you have with: ls -al /usr/local/bin is the owner:user same as root:staff?
There are tools to check and fix permissions.
Hmmm i don’t have any of those things in /usr/local/bin/ I have an apt-get installation is that the issue? All that’s in /usr/local/bin a bunch of scripts I created: the varlog script @Spaceman_Spiff gave me earlier, openhabmount and openhab2mount (2 variations on the varlog script for copying tmpfs folders) and some unrelated scripts I wrote to test my internet speed.
I ran the sudo openhabian-config command just to see and the RPi responds that it is an unknown command.
So, I’m actually gonna make a new post but I’m concerned my issues run much deeper. I’m not sure when it started but at some point after updating to OH2 my system started crashing sporadically and now its very frequently (it doesn’t make it more than a day or 2 without me seeing the openhab is offline error). Each time is spits out a hd_err_pid file with a new number. Here’s the latest https://pastebin.com/vyrKdxuF
I thought I licked it by switching to the Zulu install of java, but it appears I was mistaken. I think it would be best to sort this out first.
edit: just realized that the original point of THIS post was to fix frequent crashes and tmpfs was one of the solution offerings, so I will spare the board another post for the time being. If anyone see anything in that error file that will shed some light i’d be most grateful…
I guess if you want to make your pi run for a while then you will eventually end up at this great topic here.
I am pretty new to all this so please forgive me if I am slow in taking all this in.
Yesterday my RPi 3 B+ arrived with a 64GB SanDisk Extreme Ultra SD card (to have space for wear-levelling) and now I have arrived here to reduce the IO to a minimum.
For the moment I am running OpenHab2 and mosquitto
What is the best tool to monitor my SD I/O’s?
so first I mounted those two:
sudo mount -t tmpfs -o size=100M,mode=0755 tmpfs ` /var/lib/openhab2/persistence
sudo mount -t tmpfs -o size=100M,mode=0755 tmpfs /var/log/openhab2
then edited fstab:
tmpfs size=100M,mode=0755 0 0 tmpfs /var/log/openhab2 tmpfs size=100M,mode=0755 0 0
etc/systemd/system/varlog.service is in my case syslog.service
/usr/local/bin/varlog I have /usr/local/bin/openhabian-config
I don’t have /etc/systemd/system/openhabmount.service
and also /usr/local/bin/openhab I don’t have. there is only /usr/local/bin/openhabian-config
can you guys please check if my config was ok like that and how I can set up that the files are being saved every couple of hours as well as copied back and forth during a shut-down or restart?
sorry for these stupid questions but this is all pretty new to me.
And sure enough it won’t reboot anymore because it can’t find the openhab2 configuration files.
So I must be doing something right, thanks to you guys.
How can I recover those files and which ones?
Check this post on SD corruption. Setup Amanda for backup (option 51 in openhabian-config).
thanks mstormi, I have been there before and I will go with amanda and an USB HDD.
I’ve got a 5V 6A power supply so I can attach plenty.
Looking for a usuable powerbank at the moment. I think I saw somewhere what you guys were using, I need to find that post again.
I just set up this and I think it is working because the machine doesn’t reboot anymore. Seems that the openhab config files have gone missing. Success!
so now I have to get the lost config files back and then set up the persistance write and restore
What files you have will depend on whether you installed via Apt or manually. the openhabmount.service is a user created script that mounts the specified directories to tmpfs. An example of this script is further up in the post. Full disclosure though, I haven’t yet gotten this to work on Openhab 3 and haven’t had time to start it over from scratch.
thanks for all your great help gentlemen!
I haven’t been working on it for the last two or three days.
And I can’t at the moment without re-installing it.
Files are gone…
would someone be able to provide an original file of:
I have accidentially eliminated them.
happy new year to everyone here!
thanks to you guys I have made a huge progress in my raspberry pi3b+ openhab project.
And I also have received my external HDD USB case and have a magnetic disc HDD connected to my pi.
This or an USB stick should backup my data.
I know I should be able to boot from the HDD but the idea is still to run my openhab-server from the SD card because it is blazingly fast.
It should also run my mosquitto server, no writes other than in tmpfs and copying the files to the HDD 4 times a day.
I understand the scripts above better now but I am still struggling on getting this to work on OH2.
Have you guys been following up on this and is there a OH2 tutorial?
case $1 in
/bin/mount -t tmpfs tmpfs /opt/openhab2/userdata -o defaults,size=70M
/bin/chmod 777 /opt/openhab2/userdata
/bin/cp -Rpu /home/openhab_save/userdata_save/* /opt/openhab2/userdata
/bin/rm -fr /home/openhab_save/userdata_save
/bin/cp -Rp /opt/openhab2/userdata /home/openhab_save/userdata_save
gives me /bin/bash^M: bad interpreter: No such file or directory
why is that, the folders exist?
can someone help please?
That ‘^M’ means that the script file is in the DOS format with carriage returns instead of just line feeds. You need to save the script file in the Unix format without carriage returns, the ^M. Most editors can save in either format.