master: Add flushing changes to shadows/metaloggers on exit

This commit ensures that all the changelogs are written to shadow
masters (and metaloggers) before the active master exits after receiving
SIGTERM. New connections from shadows and metaloggers are no longer
accepted in such a situation to avoid blocking the termination forever.

Change-Id: I836c1f19151849b38073bb989d5bcae49442bf40