Skip to content

Commit

Permalink
Replace fstab by explicit systemd units to ensure right mount order (#…
Browse files Browse the repository at this point in the history
…807)

To ensure ZRAM and Samba properly work together on sharing
/srv/openhab2-*, we need to change the order of mounts.
As this cannot be done in fstab, I removed them and setup separate
systemd mount units instead.

Signed-off-by: Markus Storm <[email protected]>
  • Loading branch information
mstormi committed May 11, 2020
1 parent 48671a9 commit 9a2966f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 10 deletions.
31 changes: 21 additions & 10 deletions functions/system.bash
Original file line number Diff line number Diff line change
Expand Up @@ -127,22 +127,33 @@ vimrc_copy() {
echo "OK"
}

create_mount() {
F=/etc/systemd/system/$(systemd-escape --path /srv/openhab2-"${2}").mount
sed -e "s|%SRC|$1|g" -e "s|%DEST|$2|g" "$BASEDIR"/includes/mount_template > "$F"
systemctl -q enable "srv-openhab2\\x2d$2.mount"
systemctl -q start "srv-openhab2\\x2d$2.mount"
}

srv_bind_mounts() {
echo -n "$(timestamp) [openHABian] Preparing openHAB folder mounts under /srv/... "
systemctl is-active --quiet smbd && systemctl stop smbd
systemctl is-active --quiet zram-config && systemctl stop zram-config
cond_redirect umount -q /srv/openhab2-{sys,conf,userdata,logs,addons}
sed -i "\\#[ \\t]/srv/openhab2-#d" /etc/fstab
sed -i "/^$/d" /etc/fstab
( echo ""
echo "/usr/share/openhab2 /srv/openhab2-sys none bind 0 0"
echo "/etc/openhab2 /srv/openhab2-conf none bind 0 0"
echo "/var/lib/openhab2 /srv/openhab2-userdata none bind 0 0"
echo "/var/log/openhab2 /srv/openhab2-logs none bind 0 0"
echo "/usr/share/openhab2/addons /srv/openhab2-addons none bind 0 0"
) >> /etc/fstab
cond_redirect cat /etc/fstab
# dummy " to fix vim coloring
cond_redirect rm -f /etc/systemd/system/srv*.mount
cond_redirect mkdir -p /srv/openhab2-{sys,conf,userdata,logs,addons}
cond_redirect cp "$BASEDIR"/includes/srv_readme.txt /srv/README.txt
cond_redirect chmod ugo+w /srv /srv/README.txt
if cond_redirect mount --all --verbose; then echo "OK"; else echo "FAILED"; fi

cond_redirect create_mount /usr/share/openhab2 sys
cond_redirect create_mount /etc/openhab2 conf
cond_redirect create_mount /var/lib/openhab2 userdata
cond_redirect create_mount /var/log/openhab2 logs
cond_redirect create_mount /usr/share/openhab2/addons addons

if [ -f /etc/ztab ]; then systemctl start zram-config; fi
if [ -f /etc/samba/smb.conf ]; then systemctl start smbd; fi
}

permissions_corrections() {
Expand Down
13 changes: 13 additions & 0 deletions includes/mount_template
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[Unit]
Description=openhab2-%DEST mount
After=zram-config.service

[Mount]
What=%SRC
Where=/srv/openhab2-%DEST
Type=none
Options=bind

[Install]
WantedBy=multi-user.target

0 comments on commit 9a2966f

Please sign in to comment.