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
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
}
[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]
# 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
# note: pyzor debian readme says you need to run some initialization command
# but its outdated.
-m usermod -a -G Debian-exim clamav
soff openvpn
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
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 ########
-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
if [[ ! $HOSTNAME ]]; then
err "\$HOSTNAME is unset"
- mexit 1
+ exit 1
fi
case $1 in
;;
*)
err invalid first argument
- mexit 1
+ exit 1
;;
esac
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
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
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