done
}
+# usage: funcp COMMAND [SECOND_INTERVAL]
+# like dfp, but pass in a command name which will output a KiB integer.
+#
+# example, when removing a btrfs disk, waiting for its Data allocation to go down to 0:
+# bf() { btrfs fi usage -k / | sed -rn '/^Data/,/S7KGNU0X708190H-root/p'|tail -n1|awk '{print $2}' | sed -r 's/[^0-9].*//'; }
+# funcp bf
+funcp() {
+ local a b mp interval
+ cmd=$1
+ interval=${2:-90}
+ if [[ ! $cmd ]]; then
+ echo "funcp: error, missing 1st arg" >&2
+ return 1
+ fi
+ while true; do
+ a=$($cmd)
+ sleep $interval
+ b=$($cmd)
+ printf "used mib: %'d mib/min: %s gib/h: %s\n" $(( b /1000 )) $(( (b-a) / (interval * 1000 / 60 ) )) \
+ $(( (b-a) / (interval * 1000000 / (60*60) ) ))
+ done
+}
+
# get ipv4 ip from HOST. or if it is already a number, return that
hostip() {
local host="$1"
etail() {
tail -F /var/log/exim4/mainlog /var/log/exim4/*main /var/log/exim4/paniclog /var/log/exim4/*panic -n 200 "$@"
- }
+}
etail1() {
tail -F /var/log/exim4/mainlog -n 200 "$@"
}
#time /t/sc/scancode --info --classify --only-findings --max-in-memory 300000 -clpue --unknown-licenses --tallies --tallies-with-details --summary --generated --json-pp scan.json .
}
+# cryptsetup luksClose $1 + checks /dev/mapper for the arg.
+cryptc() {
+ local arg="$1"
+ if [[ ! -e $arg && -e /dev/mapper/$arg ]]; then
+ arg="/dev/mapper/$arg"
+ echo "cryptc: path fixup: $arg"
+ fi
+ cryptsetup luksClose "$arg"
+}
+
+# crypt open
+crypto() {
+ cryptsetup luksOpen "$@"
+}
+
# iptables -I without duplication.
iptI() { ${*/ -I/ -C/} 2>/dev/null || "$@"; }
# iptables -A without duplication.
}
fi
-dusage="5 10"
-musage="5"
check-idle() {
type -p xscreensaver-command &>/dev/null || return 0
Usage: ${0##*/} [OPTIONS]
Do btrfs maintence or stop if we have X and xprintidle shows a user
-Normally, no options are needed.
-
---check Only check if an existing maintence should be cancelled due to
- nonidle user and run in a loop every 20 seconds for 10
- minutes.
-
--dry_run Just print out what we would do.
---force Run regardless of user idle status on all disks and do scrub
- regardless of when it was last run.
---no-stats Avoid checking error statistics. Use this to avoid a rare race
- condition when running --check concurrently with normal run.
-
-h|--help Show help
ret=0; getopt -T || ret=$?
[[ $ret == 4 ]] || { echo "Install util-linux for enhanced getopt" >&2; exit 1; }
-check=false
dry_run=false
-force=false
-stats=true
-temp=$(getopt -l help,check,dry_run,force,no-stats h "$@") || usage 1
+temp=$(getopt -l help,dry_run h "$@") || usage 1
eval set -- "$temp"
while true; do
case $1 in
- --check) check=true ;;
--dry_run) dry_run=true ;;
- --force) force=true ;;
- --no-stats) stats=false ;;
-h|--help) usage ;;
--) shift; break ;;
*) echo "$0: unexpected args: $*" >&2 ; usage 1 ;;
##### end command line parsing ########
+# todo: for previous scrubs, we shoudl do:
+# cd /var/lib/btrfs
+# for uid in *; do
+# # grab 3 things out of that file:
+# # scrub status:1
+# finished:1
+# t_start:1738738808 (epoch seconds roughly at the end or start of the last scrub. good enough for our purposes)
+# I don't now what other status numbers are, but I should test it.
+#
+# Instead of canceling, we will just have a formula:
+#
+# $(nproc)
+#
+# read -r _ la1 la2 _ </proc/loadavg
+# la1=$(e "$la1 * 100" | bc | sed 's/\..*//)
+# la2=$(e "$la2 * 100" | bc | sed 's/\..*//)
+#
+# load_avg="$la1"
+# if (( la1 < la2 )); then
+# load_avg="$la2"
+# fi
+#
+# bw_limit=500mb/s * (1 - (load_avg / nproc))
+#
+# And set that per https://btrfs.readthedocs.io/en/latest/Scrub.html
+
main() {
if ! $force; then
check-idle
mnt=$($fnd --output "TARGET" --first-only --source $x)
[[ $mnt ]] || continue
- #### begin look for diff in stats, eg: increasing error count ####
+ ####### begin look for diff in stats, eg: increasing error count ####
if $stats; then
tmp=$(mktemp)
# ${mnt%/} so that if mnt is / we avoid making a buggy looking path
fi
rm -f $tmp
fi
- #### end look for diff in stats, eg: increasing error count ####
+ ######## end look for diff in stats, eg: increasing error count ####
+
+ echo 1 | tee /sys/fs/btrfs/*/allocation/data/periodic_reclaim /sys/fs/btrfs/*/allocation/data/dynamic_reclaim >/dev/null
- if $check; then
- if ! $locked; then
- if $dry_run; then
- echo "$0: not idle. if this wasnt a dry run, btrfs scrub cancel $mnt"
- else
- echo "btrfsmaint: canceling scrub of $mnt"
- btrfs scrub cancel $mnt &>/dev/null ||:
- fi
- fi
- continue
- fi
- # for comparing before and after balance.
- # the log is already fairly verbose, so commented.
- # e btrfs filesystem df $mnt
- # e df -H $mnt
- if btrfs filesystem df $mnt | grep -q "Data+Metadata"; then
- for usage in $dusage; do
- dr ionice -c 3 btrfs balance start -dusage=$usage -musage=$usage $mnt
- done
- else
- dr ionice -c 3 btrfs balance start -dusage=0 $mnt
- for usage in $dusage; do
- dr ionice -c 3 btrfs balance start -dusage=$usage $mnt
- done
- dr ionice -c 3 btrfs balance start -musage=0 $mnt
- for usage in $musage; do
- dr ionice -c 3 btrfs balance start -musage=$usage $mnt
- done
- fi
date=
scrub_status=$(btrfs scrub status $mnt)
if printf "%s\n" "$scrub_status" | grep -i '^status:[[:space:]]*finished$' &>/dev/null; then
sed -rn 's/^\s*scrub started at (.*) and finished.*/\1/p'
)
fi
- if ! $force && [[ $date ]]; then
+ if [[ $date ]]; then
if $dry_run; then
echo "$0: last scrub finish for $mnt: $date"
fi
# We normally only do one disk since this is meant to be run in
# downtime and if we try to do all disks, we invariably end up doing
-xc # a scrub after downtime. So, just do one disk per day.
+ # a scrub after downtime. So, just do one disk per day.
if ! $force; then
return 0
fi
# ref: https://support.system76.com/articles/transition-firmware/
#
# to manually get new firmware,
- # system76-firmware-cli schedule --open
- # to see a changelog, cd to
- # /var/cache/system76-firmware-daemon
- # extract the xz files there, one will contain a changelog.
- # then to install an update:
+ # system76-firmware-cli schedule --open. Last time this printed
+ # out a directory with a changelog.
+ #
+ # But in the past, I had to go through files here
+ # /var/cache/system76-firmware-daemon, extracting and inspecting. eg:
+ # mkct; declare -i i=0; for f in /var/cache/system76-firmware-daemon/*; do mkdir $i; m tar -C $i -xf $f || continue; i+=1; done
+ # by the previous command including a changelog.
+ # To install an update:
# s system76-firmware-cli schedule
fi
;;
# nfs server
pi-nostart nfs-kernel-server
+
+# 10g host-to-host net
+
+case $HOSTNAME in
+ kd|frodo)
+ s /a/exe/cedit 10g /etc/hosts <<'EOF'
+10.3.0.2 kdz kdz.b8.nz # kd zoom 10g
+10.3.0.4 frodoz frodoz.b8.nz # frodo zoom
+EOF
+ ;;
+esac
+
+
# todo, this is old, probably needs removing
if [[ $HOSTNAME == tp ]]; then
sd /etc/wireguard/wg0.conf <<EOF