I have a Raspberry Pi running ArchLinux performing a number of crucial functions on my LAN.
It is setup as a dns server/relay and dhcp server, including pxe boot (dnsmasq)
It also controls the APC UPS supplying it and the router (apcupsd)
It acts as an ntp server/relay
Now, this is all working fine but, because of unreliable power (an average of two powercuts a day) and an ISP service which isn't totally reliable, I was getting fed up with incorrect times from the ntp service (Pi boots much more quickly than the router obtains an Internet connection).
So, I've added an RTC. I've been having 'fun' configuring the rtc this afternoon and have arrived at a systemd service, rtc.service:
$this->bbcode_second_pass_code('', '[Unit]
Description=RTC clock
Requires=systemd-modules-load.service
After=systemd-modules-load.service
[Service]
Type=oneshot
ExecStart=/usr/sbin/rtc.sh
[Install]
WantedBy=multi-user.target
')
and the bash script:
$this->bbcode_second_pass_code('', '#!/bin/bash
echo ds1307 0x68 >/sys/bus/i2c/devices/i2c-1/new_device
sleep 2
hwclock -s
')
My concern is with the arbitrary sleep between entering the new device, and being able to access the hwclock - in my experience , such 'fixes' can result in race hazards. Now, when invoking the script from console, a sleep 1 was sufficient, but when running under systemctl/systemd at boot time, I found it necessary to increase the sleep to 2 seconds.
Is the delay between writing the new device and being able to access the hardware clock expected. Am I simply covering the fact that I'm trying to access the hwclock before some required system service has fully started?
Advice would be much appreciated.