summaryrefslogtreecommitdiff
path: root/meta-openbmc-mods/meta-common/recipes-core/nv-sync
diff options
context:
space:
mode:
Diffstat (limited to 'meta-openbmc-mods/meta-common/recipes-core/nv-sync')
-rw-r--r--meta-openbmc-mods/meta-common/recipes-core/nv-sync/nv-sync/nv-sync-tmp.conf2
-rw-r--r--meta-openbmc-mods/meta-common/recipes-core/nv-sync/nv-sync/nv-sync.service11
-rw-r--r--meta-openbmc-mods/meta-common/recipes-core/nv-sync/nv-sync/nv-syncd38
-rw-r--r--meta-openbmc-mods/meta-common/recipes-core/nv-sync/nv-sync_git.bb29
4 files changed, 80 insertions, 0 deletions
diff --git a/meta-openbmc-mods/meta-common/recipes-core/nv-sync/nv-sync/nv-sync-tmp.conf b/meta-openbmc-mods/meta-common/recipes-core/nv-sync/nv-sync/nv-sync-tmp.conf
new file mode 100644
index 000000000..e73e47129
--- /dev/null
+++ b/meta-openbmc-mods/meta-common/recipes-core/nv-sync/nv-sync/nv-sync-tmp.conf
@@ -0,0 +1,2 @@
+x /tmp/.rwfs - - - -
+x /tmp/.overlay - - - -
diff --git a/meta-openbmc-mods/meta-common/recipes-core/nv-sync/nv-sync/nv-sync.service b/meta-openbmc-mods/meta-common/recipes-core/nv-sync/nv-sync/nv-sync.service
new file mode 100644
index 000000000..4595541c6
--- /dev/null
+++ b/meta-openbmc-mods/meta-common/recipes-core/nv-sync/nv-sync/nv-sync.service
@@ -0,0 +1,11 @@
+[Unit]
+Description=Overlay sync to NV storage
+
+[Service]
+# Run a job to periodically sync the overlay to NV storage
+ExecStart=/usr/bin/nv-syncd
+# Due to sync delay stopping this service will take more than default 10 seconds
+TimeoutStopSec=20
+
+[Install]
+WantedBy=multi-user.target
diff --git a/meta-openbmc-mods/meta-common/recipes-core/nv-sync/nv-sync/nv-syncd b/meta-openbmc-mods/meta-common/recipes-core/nv-sync/nv-sync/nv-syncd
new file mode 100644
index 000000000..538c96875
--- /dev/null
+++ b/meta-openbmc-mods/meta-common/recipes-core/nv-sync/nv-sync/nv-syncd
@@ -0,0 +1,38 @@
+#!/bin/bash
+
+NVMP=/tmp/.rwfs
+SOMP=/var/sofs
+
+clean_var_volatile_tmp() {
+ rm -rf $NVMP/.overlay/var/volatile/tmp/* || :
+}
+
+do_sync() {
+ rsync -a --delete --exclude='**/var/volatile/tmp/**' /tmp/.overlay/ $NVMP/.overlay
+ sync $NVMP/.overlay
+}
+
+stop_nv() {
+ history -a
+ do_sync
+ mount -o remount,ro $NVMP
+ mount -o remount,ro $SOMP
+ exit 0
+}
+
+# register cleanup function
+trap stop_nv SIGINT
+trap stop_nv SIGTERM
+trap stop_nv EXIT
+
+# make sure the mount points are RW
+mount -o remount,rw $NVMP
+mount -o remount,rw $SOMP
+
+clean_var_volatile_tmp
+
+# Run rsync periodically to sync the overlay to NV storage
+while true; do
+ do_sync
+ sleep 10
+done
diff --git a/meta-openbmc-mods/meta-common/recipes-core/nv-sync/nv-sync_git.bb b/meta-openbmc-mods/meta-common/recipes-core/nv-sync/nv-sync_git.bb
new file mode 100644
index 000000000..a30df4dc6
--- /dev/null
+++ b/meta-openbmc-mods/meta-common/recipes-core/nv-sync/nv-sync_git.bb
@@ -0,0 +1,29 @@
+SUMMARY = "NV Overlay Sync"
+DESCRIPTION = "Script to periodically sync the overlay to NV storage"
+
+S = "${WORKDIR}"
+SRC_URI = "file://nv-sync.service \
+ file://nv-syncd \
+ file://nv-sync-tmp.conf \
+"
+
+LICENSE = "Apache-2.0"
+LIC_FILES_CHKSUM = "file://${INTELBASE}/COPYING.apache-2.0;md5=34400b68072d710fecd0a2940a0d1658"
+
+inherit systemd
+
+RDEPENDS:${PN} += "bash"
+
+FILES:${PN} += "${systemd_system_unitdir}/nv-sync.service \
+ ${libdir}/tmpfiles.d/nv-sync-tmp.conf"
+
+do_install() {
+ install -d ${D}${systemd_system_unitdir}
+ install -m 0644 ${WORKDIR}/nv-sync.service ${D}${systemd_system_unitdir}
+ install -d ${D}${bindir}
+ install -m 0755 ${WORKDIR}/nv-syncd ${D}${bindir}/nv-syncd
+ install -d ${D}${libdir}/tmpfiles.d
+ install -m 0644 ${WORKDIR}/nv-sync-tmp.conf ${D}${libdir}/tmpfiles.d/
+}
+
+SYSTEMD_SERVICE:${PN} += " nv-sync.service"