hopefully fix sm pull
authorIan Kelling <ian@iankelling.org>
Wed, 2 Dec 2020 03:28:43 +0000 (22:28 -0500)
committerIan Kelling <ian@iankelling.org>
Wed, 2 Dec 2020 03:28:43 +0000 (22:28 -0500)
brc2
filesystem/etc/systemd/system/vpn-static-ip@.service
mail-setup
switch-mail-host

diff --git a/brc2 b/brc2
index d505e90d20ea8f9debd14441d4fcc52ff023ab02..c767f309ea84cecc324ea6fe02c6e9c244407aec 100644 (file)
--- 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
 }
 
index b677e7cf6ba2271f9a93bf11094c0307b3b6a55d..50b015e7231d424ed9cc30fed4258b41c9bc59a5 100644 (file)
@@ -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]
index e0aa6aadcf8b08ce620a099c6f43ebaef12d71c5..93bd990d4ac6b9bb253757fd54c267cf2deb0505 100755 (executable)
@@ -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 <<EOF
+[Service]
+ExecStartPre=-/bin/mkdir /var/run/clamav
+ExecStartPre=/bin/chown clamav /var/run/clamav
+EOF
+
 # * mail vpn config
 
 
index 88f9d8f66fa4c5b6f2922514e65a43099eecd4ed..cdbeddc0a58c6c36eb726f0bb45fba5a2a4fa1ce 100644 (file)
@@ -40,7 +40,6 @@ pre="${0##*/}:"
 m() { printf "$pre %s\n"  "$*"; "$@"; }
 e() { printf "$pre %s\n"  "$*"; }
 err() { echo "$pre ERROR: $*" >&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