improved restart function

This commit is contained in:
Serghey Rodin 2013-10-09 14:11:07 +03:00
commit e7c94357a4
6 changed files with 141 additions and 96 deletions

View file

@ -13,6 +13,18 @@
source $VESTA/func/main.sh
source $VESTA/conf/vesta.conf
send_email_report() {
send_mail="$VESTA/web/inc/mail-wrapper.php"
email=$(grep CONTACT $VESTA/data/users/admin/user.conf)
email=$(echo "$email" | cut -f 2 -d "'")
tmpfile=$(mktemp)
subj="$(hostname): $CRON_SYSTEM restart failed"
/etc/init.d/$CRON_SYSTEM configtest >> $tmpfile 2>&1
/etc/init.d/$CRON_SYSTEM restart >> $tmpfile 2>&1
cat $tmpfile | $send_mail -s "$subj" $email
rm -f $tmpfile
}
#----------------------------------------------------------#
# Action #
@ -28,23 +40,19 @@ if [ -z "$1" ] && [ "$SCHEDULED_RESTART" = 'yes' ]; then
exit
fi
if [ -z "$CRON_SYSTEM" ]; then
exit
fi
# Restart system
if [ ! -z "$CRON_SYSTEM" ]; then
if [ -e "/var/run/crond.pid" ]; then
/etc/init.d/$CRON_SYSTEM reload >/dev/null 2>&1
reload cron >/dev/null 2>&1
else
/etc/init.d/$CRON_SYSTEM restart >/dev/null 2>&1
if [ $? -ne 0 ]; then
/etc/init.d/$CRON_SYSTEM restart >/dev/null 2>&1
if [ $? -ne 0 ]; then
send_mail="$VESTA/web/inc/mail-wrapper.php"
email=$(grep CONTACT $VESTA/data/users/admin/user.conf)
email=$(echo "$email" | cut -f 2 -d "'")
tmpfile=$(mktemp)
subj="$(hostname): $CRON_SYSTEM restart failed"
/etc/init.d/$CRON_SYSTEM configtest >> $tmpfile 2>&1
/etc/init.d/$CRON_SYSTEM restart >> $tmpfile 2>&1
cat $tmpfile | $send_mail -s "$subj" $email
rm -f $tmpfile
exit $E_RESTART
fi
send_email_report
exit $E_RESTART
fi
fi