This package is required for the grub-btrfs daemon
Signed-off-by: Stefan Schantl stefan.schantl@ipfire.org --- config/rootfiles/common/inotify-tools | 19 ++++++ lfs/inotify-tools | 83 +++++++++++++++++++++++++++ make.sh | 1 + 3 files changed, 103 insertions(+) create mode 100644 config/rootfiles/common/inotify-tools create mode 100644 lfs/inotify-tools
diff --git a/config/rootfiles/common/inotify-tools b/config/rootfiles/common/inotify-tools new file mode 100644 index 000000000..f99d64c01 --- /dev/null +++ b/config/rootfiles/common/inotify-tools @@ -0,0 +1,19 @@ +usr/bin/fsnotifywait +usr/bin/fsnotifywatch +usr/bin/inotifywait +usr/bin/inotifywatch +#usr/include/inotifytools +#usr/include/inotifytools/fanotify-dfid-name.h +#usr/include/inotifytools/fanotify.h +#usr/include/inotifytools/inotify-nosys.h +#usr/include/inotifytools/inotify.h +#usr/include/inotifytools/inotifytools.h +#usr/lib/libinotifytools.a +#usr/lib/libinotifytools.la +#usr/lib/libinotifytools.so +usr/lib/libinotifytools.so.0 +usr/lib/libinotifytools.so.0.4.1 +#usr/share/man/man1/fsnotifywait.1 +#usr/share/man/man1/fsnotifywatch.1 +#usr/share/man/man1/inotifywait.1 +#usr/share/man/man1/inotifywatch.1 diff --git a/lfs/inotify-tools b/lfs/inotify-tools new file mode 100644 index 000000000..bb70fbfc6 --- /dev/null +++ b/lfs/inotify-tools @@ -0,0 +1,83 @@ +############################################################################### +# # +# IPFire.org - A linux based firewall # +# Copyright (C) 2007-2023 IPFire Team info@ipfire.org # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see http://www.gnu.org/licenses/. # +# # +############################################################################### + +############################################################################### +# Definitions +############################################################################### + +include Config + +VER = 4.23.9.0 + +THISAPP = inotify-tools-$(VER) +DL_FILE = $(THISAPP).tar.gz +DL_FROM = $(URL_IPFIRE) +DIR_APP = $(DIR_SRC)/$(THISAPP) +TARGET = $(DIR_INFO)/$(THISAPP) + +############################################################################### +# Top-level Rules +############################################################################### + +objects = $(DL_FILE) + +$(DL_FILE) = $(DL_FROM)/$(DL_FILE) + +$(DL_FILE)_BLAKE2 = eddb0e44721cd8674f2309046998de16a030ed9ad84c49bc5950b9362055db9242dc0de1c615c3bd6c1f2835c83fc55446c9f8e6da52a98870c53f4e6cfa31f9 + +install : $(TARGET) + +check : $(patsubst %,$(DIR_CHK)/%,$(objects)) + +download :$(patsubst %,$(DIR_DL)/%,$(objects)) + +b2 : $(subst %,%_BLAKE2,$(objects)) + +dist: + @$(PAK) + +############################################################################### +# Downloading, checking, b2sum +############################################################################### + +$(patsubst %,$(DIR_CHK)/%,$(objects)) : + @$(CHECK) + +$(patsubst %,$(DIR_DL)/%,$(objects)) : + @$(LOAD) + +$(subst %,%_BLAKE2,$(objects)) : + @$(B2SUM) + +############################################################################### +# Installation Details +############################################################################### + +$(TARGET) : $(patsubst %,$(DIR_DL)/%,$(objects)) + @$(PREBUILD) + @rm -rf $(DIR_APP) && cd $(DIR_SRC) && tar axf $(DIR_DL)/$(DL_FILE) + $(UPDATE_AUTOMAKE) + cd $(DIR_APP) && ./autogen.sh + cd $(DIR_APP) && ./configure \ + --prefix=/usr + cd $(DIR_APP) && make $(MAKETUNING) + cd $(DIR_APP) && make install + @rm -rf $(DIR_APP) + @$(POSTBUILD) diff --git a/make.sh b/make.sh index 3c0b9ef27..1834b927a 100755 --- a/make.sh +++ b/make.sh @@ -1713,6 +1713,7 @@ buildipfire() { lfsmake2 mympd lfsmake2 wsdd lfsmake2 btrfs-progs + lfsmake2 inotify-tools
# Kernelbuild ... current we have no platform that need # multi kernel builds so KCFG is empty
This kind of grub addon will extend the grub boot menu by a additional submenu where a BTRFS snapshot can be selected to directly use as root volume and boot into it.
The grub-btrfsd daemon is using inotify(tools) to watch the snapshot directory for new or deleted snapshots and calls grub-mkconfig to adjust the snapshot grub submenu
Signed-off-by: Stefan Schantl stefan.schantl@ipfire.org --- config/rootfiles/common/grub-btrfs | 14 ++++ config/rootfiles/common/x86_64/initscripts | 4 ++ lfs/grub-btrfs | 79 ++++++++++++++++++++++ lfs/initscripts | 3 + make.sh | 1 + src/initscripts/system/grub-btrfsd | 61 +++++++++++++++++ 6 files changed, 162 insertions(+) create mode 100644 config/rootfiles/common/grub-btrfs create mode 100644 lfs/grub-btrfs create mode 100644 src/initscripts/system/grub-btrfsd
diff --git a/config/rootfiles/common/grub-btrfs b/config/rootfiles/common/grub-btrfs new file mode 100644 index 000000000..a612af065 --- /dev/null +++ b/config/rootfiles/common/grub-btrfs @@ -0,0 +1,14 @@ +boot/grub/grubenv +etc/default/grub-btrfs +etc/default/grub-btrfs/config +etc/grub.d/41_snapshots-btrfs +usr/bin/grub-btrfsd +#usr/lib/systemd/system/grub-btrfsd.service +#usr/share/doc/grub-btrfs +#usr/share/doc/grub-btrfs/README.md +#usr/share/doc/grub-btrfs/initramfs-overlayfs.md +#usr/share/licenses +#usr/share/licenses/grub-btrfs +#usr/share/licenses/grub-btrfs/LICENSE +#usr/share/man/man8/grub-btrfs.8.bz2 +#usr/share/man/man8/grub-btrfsd.8.bz2 diff --git a/config/rootfiles/common/x86_64/initscripts b/config/rootfiles/common/x86_64/initscripts index a5e1596fb..2d6fa85dc 100644 --- a/config/rootfiles/common/x86_64/initscripts +++ b/config/rootfiles/common/x86_64/initscripts @@ -26,6 +26,7 @@ etc/rc.d/init.d/firewall etc/rc.d/init.d/firstsetup etc/rc.d/init.d/fsresize etc/rc.d/init.d/functions +etc/rc.d/init.d/grub-btrfsd etc/rc.d/init.d/halt etc/rc.d/init.d/ipsec etc/rc.d/init.d/leds @@ -92,6 +93,7 @@ etc/rc.d/init.d/vnstat etc/rc.d/init.d/waitdrives etc/rc.d/init.d/wlanclient #etc/rc.d/rc0.d +etc/rc.d/rc0.d/K01grub-btrfsd #etc/rc.d/rc0.d/K01imspetor #etc/rc.d/rc0.d/K01motion #etc/rc.d/rc0.d/K01vdradmin @@ -135,10 +137,12 @@ etc/rc.d/rc3.d/S32apache etc/rc.d/rc3.d/S40fcron etc/rc.d/rc3.d/S98rc.local #etc/rc.d/rc3.d/S98sslh +etc/rc.d/rc3.d/S99grub-btrfsd #etc/rc.d/rc3.d/S99imspetor #etc/rc.d/rc3.d/S99motion #etc/rc.d/rc3.d/S99vdradmin #etc/rc.d/rc6.d +etc/rc.d/rc6.d/K01grub-btrfsd #etc/rc.d/rc6.d/K01imspetor #etc/rc.d/rc6.d/K01motion #etc/rc.d/rc6.d/K01vdradmin diff --git a/lfs/grub-btrfs b/lfs/grub-btrfs new file mode 100644 index 000000000..8dc0c4f3e --- /dev/null +++ b/lfs/grub-btrfs @@ -0,0 +1,79 @@ +############################################################################### +# # +# IPFire.org - A linux based firewall # +# Copyright (C) 2007-2023 IPFire Team info@ipfire.org # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see http://www.gnu.org/licenses/. # +# # +############################################################################### + +############################################################################### +# Definitions +############################################################################### + +include Config + +VER = 4.13 + +THISAPP = grub-btrfs-$(VER) +DL_FILE = $(THISAPP).tar.gz +DL_FROM = $(URL_IPFIRE) +DIR_APP = $(DIR_SRC)/$(THISAPP) +TARGET = $(DIR_INFO)/$(THISAPP) + +############################################################################### +# Top-level Rules +############################################################################### + +objects = $(DL_FILE) + +$(DL_FILE) = $(DL_FROM)/$(DL_FILE) + +$(DL_FILE)_BLAKE2 = e2f11a0a8282e3ec8ff8223e3bad70b5d5c5e81b4d740a1bf3554db412dbe48a8a0f216f4e6c65ae1d11c01a27b8b92bae9b470c60d2389505ce089511536e1a + +install : $(TARGET) + +check : $(patsubst %,$(DIR_CHK)/%,$(objects)) + +download :$(patsubst %,$(DIR_DL)/%,$(objects)) + +b2 : $(subst %,%_BLAKE2,$(objects)) + +dist: + @$(PAK) + +############################################################################### +# Downloading, checking, b2sum +############################################################################### + +$(patsubst %,$(DIR_CHK)/%,$(objects)) : + @$(CHECK) + +$(patsubst %,$(DIR_DL)/%,$(objects)) : + @$(LOAD) + +$(subst %,%_BLAKE2,$(objects)) : + @$(B2SUM) + +############################################################################### +# Installation Details +############################################################################### + +$(TARGET) : $(patsubst %,$(DIR_DL)/%,$(objects)) + @$(PREBUILD) + @rm -rf $(DIR_APP) && cd $(DIR_SRC) && tar axf $(DIR_DL)/$(DL_FILE) + $(UPDATE_AUTOMAKE) + cd $(DIR_APP) && make install + @rm -rf $(DIR_APP) + @$(POSTBUILD) diff --git a/lfs/initscripts b/lfs/initscripts index e078632ab..4d67ee0c4 100644 --- a/lfs/initscripts +++ b/lfs/initscripts @@ -91,6 +91,7 @@ $(TARGET) : install -v -m 755 $$i /etc/rc.d/helper/; \ done
+ ln -sf ../init.d/grub-btrfsd /etc/rc.d/rc0.d/K01grub-btrfsd ln -sf ../init.d/imspetor /etc/rc.d/rc0.d/K01imspetor ln -sf ../init.d/motion /etc/rc.d/rc0.d/K01motion ln -sf ../init.d/vdradmin /etc/rc.d/rc0.d/K01vdradmin @@ -132,10 +133,12 @@ $(TARGET) : ln -sf ../init.d/fcron /etc/rc.d/rc3.d/S40fcron ln -sf ../../sysconfig/rc.local /etc/rc.d/rc3.d/S98rc.local ln -sf ../init.d/sslh /etc/rc.d/rc3.d/S98sslh + ln -sf ../init.d/grub-btrfsd /etc/rc.d/rc3.d/S99grub-btrfsd ln -sf ../init.d/imspetor /etc/rc.d/rc3.d/S99imspetor ln -sf ../init.d/motion /etc/rc.d/rc3.d/S99motion ln -sf ../init.d/vdradmin /etc/rc.d/rc3.d/S99vdradmin
+ ln -sf ../init.d/grub-btrfsd /etc/rc.d/rc6.d/K01grub-btrfsd ln -sf ../init.d/imspetor /etc/rc.d/rc6.d/K01imspetor ln -sf ../init.d/motion /etc/rc.d/rc6.d/K01motion ln -sf ../init.d/vdradmin /etc/rc.d/rc6.d/K01vdradmin diff --git a/make.sh b/make.sh index 1834b927a..adc03f4e6 100755 --- a/make.sh +++ b/make.sh @@ -1714,6 +1714,7 @@ buildipfire() { lfsmake2 wsdd lfsmake2 btrfs-progs lfsmake2 inotify-tools + lfsmake2 grub-btrfs
# Kernelbuild ... current we have no platform that need # multi kernel builds so KCFG is empty diff --git a/src/initscripts/system/grub-btrfsd b/src/initscripts/system/grub-btrfsd new file mode 100644 index 000000000..dc5e32ad4 --- /dev/null +++ b/src/initscripts/system/grub-btrfsd @@ -0,0 +1,61 @@ +#!/bin/sh +############################################################################### +# # +# IPFire.org - A linux based firewall # +# Copyright (C) 2007-2024 IPFire Team info@ipfire.org # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see http://www.gnu.org/licenses/. # +# # +############################################################################### + +. /etc/sysconfig/rc +. ${rc_functions} + +SNAPSHOTDIR="/.snapshots" +PIDFILE="/run/grub-btrfsd.pid" + +root_is_btrfs() { + [ "$(stat -f --format="%T" /)" == "btrfs" ] || return 1 + + return 0 +} + +case "$1" in + start) + root_is_btrfs || exit 0 + + boot_mesg "Starting Grub/Btrfs snapshot manager..." + loadproc -b -p "$PIDFILE" /usr/bin/grub-btrfsd --syslog "$SNAPSHOTDIR" + + # Store the gained PID to the defined pidfile + echo "$!" > "$PIDFILE" + ;; + + stop) + boot_mesg "Stopping grub-btrfsd..." + killproc -p "$PIDFILE" /usr/bin/grub-btrfsd + sleep 1; + ;; + + restart) + $0 stop + sleep 2 + $0 start + ;; + + *) + echo "Usage: $0 {start|stop|restart}" + exit 1 + ;; +esac
Hello,
On 24 Mar 2024, at 12:39, Stefan Schantl stefan.schantl@ipfire.org wrote:
This kind of grub addon will extend the grub boot menu by a additional submenu where a BTRFS snapshot can be selected to directly use as root volume and boot into it.
The grub-btrfsd daemon is using inotify(tools) to watch the snapshot directory for new or deleted snapshots and calls grub-mkconfig to adjust the snapshot grub submenu
Signed-off-by: Stefan Schantl stefan.schantl@ipfire.org
config/rootfiles/common/grub-btrfs | 14 ++++ config/rootfiles/common/x86_64/initscripts | 4 ++ lfs/grub-btrfs | 79 ++++++++++++++++++++++ lfs/initscripts | 3 + make.sh | 1 + src/initscripts/system/grub-btrfsd | 61 +++++++++++++++++ 6 files changed, 162 insertions(+) create mode 100644 config/rootfiles/common/grub-btrfs create mode 100644 lfs/grub-btrfs create mode 100644 src/initscripts/system/grub-btrfsd
diff --git a/config/rootfiles/common/grub-btrfs b/config/rootfiles/common/grub-btrfs new file mode 100644 index 000000000..a612af065 --- /dev/null +++ b/config/rootfiles/common/grub-btrfs @@ -0,0 +1,14 @@ +boot/grub/grubenv +etc/default/grub-btrfs +etc/default/grub-btrfs/config +etc/grub.d/41_snapshots-btrfs +usr/bin/grub-btrfsd +#usr/lib/systemd/system/grub-btrfsd.service +#usr/share/doc/grub-btrfs +#usr/share/doc/grub-btrfs/README.md +#usr/share/doc/grub-btrfs/initramfs-overlayfs.md +#usr/share/licenses +#usr/share/licenses/grub-btrfs +#usr/share/licenses/grub-btrfs/LICENSE +#usr/share/man/man8/grub-btrfs.8.bz2 +#usr/share/man/man8/grub-btrfsd.8.bz2 diff --git a/config/rootfiles/common/x86_64/initscripts b/config/rootfiles/common/x86_64/initscripts index a5e1596fb..2d6fa85dc 100644 --- a/config/rootfiles/common/x86_64/initscripts +++ b/config/rootfiles/common/x86_64/initscripts @@ -26,6 +26,7 @@ etc/rc.d/init.d/firewall etc/rc.d/init.d/firstsetup etc/rc.d/init.d/fsresize etc/rc.d/init.d/functions +etc/rc.d/init.d/grub-btrfsd etc/rc.d/init.d/halt etc/rc.d/init.d/ipsec etc/rc.d/init.d/leds @@ -92,6 +93,7 @@ etc/rc.d/init.d/vnstat etc/rc.d/init.d/waitdrives etc/rc.d/init.d/wlanclient #etc/rc.d/rc0.d +etc/rc.d/rc0.d/K01grub-btrfsd #etc/rc.d/rc0.d/K01imspetor #etc/rc.d/rc0.d/K01motion #etc/rc.d/rc0.d/K01vdradmin @@ -135,10 +137,12 @@ etc/rc.d/rc3.d/S32apache etc/rc.d/rc3.d/S40fcron etc/rc.d/rc3.d/S98rc.local #etc/rc.d/rc3.d/S98sslh +etc/rc.d/rc3.d/S99grub-btrfsd #etc/rc.d/rc3.d/S99imspetor #etc/rc.d/rc3.d/S99motion #etc/rc.d/rc3.d/S99vdradmin #etc/rc.d/rc6.d +etc/rc.d/rc6.d/K01grub-btrfsd #etc/rc.d/rc6.d/K01imspetor #etc/rc.d/rc6.d/K01motion #etc/rc.d/rc6.d/K01vdradmin diff --git a/lfs/grub-btrfs b/lfs/grub-btrfs new file mode 100644 index 000000000..8dc0c4f3e --- /dev/null +++ b/lfs/grub-btrfs @@ -0,0 +1,79 @@ +############################################################################### +# # +# IPFire.org - A linux based firewall # +# Copyright (C) 2007-2023 IPFire Team info@ipfire.org # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see http://www.gnu.org/licenses/. # +# # +###############################################################################
+############################################################################### +# Definitions +###############################################################################
+include Config
+VER = 4.13
+THISAPP = grub-btrfs-$(VER) +DL_FILE = $(THISAPP).tar.gz +DL_FROM = $(URL_IPFIRE) +DIR_APP = $(DIR_SRC)/$(THISAPP) +TARGET = $(DIR_INFO)/$(THISAPP)
+############################################################################### +# Top-level Rules +###############################################################################
+objects = $(DL_FILE)
+$(DL_FILE) = $(DL_FROM)/$(DL_FILE)
+$(DL_FILE)_BLAKE2 = e2f11a0a8282e3ec8ff8223e3bad70b5d5c5e81b4d740a1bf3554db412dbe48a8a0f216f4e6c65ae1d11c01a27b8b92bae9b470c60d2389505ce089511536e1a
+install : $(TARGET)
+check : $(patsubst %,$(DIR_CHK)/%,$(objects))
+download :$(patsubst %,$(DIR_DL)/%,$(objects))
+b2 : $(subst %,%_BLAKE2,$(objects))
+dist:
- @$(PAK)
+############################################################################### +# Downloading, checking, b2sum +###############################################################################
+$(patsubst %,$(DIR_CHK)/%,$(objects)) :
- @$(CHECK)
+$(patsubst %,$(DIR_DL)/%,$(objects)) :
- @$(LOAD)
+$(subst %,%_BLAKE2,$(objects)) :
- @$(B2SUM)
+############################################################################### +# Installation Details +###############################################################################
+$(TARGET) : $(patsubst %,$(DIR_DL)/%,$(objects))
- @$(PREBUILD)
- @rm -rf $(DIR_APP) && cd $(DIR_SRC) && tar axf $(DIR_DL)/$(DL_FILE)
- $(UPDATE_AUTOMAKE)
- cd $(DIR_APP) && make install
- @rm -rf $(DIR_APP)
- @$(POSTBUILD)
diff --git a/lfs/initscripts b/lfs/initscripts index e078632ab..4d67ee0c4 100644 --- a/lfs/initscripts +++ b/lfs/initscripts @@ -91,6 +91,7 @@ $(TARGET) : install -v -m 755 $$i /etc/rc.d/helper/; \ done
- ln -sf ../init.d/grub-btrfsd /etc/rc.d/rc0.d/K01grub-btrfsd
ln -sf ../init.d/imspetor /etc/rc.d/rc0.d/K01imspetor ln -sf ../init.d/motion /etc/rc.d/rc0.d/K01motion ln -sf ../init.d/vdradmin /etc/rc.d/rc0.d/K01vdradmin @@ -132,10 +133,12 @@ $(TARGET) : ln -sf ../init.d/fcron /etc/rc.d/rc3.d/S40fcron ln -sf ../../sysconfig/rc.local /etc/rc.d/rc3.d/S98rc.local ln -sf ../init.d/sslh /etc/rc.d/rc3.d/S98sslh
- ln -sf ../init.d/grub-btrfsd /etc/rc.d/rc3.d/S99grub-btrfsd
ln -sf ../init.d/imspetor /etc/rc.d/rc3.d/S99imspetor ln -sf ../init.d/motion /etc/rc.d/rc3.d/S99motion ln -sf ../init.d/vdradmin /etc/rc.d/rc3.d/S99vdradmin
- ln -sf ../init.d/grub-btrfsd /etc/rc.d/rc6.d/K01grub-btrfsd
ln -sf ../init.d/imspetor /etc/rc.d/rc6.d/K01imspetor ln -sf ../init.d/motion /etc/rc.d/rc6.d/K01motion ln -sf ../init.d/vdradmin /etc/rc.d/rc6.d/K01vdradmin diff --git a/make.sh b/make.sh index 1834b927a..adc03f4e6 100755 --- a/make.sh +++ b/make.sh @@ -1714,6 +1714,7 @@ buildipfire() { lfsmake2 wsdd lfsmake2 btrfs-progs lfsmake2 inotify-tools
lfsmake2 grub-btrfs
# Kernelbuild ... current we have no platform that need # multi kernel builds so KCFG is empty
diff --git a/src/initscripts/system/grub-btrfsd b/src/initscripts/system/grub-btrfsd new file mode 100644 index 000000000..dc5e32ad4 --- /dev/null +++ b/src/initscripts/system/grub-btrfsd @@ -0,0 +1,61 @@ +#!/bin/sh +############################################################################### +# # +# IPFire.org - A linux based firewall # +# Copyright (C) 2007-2024 IPFire Team info@ipfire.org # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see http://www.gnu.org/licenses/. # +# # +###############################################################################
+. /etc/sysconfig/rc +. ${rc_functions}
+SNAPSHOTDIR="/.snapshots" +PIDFILE="/run/grub-btrfsd.pid"
+root_is_btrfs() {
- [ "$(stat -f --format="%T" /)" == "btrfs" ] || return 1
- return 0
+}
I think we should have this function available in the “functions” file as I can see other things needing this, too.
Recently I have been touching a lot of code that had the same functionality implemented several times (at least two, sometimes even three or four times) which causes many problems. So I would like to be more strict in what we accept in the code so that things don’t become even messier than they are now. Not that this function here is the biggest problem, but I have been put in a really bad mood about a lot of OpenVPN and web UI code…
I think we can even solve this a lot smarter. Can we have the function simply return the filesystem type of the root filesystem? You can then write code like this:
case “$(root_fs_type)” in btrfs) … ;; esac
If there is any necessity to deal with other filesystem the case could match something else, too without introducing another function for another filesystem.
I think this could already become handy when deprecating reiserfs.
This would become absolute gold if you would accept the mountpoint so that we can even check for other filesystems as they might use reiferfs, too.
Best, -Michael
+case "$1" in
start)
- root_is_btrfs || exit 0
- boot_mesg "Starting Grub/Btrfs snapshot manager..."
- loadproc -b -p "$PIDFILE" /usr/bin/grub-btrfsd --syslog "$SNAPSHOTDIR"
- # Store the gained PID to the defined pidfile
- echo "$!" > "$PIDFILE"
loadproc should do this automatically already. If not, then something is broken.
It is also enough to define PIDFILE globally as loadproc/killproc etc. will automatically use it.
- ;;
- stop)
- boot_mesg "Stopping grub-btrfsd..."
- killproc -p "$PIDFILE" /usr/bin/grub-btrfsd
- sleep 1;
- ;;
- restart)
- $0 stop
- sleep 2
- $0 start
- ;;
- *)
- echo "Usage: $0 {start|stop|restart}"
- exit 1
- ;;
+esac
2.39.2
Signed-off-by: Stefan Schantl stefan.schantl@ipfire.org --- src/initscripts/system/functions | 8 ++++++++ 1 file changed, 8 insertions(+)
diff --git a/src/initscripts/system/functions b/src/initscripts/system/functions index 5a26aef45..0fa825000 100644 --- a/src/initscripts/system/functions +++ b/src/initscripts/system/functions @@ -883,3 +883,11 @@ running_on_oci() { # We are not running on OCI return 1 } + +volume_fs_type() { + if [ ! -d "${1}" ]; then + return + fi + + echo "$(stat -f --format="%T" ${1})" +}
Signed-off-by: Stefan Schantl stefan.schantl@ipfire.org --- src/initscripts/system/grub-btrfsd | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-)
diff --git a/src/initscripts/system/grub-btrfsd b/src/initscripts/system/grub-btrfsd index dc5e32ad4..90582b1b1 100644 --- a/src/initscripts/system/grub-btrfsd +++ b/src/initscripts/system/grub-btrfsd @@ -25,21 +25,18 @@ SNAPSHOTDIR="/.snapshots" PIDFILE="/run/grub-btrfsd.pid"
-root_is_btrfs() { - [ "$(stat -f --format="%T" /)" == "btrfs" ] || return 1 - - return 0 -} - case "$1" in start) - root_is_btrfs || exit 0 + root_fs_type=$(volume_fs_type "/")
- boot_mesg "Starting Grub/Btrfs snapshot manager..." - loadproc -b -p "$PIDFILE" /usr/bin/grub-btrfsd --syslog "$SNAPSHOTDIR" + case "$root_fs_type" in + btrfs)
- # Store the gained PID to the defined pidfile - echo "$!" > "$PIDFILE" + boot_mesg "Starting Grub/Btrfs snapshot manager..." + loadproc -b -p "$PIDFILE" /usr/bin/grub-btrfsd --syslog "$SNAPSHOTDIR" + echo "$!" > "$PIDFILE" + ;; + esac ;;
stop)
Signed-off-by: Stefan Schantl stefan.schantl@ipfire.org --- src/initscripts/system/grub-btrfsd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/initscripts/system/grub-btrfsd b/src/initscripts/system/grub-btrfsd index 90582b1b1..26760f9be 100644 --- a/src/initscripts/system/grub-btrfsd +++ b/src/initscripts/system/grub-btrfsd @@ -32,7 +32,7 @@ case "$1" in case "$root_fs_type" in btrfs)
- boot_mesg "Starting Grub/Btrfs snapshot manager..." + boot_mesg "Starting GRUB/Btrfs Daemon..." loadproc -b -p "$PIDFILE" /usr/bin/grub-btrfsd --syslog "$SNAPSHOTDIR" echo "$!" > "$PIDFILE" ;;
This case is already covered by the PID mechanism of the used functions
Signed-off-by: Stefan Schantl stefan.schantl@ipfire.org --- src/initscripts/system/grub-btrfsd | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/src/initscripts/system/grub-btrfsd b/src/initscripts/system/grub-btrfsd index 26760f9be..5981c3a0a 100644 --- a/src/initscripts/system/grub-btrfsd +++ b/src/initscripts/system/grub-btrfsd @@ -33,15 +33,14 @@ case "$1" in btrfs)
boot_mesg "Starting GRUB/Btrfs Daemon..." - loadproc -b -p "$PIDFILE" /usr/bin/grub-btrfsd --syslog "$SNAPSHOTDIR" - echo "$!" > "$PIDFILE" + loadproc -b /usr/bin/grub-btrfsd --syslog "$SNAPSHOTDIR" ;; esac ;;
stop) boot_mesg "Stopping grub-btrfsd..." - killproc -p "$PIDFILE" /usr/bin/grub-btrfsd + killproc -p /usr/bin/grub-btrfsd sleep 1; ;;
On 27 Mar 2024, at 05:15, Stefan Schantl stefan.schantl@ipfire.org wrote:
This case is already covered by the PID mechanism of the used functions
Signed-off-by: Stefan Schantl stefan.schantl@ipfire.org
src/initscripts/system/grub-btrfsd | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/src/initscripts/system/grub-btrfsd b/src/initscripts/system/grub-btrfsd index 26760f9be..5981c3a0a 100644 --- a/src/initscripts/system/grub-btrfsd +++ b/src/initscripts/system/grub-btrfsd @@ -33,15 +33,14 @@ case "$1" in btrfs)
boot_mesg "Starting GRUB/Btrfs Daemon..."
- loadproc -b -p "$PIDFILE" /usr/bin/grub-btrfsd --syslog "$SNAPSHOTDIR"
- echo "$!" > "$PIDFILE"
- loadproc -b /usr/bin/grub-btrfsd --syslog "$SNAPSHOTDIR"
;; esac ;;
stop) boot_mesg "Stopping grub-btrfsd..."
- killproc -p "$PIDFILE" /usr/bin/grub-btrfsd
- killproc -p /usr/bin/grub-btrfsd
sleep 1;
Why is there a sleep here?
;;
-- 2.39.2
Am Mittwoch, dem 27.03.2024 um 10:15 +0000 schrieb Michael Tremer:
On 27 Mar 2024, at 05:15, Stefan Schantl stefan.schantl@ipfire.org wrote:
This case is already covered by the PID mechanism of the used functions
Signed-off-by: Stefan Schantl stefan.schantl@ipfire.org
src/initscripts/system/grub-btrfsd | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/src/initscripts/system/grub-btrfsd b/src/initscripts/system/grub-btrfsd index 26760f9be..5981c3a0a 100644 --- a/src/initscripts/system/grub-btrfsd +++ b/src/initscripts/system/grub-btrfsd @@ -33,15 +33,14 @@ case "$1" in btrfs)
boot_mesg "Starting GRUB/Btrfs Daemon..."
- loadproc -b -p "$PIDFILE" /usr/bin/grub-btrfsd --syslog
"$SNAPSHOTDIR"
- echo "$!" > "$PIDFILE"
- loadproc -b /usr/bin/grub-btrfsd --syslog "$SNAPSHOTDIR"
;; esac ;;
stop) boot_mesg "Stopping grub-btrfsd..."
- killproc -p "$PIDFILE" /usr/bin/grub-btrfsd
- killproc -p /usr/bin/grub-btrfsd
sleep 1;
Why is there a sleep here?
Good catch, that's a classical orphaned piece of code when removing some other stuff.
I'll handle it in a v2 patchset.
;;
-- 2.39.2
It is almost as if there is something good about having this review process :)
On 27 Mar 2024, at 19:42, Stefan Schantl stefan.schantl@ipfire.org wrote:
Am Mittwoch, dem 27.03.2024 um 10:15 +0000 schrieb Michael Tremer:
On 27 Mar 2024, at 05:15, Stefan Schantl stefan.schantl@ipfire.org wrote:
This case is already covered by the PID mechanism of the used functions
Signed-off-by: Stefan Schantl stefan.schantl@ipfire.org
src/initscripts/system/grub-btrfsd | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/src/initscripts/system/grub-btrfsd b/src/initscripts/system/grub-btrfsd index 26760f9be..5981c3a0a 100644 --- a/src/initscripts/system/grub-btrfsd +++ b/src/initscripts/system/grub-btrfsd @@ -33,15 +33,14 @@ case "$1" in btrfs)
boot_mesg "Starting GRUB/Btrfs Daemon..."
- loadproc -b -p "$PIDFILE" /usr/bin/grub-btrfsd --syslog
"$SNAPSHOTDIR"
- echo "$!" > "$PIDFILE"
- loadproc -b /usr/bin/grub-btrfsd --syslog "$SNAPSHOTDIR"
;; esac ;;
stop) boot_mesg "Stopping grub-btrfsd..."
- killproc -p "$PIDFILE" /usr/bin/grub-btrfsd
- killproc -p /usr/bin/grub-btrfsd
sleep 1;
Why is there a sleep here?
Good catch, that's a classical orphaned piece of code when removing some other stuff.
I'll handle it in a v2 patchset.
;;
-- 2.39.2
Hello Stefan,
On 27 Mar 2024, at 05:15, Stefan Schantl stefan.schantl@ipfire.org wrote:
Signed-off-by: Stefan Schantl stefan.schantl@ipfire.org
src/initscripts/system/functions | 8 ++++++++ 1 file changed, 8 insertions(+)
diff --git a/src/initscripts/system/functions b/src/initscripts/system/functions index 5a26aef45..0fa825000 100644 --- a/src/initscripts/system/functions +++ b/src/initscripts/system/functions @@ -883,3 +883,11 @@ running_on_oci() { # We are not running on OCI return 1 }
+volume_fs_type() {
- if [ ! -d "${1}" ]; then
- return
- fi
- echo "$(stat -f --format="%T" ${1})"
You don’t need to run a sub shell for this and echo the result. It would be enough to just call stat with its arguments.
+}
2.39.2
Am Mittwoch, dem 27.03.2024 um 10:15 +0000 schrieb Michael Tremer:
Hello Stefan,
On 27 Mar 2024, at 05:15, Stefan Schantl stefan.schantl@ipfire.org wrote:
Signed-off-by: Stefan Schantl stefan.schantl@ipfire.org
src/initscripts/system/functions | 8 ++++++++ 1 file changed, 8 insertions(+)
diff --git a/src/initscripts/system/functions b/src/initscripts/system/functions index 5a26aef45..0fa825000 100644 --- a/src/initscripts/system/functions +++ b/src/initscripts/system/functions @@ -883,3 +883,11 @@ running_on_oci() { # We are not running on OCI return 1 }
+volume_fs_type() {
- if [ ! -d "${1}" ]; then
- return
- fi
- echo "$(stat -f --format="%T" ${1})"
You don’t need to run a sub shell for this and echo the result. It would be enough to just call stat with its arguments.
Thanks for pointing this out,
I'll remove the subshell call in a v2 patch.
+}
2.39.2