From ea5a5060d0a1d50aa694f03c708bc965ab7a75ae Mon Sep 17 00:00:00 2001 From: Ian Kelling Date: Tue, 1 Dec 2020 22:28:43 -0500 Subject: [PATCH] hopefully fix sm pull --- brc2 | 43 +++++++++++-------- .../etc/systemd/system/vpn-static-ip@.service | 2 +- mail-setup | 19 ++++---- switch-mail-host | 17 ++++---- 4 files changed, 45 insertions(+), 36 deletions(-) diff --git a/brc2 b/brc2 index d505e90..c767f30 100644 --- a/brc2 +++ b/brc2 @@ -248,7 +248,9 @@ bbk() { # btrbk wrapper fi # run latest install-my-scripts - jrun -p btrbk btrbk-run "$@" + # todo: consider changing this to srun and having the args come + # from a file like /etc/default/btrbk, like is done in exim + jrun btrbk-run "$@" if $active; then if (( ret )); then echo bbk: WARNING: btrbk.timer not restarted due to failure @@ -270,43 +272,50 @@ nnn() { /a/opt/nnn -H "$@"; } jrun() { # journal run. run args, log to journal, tail and grep the journal. # Note, an alternative without systemd would be something like ts. - # Note: I tried doing cmd | pee "sudo systemd-cat" cat, but that - # had some problems like ctrl-c didnt work or something. - local pattern sedscript cmd_name + # Note, I tried using systemd-cat, but this seems obviously better, + # and that seemed to have a problem exiting during a systemctl daemon-reload + local cmd_name ret jr_pid ret=0 - case $1 in - -p) - pattern="$2|" - shift 2 - ;; - esac cmd_name=${1##*/} - sedscript="/$pattern$cmd_name/p;/^.{16}[^ ]+ $cmd_name\[[0-9]+]: ([^ ]*\/)?$cmd_name: exiting with status [0-9]+\$/q" + cmd=$1 + if [[ $cmd != /* ]]; then + cmd=$(which $1) + fi # We use >() so that $! is the pid of journalctl, otherwise its the sed pid and then # if we kill that, it takes journalctl about 10 seconds to catch up, and we get # an annoying message about job finishing then. - journalctl -qn2 -f &> >(sed -nr "$sedscript") & + journalctl -qn2 -f -u "$cmd_name" & # We kill this in prompt-command for the case that we ctrl-c the # systemd-cat. i dont know any way to trap ctrl-c and still run the # normal action for it. There might be a way, unsure. jr_pid=$! - systemd-cat -t "$cmd_name" "$@" || ret=$? - if (( ret )); then - echo "jrun: ERROR: $* returned $ret" - fi + systemd-run --unit "$cmd_name" --wait --collect "$cmd" "${@:2}" || ret=$ # This justs lets the journal output its last line # before the prompt comes up. sleep .5 kill $jr_pid &>/dev/null ||: unset jr_pid fg &>/dev/null ||: + return $ret +} +# service run, and watch the output +srun() { + local unit + ret=0 + unit=$1 + journalctl -qn2 -f -u $unit & + systemctl start $unit + sleep .5 + kill $jr_pid &>/dev/null ||: + unset jr_pid + fg &>/dev/null ||: } sm() { c / # run latest install-my-scripts - jrun -p btrbk switch-mail-host "$@" + jrun switch-mail-host "$@" return $ret } diff --git a/filesystem/etc/systemd/system/vpn-static-ip@.service b/filesystem/etc/systemd/system/vpn-static-ip@.service index b677e7c..50b015e 100644 --- a/filesystem/etc/systemd/system/vpn-static-ip@.service +++ b/filesystem/etc/systemd/system/vpn-static-ip@.service @@ -1,6 +1,6 @@ [Unit] Description=vpn-static-ip -After=syslog.target network-online.target vpn-static-ip@%i.service +After=syslog.target network-online.target Wants=network-online.target [Service] diff --git a/mail-setup b/mail-setup index e0aa6aa..93bd990 100755 --- a/mail-setup +++ b/mail-setup @@ -3,18 +3,10 @@ # Copyright (C) 2019 Ian Kelling # SPDX-License-Identifier: AGPL-3.0-or-later -# todo: sm pull really needs to execute as systemd else it will always fail -# because of journal reload - # todo setup better backup/sync of MAIL_HOST emails # todo: reinstall bk with bigger filesystem -# fix so i dont have to do this every reboot: -# /a/f/ans A D PANIC! $ s mkdir /var/run/clamav -# -#/a/f/ans A D PANIC! $ s chown clamav /var/run/clamav - # todo: monitor for msft unblock, and then remove on bk: # /etc/exim4/conf.d/router/190_msft # dnslookup_msft @@ -369,7 +361,6 @@ pi-nostart exim4 exim4-daemon-heavy spamassassin openvpn unbound # note: pyzor debian readme says you need to run some initialization command # but its outdated. -m usermod -a -G Debian-exim clamav soff openvpn @@ -436,6 +427,16 @@ i /etc/default/postgrey <<'EOF' POSTGREY_OPTS="--exim --unix=/var/run/postgrey/postgrey.sock --retry-window=4 --max-age=60" EOF +# * clamav + +m usermod -a -G Debian-exim clamav + +i /etc/systemd/system/clamav-daemon.service.d/fix.conf <&2; } -mexit() { echo "$pre exiting with status $1"; exit $1; } ##### begin command line parsing ######## @@ -55,7 +54,7 @@ while true; do -o) mp_args="-m /o"; shift ;; -h|--help) usage ;; --) shift; break ;; - *) echo "$0: Internal error! unexpected args: $*" ; mexit 1 ;; + *) echo "$0: Internal error! unexpected args: $*" ; exit 1 ;; esac done @@ -64,7 +63,7 @@ done if [[ ! $HOSTNAME ]]; then err "\$HOSTNAME is unset" - mexit 1 + exit 1 fi case $1 in @@ -87,7 +86,7 @@ case $1 in ;; *) err invalid first argument - mexit 1 + exit 1 ;; esac @@ -95,12 +94,12 @@ source /a/bin/bash_unpublished/source-state if [[ $old_hostname != "$MAIL_HOST" ]] && ! $force; then err "\$old_hostname($old_hostname) != \$MAIL_HOST($MAIL_HOST). Rerun with --force if you really want this." - mexit 1 + exit 1 fi if [[ ! $new_host || ! $old_host ]]; then echo "$0: bad args. see script" - mexit 1 + exit 1 fi @@ -164,7 +163,7 @@ e Running initial btrbk if ! m btrbk-run -v $bbk_args $incremental_arg $mp_args; then ret=$? err "failed initial btrbk" - mexit $ret + exit $ret fi m $old_shell /a/exe/primary-setup $new_hostname @@ -175,9 +174,9 @@ if (( ret )); then bang="$(printf "$(tput setaf 5)█$(tput sgr0)%.0s" 1 2 3 4 5 6 7)" e $bang failed btrbk of /o. restoring old host as primary m $old_shell /a/exe/primary-setup localhost - mexit $ret + exit $ret fi m $new_shell /a/exe/primary-setup localhost -mexit 0 +exit 0 -- 2.30.2