Skip to content

Instantly share code, notes, and snippets.

@jogerj
Last active January 26, 2022 17:08
Show Gist options
  • Save jogerj/d444b615fe91f6593dd44aff91e8f8ba to your computer and use it in GitHub Desktop.
Save jogerj/d444b615fe91f6593dd44aff91e8f8ba to your computer and use it in GitHub Desktop.
Auto restart zimbra if something stops working, because some zimbra services likes to stop working randomly. Prevent consecutive restart if last restart didn't fix the problem. Also send a Pushbullet notification on restart. Best to pair this script with crontab!
#!/bin/bash
check=$(su - zimbra -c 'zmcontrol status' | grep Stopped)
fixes_dir="/root"
# run as root only! make sure chmod 500 to keep secret!
access_token="PUSHBULLET_API_TOKEN"
pushbullet () {
msg="$(date -R)\n${2}"
title="${1}"
curl --ssl-reqd -s -o /dev/null --header "Access-Token: ${access_token}" --header 'Content-Type: application/json' --data-binary "{\"body\":\"${msg}\",\"title\":\"${title}\",\"type\":\"note\"}" --request POST https://api.pushbullet.com/v2/pushes
}
if [ "x$check" != "x" ]; then
echo "[INFO] $(date -R) - ${check}" >> $fixes_dir/restarts.log
# check if restarted already
if [ ! -f $fixes_dir/.restarted ]; then
su - zimbra -c "zmcontrol restart";
echo "[INFO] $(date -R) - Restarted" >> $fixes_dir/restarts.log;
touch $fixes_dir/.restarted;
pushbullet "Zimbra Server" "Zimbra was restarted";
else
echo "[ERROR] $(date -R) - Consecutive restart detected! Previous restart did not solve problem" >> $fixes_dir/restarts.log;
pushbullet "Zimbra Server" "Zimbra restart failed to solve problem!"
fi;
else
# all Running
rm -f $fixes_dir/.restarted;
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment