From 6aead8d49c6aa020ef6630d25f30df9df1ace5d2 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sat, 25 Mar 2017 17:16:13 +0200 Subject: Implement buildid monitoring and automatic reboot --- buildos | 45 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 3 deletions(-) (limited to 'buildos') diff --git a/buildos b/buildos index fd0f8c2..9a0224a 100755 --- a/buildos +++ b/buildos @@ -63,14 +63,53 @@ for v in "${cmdline[@]}"; do fi done +hname="$(hostname)" + +# Get the build id. +# +buildid="$(sed -n -re 's/^BUILD_ID="(.+)"$/\1/p' /etc/os-release)" + function email () # < { - (echo -e "Subject: $1\n"; cat -) | sendmail -i "$admin_email" + (echo -e "Subject: [$hname] $1\n"; cat -) | sendmail -i "$admin_email" +} + +function restart () +{ + sendmail -q # Flush mail queue. + sleep 10 # Give any remaining mail chance to go through. + sudo systemctl reboot } -email "starting buildos monitor on $(hostname)" <<<"" +if [ -z "$buildid_url" ]; then + info "no buildos.buildid_url specified, not monitoring for new os builds" +fi + +email "starting buildos monitor" <