improvements
authorIan Kelling <ian@iankelling.org>
Tue, 24 Feb 2026 01:07:58 +0000 (20:07 -0500)
committerIan Kelling <ian@iankelling.org>
Tue, 24 Feb 2026 01:07:58 +0000 (20:07 -0500)
brc
btrfsmaint
distro-end
schrootupdate

diff --git a/brc b/brc
index 69994e0c06eec55ad585d733add38ab22d65c653..1793d64fd8fc1cd567b5b6682b2cd74c20ed455d 100644 (file)
--- a/brc
+++ b/brc
@@ -1358,6 +1358,29 @@ dfp() {
   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"
@@ -1562,7 +1585,7 @@ etailbg() {
 
 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 "$@"
 }
@@ -4716,6 +4739,21 @@ dedup-node-modules() {
   #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.
index bad4df8c54b11d231db45af5b50b23ae0c65f9e2..8f56e4c8e92d96668ad9d6eaf57343f6db621ca8 100755 (executable)
@@ -42,8 +42,6 @@ EOF
   }
 fi
 
-dusage="5 10"
-musage="5"
 
 check-idle() {
   type -p xscreensaver-command &>/dev/null || return 0
@@ -62,19 +60,8 @@ usage() {
 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
 
@@ -90,19 +77,13 @@ EOF
 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 ;;
@@ -113,6 +94,32 @@ readonly check dry_run force stats
 ##### 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
@@ -139,7 +146,7 @@ main() {
     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
@@ -164,38 +171,11 @@ EOF
       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
@@ -208,7 +188,7 @@ EOF
           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
@@ -228,7 +208,7 @@ EOF
 
     # 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
index 5e8e366e5cd8b6c0c2b24228ad47595e9e9f3625..9d06ff06bad3005d78fd3d7ea7d9aa0473447def 100755 (executable)
@@ -692,11 +692,14 @@ EOF
       # 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
     ;;
@@ -2180,6 +2183,19 @@ esac
 # 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
index 2692c2e11b613a0d2972e337edba01916b915952..48539d8e3c0f48ed28525060f96f8490f3b8f03a 100755 (executable)
@@ -33,6 +33,13 @@ if [[ -e /etc/schroot/chroot.d/$n.conf ]]; then
   cd /
   schroot -c $n -- apt-get -y update
   schroot -c $n -- apt-get -y dist-upgrade --purge --auto-remove
+
+  # I dunno why I get leftover schroot sessions or whether it happens
+  # here, but remove any here.
+  sessions=$(schroot -l --all-sessions | grep "^session:${n}-" | sed 's/session://')
+  for session in $sessions; do
+    schroot -e -c $session
+  done
 fi
 #done