Skip to content

Commit da129b9

Browse files
author
Guy
committed
Added Debian Sysvinit support
1 parent 6845af4 commit da129b9

3 files changed

Lines changed: 152 additions & 0 deletions

File tree

‎Makefile‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ PREFIX ?= /usr
44
INITCPIO ?= false
55
SYSTEMD ?= true
66
OPENRC ?= false
7+
SYSVINIT ?= false
78

89
BOOT_DIR_DEBIAN ?= /boot/grub
910
BOOT_DIR_FEDORA ?= /boot/grub2
@@ -64,6 +65,10 @@ install:
6465
install -Dm744 grub-btrfsd.initd "$(DESTDIR)/etc/init.d/grub-btrfsd"; \
6566
install -Dm644 grub-btrfsd.confd "$(DESTDIR)/etc/conf.d/grub-btrfsd"; \
6667
fi
68+
@if test "$(SYSVINIT)" = true; then \
69+
echo "Installing sysvinit init.d file"; \
70+
install -Dm755 grub-btrfsd.sysvinit.initd "$(DESTDIR)/etc/init.d/grub-btrfsd"; \
71+
fi
6772
@# Arch Linux like distros only :
6873
@if test "$(INITCPIO)" = true; then \
6974
echo "Installing initcpio hook"; \

‎README.md‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,51 @@ After that, the daemon should be restarted with:
274274
sudo rc-service grub-btrfsd restart
275275
```
276276

277+
- - -
278+
#### grub-btrfsd Sysvinit instructions
279+
The sysvinit grub-btrfsd script is designed for Debian and
280+
Debian-based distributions using sysvinit (Devuan, MX Linux, etc). It depends on Linux
281+
Standards Base (LSB) init functions which are located at
282+
`/lib/lsb/init-functions` on Debian and Debian-derivatives. These functions may be located in a
283+
different directory in other distributions using sysvinit, and the
284+
functions contained therein may differ from those called in the script.
285+
286+
To start the daemon run:
287+
```bash
288+
sudo service grub-btrfsd start
289+
```
290+
291+
To activate it during system startup, run:
292+
```bash
293+
sudo update-rc.d grub-btrfsd defaults
294+
```
295+
296+
##### 💼 Snapshots not in `/.snapshots` for Sysvinit
297+
By default the daemon is watching the directory `/.snapshots`. If the daemon should watch a different directory, it can be edited by passing different arguments to it.
298+
Arguments are passed to grub-btrfsd via `DAEMON_ARGS` and `SNAPSHOTS`
299+
variables in the script `/etc/init.d/grub-btrfsd`.
300+
The variable `SNAPSHOTS` defines the path the daemon will monitor for
301+
snapshots.
302+
303+
After editing, the applicable portion of the file should look like this:
304+
305+
``` bash
306+
SNAPSHOTS="/.snapshots" # Snapper in the root directory
307+
# SNAPSHOTS="/run/timeshift/backup/timeshift-btrfs/snapshots" # Timeshift < v22.06
308+
309+
## Optional arguments to run with the daemon
310+
# Append options to this like this:
311+
# DAEMON_ARGS="--syslog --timeshift-auto --verbose"
312+
# Possible options are:
313+
# -t, --timeshift-auto Automatically detect Timeshifts snapshot directory for timeshift >= 22.06
314+
# -o, --timeshift-old Look for snapshots in directory of Timeshift <v22.06 (requires --timeshift-auto)
315+
# -l, --log-file Specify a logfile to write to
316+
# -v, --verbose Let the log of the daemon be more verbose
317+
# -s, --syslog Write to syslog
318+
319+
DAEMON_ARGS="--syslog"
320+
```
321+
277322
##### 🔒 Snapshots on LUKS encrypted devices
278323
By default, grub-btrfs generates entries that does not load modules for dealing with encrypted devices.
279324
Enable the `GRUB_BTRFS_ENABLE_CRYPTODISK` variable in `/etc/default/grub-btrfs/config` to load said modules and then execute the steps to mount encrypted root after selecting the snapshot.

‎grub-btrfsd.sysvinit.initd‎

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
#!/bin/sh
2+
### BEGIN INIT INFO
3+
# Provides: grub-btrfsd
4+
# Required-Start: $local_fs $syslog
5+
# Required-Stop: $local_fs $syslog
6+
# Default-Start: 2 3 4 5
7+
# Default-Stop: 0 1 6
8+
# Short-Description: Regenerate grub-btrfs.cfg
9+
# Description: Monitors btrfs snapshots created with snapper
10+
# or Timeshift and automatically regenerates
11+
# grub-btrfs.cfg.
12+
### END INIT INFO
13+
14+
PATH=/usr/sbin:/usr/bin:/sbin:/bin
15+
16+
DESC="grub-btrfs snapshot daemon"
17+
NAME=grub-btrfsd
18+
DAEMON=/usr/bin/$NAME
19+
PIDFILE=/run/$NAME.pid
20+
21+
SCRIPTNAME=/etc/init.d/$NAME
22+
23+
SNAPSHOTS="/.snapshots" # Snapper in the root directory
24+
# SNAPSHOTS="/run/timeshift/backup/timeshift-btrfs/snapshots" # Timeshift < v22.06
25+
26+
## Optional arguments to run with the daemon
27+
# Append options to this like this:
28+
# DAEMON_ARGS="--syslog --timeshift-auto --verbose"
29+
# Possible options are:
30+
# -t, --timeshift-auto Automatically detect Timeshifts snapshot directory for timeshift >= 22.06
31+
# -o, --timeshift-old Look for snapshots in directory of Timeshift <v22.06 (requires --timeshift-auto)
32+
# -l, --log-file Specify a logfile to write to
33+
# -v, --verbose Let the log of the daemon be more verbose
34+
# -s, --syslog Write to syslog
35+
36+
DAEMON_ARGS="--syslog" # Snapper
37+
# DAEMON_ARGS="--syslog --timeshift-auto --verbose" # Timeshift >= 22.06
38+
39+
# Exit if the package is not installed
40+
[ -x "$DAEMON" ] || exit 0
41+
42+
# Load LSB init functions.
43+
# This is the path for Debian and Devuan, may vary on other distributions.
44+
. /lib/lsb/init-functions
45+
46+
do_start() {
47+
start-stop-daemon \
48+
--start \
49+
--background \
50+
--make-pidfile \
51+
--pidfile "$PIDFILE" \
52+
--exec "$DAEMON" -- \
53+
$DAEMON_ARGS \
54+
"$SNAPSHOTS"
55+
}
56+
57+
do_stop() {
58+
start-stop-daemon \
59+
--stop \
60+
--quiet \
61+
--retry=TERM/30/KILL/5 \
62+
--pidfile "$PIDFILE"
63+
}
64+
65+
case "$1" in
66+
start)
67+
log_daemon_msg "Starting $DESC" "$NAME"
68+
if do_start; then
69+
log_end_msg 0
70+
else
71+
log_end_msg 1
72+
fi
73+
;;
74+
stop)
75+
log_daemon_msg "Stopping $DESC" "$NAME"
76+
if do_stop; then
77+
log_end_msg 0
78+
else
79+
log_end_msg 1
80+
fi
81+
;;
82+
restart|force-reload)
83+
log_daemon_msg "Restarting $DESC" "$NAME"
84+
do_stop
85+
sleep 1
86+
if do_start; then
87+
log_end_msg 0
88+
else
89+
log_end_msg 1
90+
fi
91+
;;
92+
status)
93+
status_of_proc -p "$PIDFILE" "$DAEMON" "$NAME"
94+
exit $?
95+
;;
96+
*)
97+
echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload|status}"
98+
exit 2
99+
;;
100+
esac
101+
102+
exit 0

0 commit comments

Comments
 (0)