This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
opencpn.conf gets randomly emptied WALKED AROUND
#1
Rather than duplicate the info, I have posted a new thread on cruisers forum regarding an issue with opencpn.conf file getting corrupted.
So far, the issue doesn't seem to be addressed by the OpenCPN team ...

The walk around  I mention makes use of 2 bash scrips, one to create a backup of opencpn.conf, to be run when everything is going nicely, and the second one to restore the opencpn.conf when the catastrophe happened !
Not so elegant, but please consider these are my very first bash scripts !
here they are :

Backup :
# this script backs up the opencpn.conf file in the
# directory : ~/Sauvegardes
#OpenCPNshould be stooped 1st (CTRL+Q) and
# the content of opencpn.conf checked non empty)
cp /home/pi/.opencpn/opencpn.conf /home/pi/Sauvegardes/opencpn.conf

Restore :
# this script replaces the file /.opencpn/opencpn.conf,
# when corrpted with he file formerly saved in the directory : ~/Sauvegardes
# Save the corrupted file, target of the pocedure, for forensic analysis :
cp /home/pi/.opencpn/opencpn.conf /home/pi/.opencpn/garbage.ocpn.txt
# delete the corrupted file :
rm -f /home/pi/.opencpn/opencpn.conf
# replace the corrupted file by its backup :
cp /home/pi/Sauvegardes/opencpn.conf /home/pi/.opencpn/opencpn.conf

Edit : see improved script later in this thread

Being a complete newbie in the art of bash/Linux, I am sure these scripts can be condensed, and then improved, maybe merged in a single script which would run automaticaly at startup ?

I am opened to any suggestion to automate the process as much as possible !
Cordialement
Didier B
Pi4, SSD USB3, OP 3.0 Touch SK 3.2.1 OpenCPN  5.8.4 :  Thank you  Thank you  Thank you


Reply
#2
I think opencpn team is right. This is a difficult issue to solve. But, let's turn a problem into an advantage...

Following your idea I think we should have an option in OP interface to manage a kind of "templates" to save/import not only opencpn settings but all important programs.

This "save/import templates" button should open a new window to choose what settings you want to save/import:

All - OpenPlotter - kplex - Signal K and plugins - OpenCPN and plugins - SDR receiver.

Am I forgetting any app?
Reply
#3
(2019-05-29, 08:32 PM)Sailoog Wrote: I think opencpn team is right. This is a difficult issue to solve. But, let's turn a problem into an advantage...

Following your idea I think we should have an option in OP interface to manage a kind of "templates" to save/import not only opencpn settings but all important programs.

This "save/import templates" button should open a new window to choose what settings you want to save/import:

All - OpenPlotter - kplex - Signal K and plugins - OpenCPN and plugins - SDR receiver.

Am I forgetting any app?
Agreed with you Sailoog ! Big Grin 
(Some people in front of an issue beyond their competencies, forget to stay simply correct, isn't it ?)

Our both approaches have there pros and cons.
On one hand, I would like, for inexperienced users, to kiss it (Keep It Short & Simple !) : when the initial OCPN message shows up, stop it and  push the restore  button !
On the other hand, what you are  suggesting could be so usefull fore more experienced user, allowing to backup/restore complete OP configuration ...A new OP tab, maybe ?

What I dislike in my 1st approach (2 bash scripts) is that, if you push the 'backup' button after a corruption, you will kill the only restore possibility ...
Practically, if the conf file has a zero byte lenght, it would be wise to abort the backup script ! But that is far beyond my knowledge of bash scripts ...
Ideally the backup should be 100% automatic, at OP startup, testing opencpn.conf length, and if lenght > 0 back it up in the appropriate dir. If not abort the backup process !
Then only a 'restore' button will be needed. Cool
Cordialement
Didier B
Pi4, SSD USB3, OP 3.0 Touch SK 3.2.1 OpenCPN  5.8.4 :  Thank you  Thank you  Thank you


Reply
#4
Sailoog,
Maybe it would be interesting to display a warning message : "Always close OpenCPN (Ctrl + Q) before system shutdown !"
  • in the "first use" message,
  • and in the desktop wall  paper, as "first use" message is rarely remembered !
Cordialement
Didier B
Pi4, SSD USB3, OP 3.0 Touch SK 3.2.1 OpenCPN  5.8.4 :  Thank you  Thank you  Thank you


Reply
#5
We have already an "startup" script that runs the first OP window every start. We could do something there. We could check the conf file and if it is >0 we make a backup copy and if its content is 0 we load the latest backup file. Are you sure the file is 0 when this happens?
Reply
#6
I have reported to element14, see here,  of course for them it is an Application problem...
I suggested adding a time out before the power down in the Pi desktop software, and proposed to participate in the validation of the solution ...

if s'thing happens I will report here   Dodgy
Cordialement
Didier B
Pi4, SSD USB3, OP 3.0 Touch SK 3.2.1 OpenCPN  5.8.4 :  Thank you  Thank you  Thank you


Reply
#7
Higher in this script I wrote : Being a complete newbie in the art of bash/Linux, I am sure these scripts can be condensed, and then improved, maybe merged in a single script which would run automaticaly at startup ?

Well, with little inspiration and a lot of transpiration, its done now and here is the new KeepOCPN_conf_Tidy script :
Code:
# This script tests the opencpn.conf file length. If NOT 0 it will consider
# the file as valid and copy it as the new backup version.
# Else It will restore it with the former backup version.

if [ -s /home/pi/.opencpn/opencpn.conf ]; then cp /home/pi/.opencpn/opencpn.conf /home/pi/Sauvegardes/opencpn.conf;
else
    # Copy corrupted file for forensic investigations
    cp /home/pi/.opencpn/opencpn.conf /home/pi/.opencpn/garbage.ocpn.txt
    # delete corrupted file
    rm -f /home/pi/.opencpn/opencpn.conf
    # restore opencpn.conf using former backup :
    cp /home/pi/Sauvegardes/opencpn.conf /home/pi/.opencpn/opencpn.conf;

fi
What is not addressed is the case where the opencpn.conf file is corrupted AND its length is not ZERO ! But I had dozens of corruptions, and length was always zero !

Still to find how make OP run this script at startup  ! Any suggestion warmly welcomed
Cordialement
Didier B
Pi4, SSD USB3, OP 3.0 Touch SK 3.2.1 OpenCPN  5.8.4 :  Thank you  Thank you  Thank you


Reply
#8

.pdf   KeepOCPN_conf_Tidy.pdf (Size: 11.17 KB / Downloads: 207)
next and final step :
I have added, as ROOT, that line to /etc/RC.locale :
Code:
/home/pi/KeepOCPN_conf_Tidy
Which makes /etc/RC.locale now like this :
Code:
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
 printf "My IP address is %s\n" "$_IP"
fi
/home/pi/KeepOCPN_conf_Tidy
chmod 755 /media/pi
exit 0
note the 3rd line before the bottom of the file.

Let us control its perfect operational condition  :
  1. delete the copy of opencpn.conf from the directory /home/pi/Sauvegardes  (if any)
  2. reboot the RPi, quit OpenCPN if it started ;
  3. check that file opencpn.conf is back in the directory /home/pi/Sauvegardes, its magic ! Smile 
  4. Open in text editor the file /home/pi/.opencpn/opencpn.conf, Select all, delette, save, quit (yes, corrupt opencpn.conf, and check its lengh is Zero.
  5. reboot the RPi
  6. OpenCPN starts like charm ! nothing to reconfigure ...Quit OpenCPN, and check the length of opencpn.conf which should be some k (16k in my case).
Et voilà ... Angel . Should the config be lost, you will not notice it Big Grin 

The only drawback in case of corruption is you will have the configuration of your previous session ..., which is much better than no configuration at all !
I have stamped my desktop with this GOLD rule :
Always quit OpenCPN before stopping the system !



To summarize :
  • create in /home/pi a directory Sauvegardes ; it will accommodate the config file backups
  • copy the file KeepOCPN_conf-Tidy (*) in /home/pi, adjust its properties/access rights in fileman :  Right to execute : everybody
  • copy the file  etc/rc.locale  to etc/rc.locale.orig
  • Add the line in etc/rc.locale as ROOT as explained above
  • Apply above 6 steps control procedure, and you're done !
  • and remember : always quit OpenCPN before stopping the system !
(*) The site's rules prevents me to attach the script file ! Angry

EDIT : see next post
Cordialement
Didier B
Pi4, SSD USB3, OP 3.0 Touch SK 3.2.1 OpenCPN  5.8.4 :  Thank you  Thank you  Thank you


Reply
#9
I coud eventually attach a file ! to use it you should copy/paste its content in a text file, save it with the proper name, no extension.


.pdf   KeepOCPN_conf_Tidy.pdf (Size: 11.17 KB / Downloads: 253)
Cordialement
Didier B
Pi4, SSD USB3, OP 3.0 Touch SK 3.2.1 OpenCPN  5.8.4 :  Thank you  Thank you  Thank you


Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)