diff --git a/roles/i2c-clock/files/etc/modules-load.d/rtc-ds1307.conf b/roles/i2c-clock/files/etc/modules-load.d/rtc-ds1307.conf index 2cf3225..7b4fd30 100644 --- a/roles/i2c-clock/files/etc/modules-load.d/rtc-ds1307.conf +++ b/roles/i2c-clock/files/etc/modules-load.d/rtc-ds1307.conf @@ -1 +1 @@ -rtc-ds1307 \ No newline at end of file +rtc-ds1307 diff --git a/roles/i2c-clock/files/etc/systemd/system/rtc-i2c.service b/roles/i2c-clock/files/etc/systemd/system/rtc-i2c.service index 8573790..d678375 100644 --- a/roles/i2c-clock/files/etc/systemd/system/rtc-i2c.service +++ b/roles/i2c-clock/files/etc/systemd/system/rtc-i2c.service @@ -4,7 +4,8 @@ ConditionVirtualization=!container DefaultDependencies=no Wants=dev-rtc_i2c.device After=dev-rtc_i2c.device -Before=systemd-timesyncd.service ntpd.service chrony.service +Before=sysinit.target +Conflicts=shutdown.target [Service] Type=oneshot @@ -12,10 +13,10 @@ CapabilityBoundingSet=CAP_SYS_TIME PrivateTmp=yes ProtectSystem=full ProtectHome=yes -DeviceAllow=/dev/rtc_i2c rw +DeviceAllow=/dev/rtc rw DevicePolicy=closed -ExecStartPre=/usr/bin/echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device -ExecStart=/sbin/hwclock -s +ExecStart=/bin/sh -c "/usr/bin/echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device" +ExecStartPost=/usr/bin/logger --tag rtc-i2c 'System clock set from i2c hardware clock' [Install] -WantedBy=time-sync.target \ No newline at end of file +WantedBy=sysinit.target diff --git a/roles/i2c-clock/tasks/install.yml b/roles/i2c-clock/tasks/install.yml index c051ea5..940a674 100644 --- a/roles/i2c-clock/tasks/install.yml +++ b/roles/i2c-clock/tasks/install.yml @@ -7,6 +7,12 @@ update_cache: yes pkg: - i2c-tools + - libraspberrypi-bin + + - name: enable i2c-rtc dtoverlay + shell: + cmd: | + dtoverlay i2c-rtc - name: enable automatic module load copy: @@ -18,8 +24,13 @@ src: etc/systemd/system/rtc-i2c.service dest: /etc/systemd/system/rtc-i2c.service + - name: disable systemd service + systemd: + daemon_reload: yes + name: rtc-i2c.service + enabled: no + - name: enable systemd service systemd: name: rtc-i2c.service enabled: yes - state: started diff --git a/roles/i2c-clock/tasks/set-time.yml b/roles/i2c-clock/tasks/set-time.yml index 2410668..26cc764 100644 --- a/roles/i2c-clock/tasks/set-time.yml +++ b/roles/i2c-clock/tasks/set-time.yml @@ -1,5 +1,11 @@ --- +- name: Check if rtc is loaded + stat: + path: /dev/rtc + register: rtc_file + - become: yes + when: rtc_file.stat.exists == False block: - name: load hwclock shell: