Skip to content

Instantly share code, notes, and snippets.

@Sheridan
Created July 30, 2019 06:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sheridan/7d2988b3195c6bd766dab61396a4bad1 to your computer and use it in GitHub Desktop.
Save Sheridan/7d2988b3195c6bd766dab61396a4bad1 to your computer and use it in GitHub Desktop.
pacemaker/corosync alert helper
#!/bin/bash
log_file="/var/log/hacluster/alerts.log"
flags_dir="/var/lib/hacluster"
echo "--[${CRM_alert_timestamp}]--" >> ${log_file}.debug
env | grep "CRM_alert" >> ${log_file}.debug
echo "----" >> ${log_file}.debug
function to_log()
{
what=$1
echo "[${CRM_alert_timestamp}] ${what}" >> ${log_file}
}
function execute()
{
command=$1
to_log "Executing [${command}]: "
{ time $command ; } >> ${log_file} 2>&1
to_log "Executing done"
}
function set_flag()
{
flag=$1
touch ${flags_dir}/${flag}
}
function remove_flag()
{
flag=$1
rm -f ${flags_dir}/${flag}
}
function flag_exists()
{
flag=$1
if [ -f "${flags_dir}/${flag}" ]
then
return 0
fi
return 1
}
function process_kinds()
{
case ${CRM_alert_kind} in
"node")
process_kind_node
;;
"resource")
process_kind_resource
;;
esac
}
function process_kind_node()
{
to_log "Node '${CRM_alert_node}' is now '${CRM_alert_desc}'"
}
function process_kind_resource()
{
case ${CRM_alert_rsc} in
"p_postgresql")
process_p_postgresql_tasks
;;
esac
}
function process_p_postgresql_tasks()
{
case ${CRM_alert_task} in
"monitor")
case ${CRM_alert_desc} in
"Cancelled") ;;
"not running"|"unknown error")
set_flag "postgresql_not_running"
to_log "PostgreSQL not running on '${CRM_alert_node}'. Ressurect sheduled."
;;
esac
;;
"stop")
if flag_exists "postgresql_not_running"
then
to_log "Ressurect PostgreSQL on '${CRM_alert_node}'."
execute "pcs resource cleanup p_postgresql --node=${CRM_alert_node}"
remove_flag "postgresql_not_running"
fi
;;
esac
}
process_kinds
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment