yorknh
Posts: 3
Joined: Sun Sep 15, 2019 12:56 pm

Problems with date after read-only configuration

Sun Sep 15, 2019 1:15 pm

I have a pi-zero W that I've run the ADA fruit read-only file system script on.
https://raw.githubusercontent.com/adafr ... only-fs.sh

Everything works like I need it to except for the time. I've tried a number of solutions and the only one that kind of works is to run the following after a reboot:

sudo /etc/init.d/ntp stop
sudo ntpd -q-g
sudo /etc/init.d/ntp start


Since the whole point of the read-only fs, in my case, is to prevent power outages from corrupting the sd card on power loss and to reboot in a functioning state I need the time to be correct for the python scripts that start at bootup. Since running the commands listed work after the reboot I had hopes that putting them in /etc/cron.d would work, but it has no effect. The contents of my cron.d file are:

@reboot root /etc/init.d/ntp stop
@reboot root ntpd -q -g
@reboot root /etc/init.d/ntp start
@reboot root sleep 10
@reboot root python /home/pi/Adafruit_Python_MCP4725/LightControl.py
@reboot root sleep 10
@reboot root python /home/pi/Adafruit_DotStar_Pi-master/secondaryLights.py

The python scripts are running after reboot, but the time is wrong.

Any suggestions?

RattusRattus
Posts: 70
Joined: Sat Sep 29, 2018 11:27 am

Re: Problems with date after read-only configuration

Sun Sep 15, 2019 5:20 pm

Your NTP client is obviously trying to save skew data.

Try sim-linking its files into a RAMDisk (/dev/shm)

You will need to set the sim-links up before starting your NTP client

/Andy

User avatar
Paeryn
Posts: 2779
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: Problems with date after read-only configuration

Mon Sep 16, 2019 1:29 am

yorknh wrote:
Sun Sep 15, 2019 1:15 pm
Since running the commands listed work after the reboot I had hopes that putting them in /etc/cron.d would work, but it has no effect. The contents of my cron.d file are:

@reboot root /etc/init.d/ntp stop
@reboot root ntpd -q -g
@reboot root /etc/init.d/ntp start
@reboot root sleep 10
@reboot root python /home/pi/Adafruit_Python_MCP4725/LightControl.py
@reboot root sleep 10
@reboot root python /home/pi/Adafruit_DotStar_Pi-master/secondaryLights.py

The python scripts are running after reboot, but the time is wrong.

Any suggestions?
Couple of points, firstly /etc/cron.d is (should be) a directory not a file.
Secondly each line is an independent job and they will all be started at near enough the same time, cron doesn't wait for a job to finish before starting the next. I think it's likely they start in the order listed but I'm not sure if there is any guarantee of it, if you have a job that is slow to start followed by a job which finishes practically straight away then you can end up with the second job finishing before the first has got going.
Case in point, you two sleep 10 jobs, when they start they wait for 10 seconds then end, in which time the jobs after them will all have been already started. So a cron job which just sleeps is a waste of resources and has very little effect of on the rest of the crontab (definitely doesn't make the subsequent jobs wait 10 seconds).

If you want a sequence of commands to run at bootup you'd be better off putting the commands in a shell script and have just one crontab entry which runs that script.
She who travels light — forgot something.

yorknh
Posts: 3
Joined: Sun Sep 15, 2019 12:56 pm

Re: Problems with date after read-only configuration

Mon Sep 16, 2019 4:31 pm

RattusRattus wrote:
Sun Sep 15, 2019 5:20 pm
Your NTP client is obviously trying to save skew data.

Try sim-linking its files into a RAMDisk (/dev/shm)

You will need to set the sim-links up before starting your NTP client

/Andy
I kind of understand and kind of don't. Why would what you suggest make any difference? After the pi has booted I can run those commands and everything works, I just need to automate that.

yorknh
Posts: 3
Joined: Sun Sep 15, 2019 12:56 pm

Re: Problems with date after read-only configuration

Mon Sep 16, 2019 4:36 pm

Paeryn wrote:
Mon Sep 16, 2019 1:29 am
yorknh wrote:
Sun Sep 15, 2019 1:15 pm
Since running the commands listed work after the reboot I had hopes that putting them in /etc/cron.d would work, but it has no effect. The contents of my cron.d file are:

@reboot root /etc/init.d/ntp stop
@reboot root ntpd -q -g
@reboot root /etc/init.d/ntp start
@reboot root sleep 10
@reboot root python /home/pi/Adafruit_Python_MCP4725/LightControl.py
@reboot root sleep 10
@reboot root python /home/pi/Adafruit_DotStar_Pi-master/secondaryLights.py

The python scripts are running after reboot, but the time is wrong.

Any suggestions?
Couple of points, firstly /etc/cron.d is (should be) a directory not a file.
Secondly each line is an independent job and they will all be started at near enough the same time, cron doesn't wait for a job to finish before starting the next. I think it's likely they start in the order listed but I'm not sure if there is any guarantee of it, if you have a job that is slow to start followed by a job which finishes practically straight away then you can end up with the second job finishing before the first has got going.
Case in point, you two sleep 10 jobs, when they start they wait for 10 seconds then end, in which time the jobs after them will all have been already started. So a cron job which just sleeps is a waste of resources and has very little effect of on the rest of the crontab (definitely doesn't make the subsequent jobs wait 10 seconds).

If you want a sequence of commands to run at bootup you'd be better off putting the commands in a shell script and have just one crontab entry which runs that script.
Yeah sorry, those contents are in a file in cron.d. I obviously didn't know that about the sequencing, thanks for that explanation.

Return to “Troubleshooting”