Systemd-Service zur Verwendung einer DS3231-RTC auf dem Raspberry Pi
Der folgende systemd-Service wird automatisch. Siehe diese Anleitung für weitere Informationen zum Setup und stellen Sie sicher, dass sudo i2cdetect -y 1 die RTC mit der Adresse 0x68 erkennt.
Dies ist ein automatisches Service-Installations- und Aktivierungsskript basierend auf Ein einfaches systemd-Service-Autoinstallations-Skript. Dieses Skript wird den Service beim Booten automatisch aktivieren:
install_configure_rtc.sh
#!/bin/bash
# This script installs and enables/starts a systemd service
# It also installs the service file
export NAME=ConfigureRTC
cat >/etc/systemd/system/${NAME}.service <<EOF
[Unit]
Description=${NAME}
[Service]
ExecStart=/bin/bash -c 'echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device && hwclock -s'
Restart=always
[Install]
WantedBy=multi-user.target
EOF
# Enable and start service
systemctl enable --now ${NAME}.serviceinstall_configure_rtc.sh
#!/bin/bash
# This script installs and enables/starts a systemd service
# It also installs the service file
export NAME=ConfigureRTC
cat >/etc/systemd/system/${NAME}.service <<EOF
[Unit]
Description=${NAME}
[Service]
ExecStart=/bin/bash -c 'echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device && hwclock -s'
Restart=always
[Install]
WantedBy=multi-user.target
EOF
# Enable and start service
systemctl enable --now ${NAME}.serviceDies ist nur der systemd-Service:
configure_rtc.service
[Unit]
Description=ConfigureRTC
[Service]
ExecStart=/bin/bash -c 'echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device && hwclock -s'
Restart=always
[Install]
WantedBy=multi-user.targetconfigure_rtc.service
[Unit]
Description=ConfigureRTC
[Service]
ExecStart=/bin/bash -c 'echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device && hwclock -s'
Restart=always
[Install]
WantedBy=multi-user.targetCheck out similar posts by category:
Linux, Raspberry Pi
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow