<commit_before>#!/usr/bin/env bash
set -u

ICINGA_URL='https://nagios.cluster/cgi-bin/icinga/status.cgi?search_string=%5E<%= @node_class_search_phrase %>-[0-9]&allunhandledproblems&jsonoutput'

# Release the lock if this machine has it.
if /usr/bin/locksmithctl -endpoint='<%= @etcd_endpoints.join(',') %>' status | grep -q '<%= @fqdn %>'
then
  /usr/bin/locksmithctl -endpoint='<%= @etcd_endpoints.join(',') %>' unlock '<%= @fqdn %>'
fi

if ! [ -f /var/run/reboot-required ]; then
  # No reboot required
  exit 0
fi

# Check that this machine is safe to reboot
if ! [[ "$(/usr/local/bin/govuk_setenv default /usr/bin/printenv SAFE_TO_REBOOT)" =~ ^(yes|overnight)$ ]]; then
  # Machine marked as not safe to reboot
  exit 0
fi

# Check for 'down' and 'unreachable' host alerts; 'critical' and 'warning' service alerts

/usr/local/bin/check_icinga $ICINGA_URL

if [ $? -ne 0 ]; then
  echo 'Host or service alerts exist for node class, or Icinga unavailable'
  exit 1
fi

/usr/bin/locksmithctl -endpoint='<%= @etcd_endpoints.join(',') %>' lock '<%= @fqdn %>'

if [ $? -ne 0 ]; then
  echo "Couldn't obtain lock"
  exit 1
fi

/sbin/reboot

if [ $? -ne 0 ]; then
  echo 'Reboot failed'
  exit 1
fi
<commit_msg>Simplify logic when removing reboot lock<commit_after>#!/usr/bin/env bash
set -u

ICINGA_URL='https://nagios.cluster/cgi-bin/icinga/status.cgi?search_string=%5E<%= @node_class_search_phrase %>-[0-9]&allunhandledproblems&jsonoutput'

# Release the lock if this machine has it.
/usr/bin/locksmithctl -endpoint='<%= @etcd_endpoints.join(',') %>' unlock '<%= @fqdn %>'

if ! [ -f /var/run/reboot-required ]; then
  # No reboot required
  exit 0
fi

# Check that this machine is safe to reboot
if ! [[ "$(/usr/local/bin/govuk_setenv default /usr/bin/printenv SAFE_TO_REBOOT)" =~ ^(yes|overnight)$ ]]; then
  # Machine marked as not safe to reboot
  exit 0
fi

# Check for 'down' and 'unreachable' host alerts; 'critical' and 'warning' service alerts

/usr/local/bin/check_icinga $ICINGA_URL

if [ $? -ne 0 ]; then
  echo 'Host or service alerts exist for node class, or Icinga unavailable'
  exit 1
fi

/usr/bin/locksmithctl -endpoint='<%= @etcd_endpoints.join(',') %>' lock '<%= @fqdn %>'

if [ $? -ne 0 ]; then
  echo "Couldn't obtain lock"
  exit 1
fi

/sbin/reboot

if [ $? -ne 0 ]; then
  echo 'Reboot failed'
  exit 1
fi

{'fraction_non_alphanumeric': 0.1601545727780163, 'fraction_numerical': 0.009446114212108201, 'mean_word_length': 4.0, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3834092', 'n_tokens_mistral': 936, 'n_tokens_neox': 873, 'n_words': 245}