Last active
January 26, 2022 17:08
-
-
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!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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