4 # setup things which involve being the primary host or not
6 source /usr
/local
/lib
/err
8 script_name
="${BASH_SOURCE[0]}"
9 script_name
="${script_name##*/}"
10 pre
="${SSH_CLIENT:+$HOSTNAME} $script_name:"
11 m
() { printf "$pre %s\n" "$*"; "$@"; }
12 e
() { printf "$pre %s\n" "$*"; }
13 err
() { echo "[$(date +'%Y-%m-%d %H:%M:%S%z')]: $0: $*" >&2; }
16 local service
=${@: -1}
17 if [[ ! -s /etc
/systemd
/system
/$service ]]; then
23 [[ $EUID == 0 ]] ||
exec sudo
-E "${BASH_SOURCE[0]}" "$@"
27 if [[ $new_host == localhost
]]; then
34 # https://www.robustperception.io/how-to-have-labels-for-machine-roles
35 dir
=/var
/lib
/prometheus
/node-exporter
36 if [[ -e $dir ]]; then
37 cat > $dir/mailhost.prom
<<EOF
38 host_role{role="mailhost"} $mailhost_p
42 m
sed -ri "s/MAIL_HOST=.*/MAIL_HOST=$new_host/" /a
/bin
/bash_unpublished
/source-state
44 source /a
/bin
/bash_unpublished
/source-state
46 # fixing up a bad state that servers got in.
47 if [[ -e /dev
/shm
/iank-status
]]; then
48 chown iank.iank
/dev
/shm
/iank-status
52 if [[ $HOSTNAME == "$MAIL_HOST" ||
$HOSTNAME == kd
]]; then
53 m systemctl
--now enable btrbk.timer
55 serm systemctl
--now disable btrbk.timer
59 if dpkg
-s rss2email
&>/dev
/null
; then
60 if [[ $HOSTNAME == "$MAIL_HOST" ]]; then
61 # arbtt disabled for now
62 #DISPLAY=:0 arbtt-capture --sample-rate=10 &
63 m systemctl
--now enable rss2email.timer
65 files
=(/sysd-mail-once
/btrbk
*)
66 if (( ${#files[@]} )); then
70 serm systemctl stop rss2email.service
71 serm systemctl
--now disable rss2email.timer
72 # arbtt disabled for now
73 # for ((i=0; i<10; i++)); do
74 # killall arbtt-capture || break
76 # if [[ $i == 9 ]]; then
83 # todo: whats going on here? figure out if this should be removed.
85 # if dpkg -s radicale &>/dev/null; then
86 # if [[ $HOSTNAME == "$MAIL_HOST" ]]; then
87 # m systemctl restart radicale
88 # m systemctl enable radicale
89 # if [[ -e /etc/logrotate.d/radicale.disabled ]]; then
90 # m mv /etc/logrotate.d/radicale{.disabled,}
93 # m systemctl stop radicale
94 # m systemctl disable radicale
95 # # weekly logrotate tries to restart radicale even if it's a disabled service in flidas.
96 # if [[ -e /etc/logrotate.d/radicale ]]; then
97 # m mv /etc/logrotate.d/radicale{,.disabled}
103 # todo: this needs to be disabled earlier than primary-setup in switch-mail-host
105 # if dpkg -s profile-sync-daemon &>/dev/null; then
106 # if [[ $HOSTNAME == "$MAIL_HOST" ]]; then
107 # m systemctl --user start psd
108 # m systemctl --user enable psd
110 # m systemctl --user stop psd
111 # m systemctl --user disable psd