constantly firing timers cause systemd to think startup never finishes
[distro-setup] / primary-setup
1 #!/bin/bash
2
3 # usage $0 [MAIL_HOST]
4 # setup things which involve being the primary host or not
5
6 source /usr/local/lib/err
7
8 pre="${0##*/}:"
9 m() { printf "$pre %s\n" "$*"; "$@"; }
10 e() { printf "$pre %s\n" "$*"; }
11 err() { echo "[$(date +'%Y-%m-%d %H:%M:%S%z')]: $0: $*" >&2; }
12
13
14 [[ $EUID == 0 ]] || exec sudo -E "${BASH_SOURCE[0]}" "$@"
15
16 if [[ $1 ]]; then
17 new_host=$1
18 if [[ $new_host == localhost ]]; then
19 mailhost_p=1
20 new_host=$HOSTNAME
21 else
22 mailhost_p=0
23 fi
24
25 # https://www.robustperception.io/how-to-have-labels-for-machine-roles
26 dir=/var/lib/prometheus/node-exporter
27 if [[ -e $dir ]]; then
28 cat > $dir/mailhost.prom <<EOF
29 host_role{role="mailhost"} $mailhost_p
30 EOF
31 fi
32
33 m sed -ri "s/MAIL_HOST=.*/MAIL_HOST=$new_host/" /a/bin/bash_unpublished/source-state
34 fi
35 source /a/bin/bash_unpublished/source-state
36
37
38 if dpkg -s rss2email &>/dev/null; then
39 if [[ $HOSTNAME == "$MAIL_HOST" ]]; then
40 # arbtt disabled for now
41 #DISPLAY=:0 arbtt-capture --sample-rate=10 &
42 m systemctl --now enable rss2email.timer
43 # off is in mail-setup. no reason for this to be in the rss2email block.
44 m systemctl --now enable btrbk.timer
45 else
46 m systemctl --now disable btrbk.timer
47
48 m systemctl stop rss2email.service
49 m systemctl --now disable rss2email.timer
50 # arbtt disabled for now
51 # for ((i=0; i<10; i++)); do
52 # killall arbtt-capture || break
53 # sleep 1
54 # if [[ $i == 9 ]]; then
55 # exit 1
56 # fi
57 # done
58 fi
59 fi
60
61 # todo: whats going on here? figure out if this should be removed.
62
63 # if dpkg -s radicale &>/dev/null; then
64 # if [[ $HOSTNAME == "$MAIL_HOST" ]]; then
65 # m systemctl restart radicale
66 # m systemctl enable radicale
67 # if [[ -e /etc/logrotate.d/radicale.disabled ]]; then
68 # m mv /etc/logrotate.d/radicale{.disabled,}
69 # fi
70 # else
71 # m systemctl stop radicale
72 # m systemctl disable radicale
73 # # weekly logrotate tries to restart radicale even if it's a disabled service in flidas.
74 # if [[ -e /etc/logrotate.d/radicale ]]; then
75 # m mv /etc/logrotate.d/radicale{,.disabled}
76 # fi
77 # fi
78 # fi
79
80
81 # todo: this needs to be disabled earlier than primary-setup in switch-mail-host
82
83 # if dpkg -s profile-sync-daemon &>/dev/null; then
84 # if [[ $HOSTNAME == "$MAIL_HOST" ]]; then
85 # m systemctl --user start psd
86 # m systemctl --user enable psd
87 # else
88 # m systemctl --user stop psd
89 # m systemctl --user disable psd
90 # fi
91 # fi
92
93
94 m /a/exe/mail-setup
95 exit 0