From 2a377049b7af36c332c83ce3dc2f3187705a462c Mon Sep 17 00:00:00 2001 From: Ian Kelling Date: Tue, 29 Dec 2020 18:12:43 -0500 Subject: [PATCH] various fixes --- brc | 37 ++++++++++++++++++++++++++++--------- check-subvol-stale | 2 +- distro-begin | 3 +++ mail-setup | 28 +++++++++++++++------------- mailtest-check | 2 ++ mount-latest-subvol | 6 ++++-- primary-setup | 4 ++++ system-status | 6 +++++- 8 files changed, 62 insertions(+), 26 deletions(-) diff --git a/brc b/brc index b2eac3f..5579fc4 100644 --- a/brc +++ b/brc @@ -636,10 +636,11 @@ eless() { ccomp less eless eqcat() { exiqgrep -i | while read -r i; do - m exim -Mvh $i - m exim -Mvb $i - hr - m exigrep $i /var/log/exim4/mainlog | cat ||: + hlm exim -Mvh $i + echo + hlm exim -Mvb $i + echo + hlm exigrep $i /var/log/exim4/mainlog | cat ||: done } @@ -840,6 +841,20 @@ hr() { # horizontal row. used to break up output printf "$(tput setaf 5 2>/dev/null ||:)█$(tput sgr0 2>/dev/null||:)%.0s" $(eval echo "{1..${COLUMNS:-60}}") echo } +# highlight +hl() { + local col input_len=0 + for arg; do + input_len=$((input_len + 1 + ${#arg})) + done + col=$((60 - input_len)) + printf "\e[1;97;41m%s" "$*" + if (( col > 0 )); then + printf "\e[1;97;41m \e[0m%.0s" $(eval echo "{1..${col}}") + fi + echo +} +hlm() { hl "$*"; "$@"; } hrcat() { local f; for f; do [[ -f $f ]] || continue; hr; echo "$f"; cat "$f"; done } @@ -1275,10 +1290,14 @@ sgo() { # service go ser enable $service fi } -soff() { # service go - service=$1 - ser stop $service - ser disable $service +soff () { + for service; do + # ignore services that dont exist + if systemctl cat $service &>/dev/null; then + ser stop $service; + ser disable $service + fi + done } sgu() { @@ -1478,7 +1497,7 @@ sl() { if $haveinfo && [[ $type == b ]]; then info_sec=${tmp::10} - read files_sec _ < <(find -L $SL_FILES_DIR -printf "%T@ %p\n" | sort -nr || [[ $? == 141 ]]) + read files_sec _ < <(find -L $SL_FILES_DIR -printf "%T@ %p\n" | sort -nr || [[ $? == 141 || ${PIPESTATUS[0]} == 32 ]] ) files_sec=${files_sec%%.*} if (( files_sec > info_sec )); then dorsync=true diff --git a/check-subvol-stale b/check-subvol-stale index 4f489e7..8453026 100644 --- a/check-subvol-stale +++ b/check-subvol-stale @@ -137,7 +137,7 @@ for d; do unix_time=$(date -d $(sed -r 's/(.{4})(..)(.{5})(..)(.*)/\1-\2-\3:\4:\5/' <<<${f#$vol.}) +%s) printf "%s %s\n" $unix_time $s # sort will fail - done | sort -r | head -n 1 | awk '{print $2}' || [[ ${PIPESTATUS[1]} == 141 ]] + done | sort -r | head -n 1 | awk '{print $2}' || [[ ${PIPESTATUS[1]} == 141 || ${PIPESTATUS[0]} == 32 ]] ) if [[ ! $last_snap ]]; then # should not happen. diff --git a/distro-begin b/distro-begin index 0950719..1f1d7bc 100755 --- a/distro-begin +++ b/distro-begin @@ -334,6 +334,9 @@ if dpkg -s -- nscd &>/dev/null; then sudo systemctl stop nscd ||: # fails if already stopped fi +# http://strugglers.net/~andy/blog/2020/12/03/starting-services-only-when-the-network-is-ready-on-debiansystemd/ +systemctl enable ifupdown-wait-online.service + if bitfolk; then # remove line like this: 85.119.82.128 je.iankelling.org je # it messes with hostname -f. diff --git a/mail-setup b/mail-setup index 57cc43e..8dc41f0 100755 --- a/mail-setup +++ b/mail-setup @@ -3,6 +3,11 @@ # Copyright (C) 2019 Ian Kelling # SPDX-License-Identifier: AGPL-3.0-or-later +# todo: run mailping test after running, or otherwise +# clear out terminal alert + +# todo: in err can we print out variables? + # todo setup better backup/sync of MAIL_HOST emails # todo: reinstall bk with bigger filesystem @@ -262,7 +267,7 @@ fi pre="${0##*/}:" m() { printf "$pre %s\n" "$*"; "$@"; } e() { printf "$pre %s\n" "$*"; } -err() { echo "[$(date +'%Y-%m-%d %H:%M:%S%z')]: $0: $*" >&2; exit 1; } +err() { printf "$pre %s\n" "$*" >&2; exit 1; } reload=false i() { # install file local tmp tmpdir dest="$1" @@ -506,7 +511,7 @@ StartLimitIntervalSec=0 [Service] -Type=oneshot +Type=simple RemainAfterExit=true PrivateNetwork=true ExecStart=/usr/bin/flock -w 20 /tmp/newns.flock /a/bin/newns/newns -n 10.173.8 start mail @@ -529,9 +534,7 @@ Wants=network-online.target [Service] Type=simple PrivateNetwork=true -ExecStartPre=/usr/bin/flock -w 20 /tmp/newns.flock /a/bin/newns/newns -n 10.173.8 start mail ExecStart=/bin/sleep infinity -ExecStopPost=/usr/bin/flock -w 20 /tmp/newns.flock /a/bin/newns/newns stop mail [Install] WantedBy=multi-user.target @@ -594,6 +597,7 @@ case $HOSTNAME in $MAIL_HOST) i /etc/systemd/system/unbound.service.d/nn.conf <$rcdir/config/secret || [[ $? == 141 ]] + base64 $rcdir/config/secret || [[ $? == 141 || ${PIPESTATUS[0]} == 32 ]] fi secret=$(cat $rcdir/config/secret) @@ -1816,7 +1819,7 @@ EOF \$CONFIG['htaccess.RewriteBase'] = '/nextcloud'; \$CONFIG['trusted_domains'] = array ( 0 => '$domain', - ); + );s #\$CONFIG[''] = ''; fwrite(STDOUT, ">/etc/exim4/update-exim4.conf.conf < $tmp || [[ $? == 141 ]] + # in testing, same subvol is 136 bytes. allow some overhead. 32 happens sometimes under systemd. + # $ errno 32 + # EPIPE 32 Broken pipe + btrfs send --no-data -p $bsub $leaf | head -c 1000 > $tmp || [[ $? == 141 || ${PIPESTATUS[0]} == 32 ]] if (( $(stat -c%s $tmp) < 1000)); then # example output for an empty diff: # Found a valid Btrfs stream header, version 1 diff --git a/primary-setup b/primary-setup index 9894f3f..6b294ab 100755 --- a/primary-setup +++ b/primary-setup @@ -68,9 +68,13 @@ fi # fi if [[ $HOSTNAME == "$MAIL_HOST" ]]; then + m sudo systemctl --user start psd + m sudo systemctl --user enable psd m sudo systemctl start openvpn-client@hole m sudo systemctl enable openvpn-client@hole else + m sudo systemctl --user stop psd + m sudo systemctl --user disable psd m sudo systemctl stop openvpn-client@hole m sudo systemctl disable openvpn-client@hole fi diff --git a/system-status b/system-status index eaf3599..1167bfd 100644 --- a/system-status +++ b/system-status @@ -215,8 +215,12 @@ write-status() { # allow failure in case there are no snapshots yet. # shellcheck disable=SC2012 shopt -u nullglob - snaps=($(ls -1avdr /mnt/root/btrbk/$vol.20* 2>/dev/null |head -n1 || : )) + files=(/mnt/root/btrbk/$vol.20*) shopt -s nullglob + snaps=() + if (( ${#files[@]} )); then + snaps=($(ls -1avdr "${files[@]}" 2>/dev/null |head -n1 || : )) + fi now=$(date +%s) maxtime=0 for s in ${snaps[@]}; do -- 2.30.2