diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2017-03-25 17:16:13 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2017-03-25 17:16:13 +0200 |
commit | 6aead8d49c6aa020ef6630d25f30df9df1ace5d2 (patch) | |
tree | 48cad6fbfa19e0155c1d90ee452ec56c360ef8d9 /buildos | |
parent | 864fc1c2e0597606ec8e2e04ae3150144aa3ed39 (diff) |
Implement buildid monitoring and automatic reboot
Diffstat (limited to 'buildos')
-rwxr-xr-x | buildos | 45 |
1 files changed, 42 insertions, 3 deletions
@@ -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 () # <subject> < <body> { - (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" <<EOF +buildid: $buildid +buildid_url: $buildid_url +EOF while true; do info "monitoring..." - sleep 2 + + sleep 5 + + if [ -n "$buildid_url" ]; then + # Fetch the current id. While normally it will be a TFTP URL, it could also + # be HTTP(S) so we configure sensible behavior for that. + # + if id="$(curl -f -L -s -S "$buildid_url")"; then + if [ "$id" != "$buildid" ]; then + email "rebooting because of new os build" <<EOF +old_buildid: $buildid +new_buildid: $id +EOF + info "new os build ($id), rebooting..." + restart + fi + else + info "unable to fetch $buildid_url, will try again" + fi + fi done |