From e7c94357a4778fcc806430838f04f6a270fa7bff Mon Sep 17 00:00:00 2001 From: Serghey Rodin Date: Wed, 9 Oct 2013 14:11:07 +0300 Subject: [PATCH] improved restart function --- bin/v-restart-cron | 36 +++++++++++++++++++------------- bin/v-restart-dns | 51 +++++++++++++++++++++++++-------------------- bin/v-restart-ftp | 37 +++++++++++++++++--------------- bin/v-restart-mail | 38 ++++++++++++++++++--------------- bin/v-restart-proxy | 36 +++++++++++++++++++------------- bin/v-restart-web | 39 +++++++++++++++++++++++++--------- 6 files changed, 141 insertions(+), 96 deletions(-) diff --git a/bin/v-restart-cron b/bin/v-restart-cron index 03e2f9aa7..04b7dd6a0 100755 --- a/bin/v-restart-cron +++ b/bin/v-restart-cron @@ -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 diff --git a/bin/v-restart-dns b/bin/v-restart-dns index 1bebb6d42..67025040a 100755 --- a/bin/v-restart-dns +++ b/bin/v-restart-dns @@ -13,6 +13,24 @@ source $VESTA/func/main.sh source $VESTA/conf/vesta.conf +send_email_report() { + if [ -e '/etc/named.conf' ]; then + dns_conf='/etc/named.conf' + else + dns_conf='/etc/bind/named.conf' + fi + + 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): $DNS_SYSTEM restart failed" + named-checkconf $dns_conf >> $tmpfile 2>&1 + /etc/init.d/$DNS_SYSTEM restart >> $tmpfile 2>&1 + cat $tmpfile | $send_mail -s "$subj" $email + rm -f $tmpfile +} + #----------------------------------------------------------# # Action # @@ -28,30 +46,17 @@ if [ -z "$1" ] && [ "$SCHEDULED_RESTART" = 'yes' ]; then exit fi -# Restart system -if [ ! -z "$DNS_SYSTEM" ]; then - /etc/init.d/$DNS_SYSTEM reload >/dev/null 2>&1 - if [ $? -ne 0 ]; then - /etc/init.d/$DNS_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): $DNS_SYSTEM restart failed" +if [ -z "$DNS_SYSTEM" ]; then + exit +fi - # Get dns config path - if [ -e '/etc/named.conf' ]; then - dns_conf='/etc/named.conf' - else - dns_conf='/etc/bind/named.conf' - fi - named-checkconf $dns_conf >> $tmpfile 2>&1 - /etc/init.d/$DNS_SYSTEM restart >> $tmpfile 2>&1 - cat $tmpfile | $send_mail -s "$subj" $email - rm -f $tmpfile - exit $E_RESTART - fi +# Restart system +/etc/init.d/$DNS_SYSTEM reload >/dev/null 2>&1 +if [ $? -ne 0 ]; then + /etc/init.d/$DNS_SYSTEM restart >/dev/null 2>&1 + if [ $? -ne 0 ]; then + send_email_report + exit $E_RESTART fi fi diff --git a/bin/v-restart-ftp b/bin/v-restart-ftp index 32454a4cb..7d02b0623 100755 --- a/bin/v-restart-ftp +++ b/bin/v-restart-ftp @@ -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): $FTP_SYSTEM restart failed" + /etc/init.d/$FTP_SYSTEM configtest >> $tmpfile 2>&1 + /etc/init.d/$FTP_SYSTEM restart >> $tmpfile 2>&1 + cat $tmpfile | $send_mail -s "$subj" $email + rm -f $tmpfile +} + #----------------------------------------------------------# # Action # @@ -28,24 +40,15 @@ if [ -z "$1" ] && [ "$SCHEDULED_RESTART" = 'yes' ]; then exit fi +if [ -z "$FTP_SYSTEM" ]; then + exit +fi + # Restart system -if [ ! -z "$FTP_SYSTEM" ]; then - /etc/init.d/$FTP_SYSTEM reload >/dev/null 2>&1 - if [ $? -ne 0 ]; then - /etc/init.d/$FTP_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): $FTP_SYSTEM restart failed" - /etc/init.d/$FTP_SYSTEM configtest >> $tmpfile 2>&1 - /etc/init.d/$FTP_SYSTEM restart >> $tmpfile 2>&1 - cat $tmpfile | $send_mail -s "$subj" $email - rm -f $tmpfile - exit $E_RESTART - fi - fi +/etc/init.d/$FTP_SYSTEM restart >/dev/null 2>&1 +if [ $? -ne 0 ]; then + send_email_report + exit $E_RESTART fi # Update restart queue diff --git a/bin/v-restart-mail b/bin/v-restart-mail index 96d601e57..2247e1200 100755 --- a/bin/v-restart-mail +++ b/bin/v-restart-mail @@ -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): $MAIL_SYSTEM restart failed" + /etc/init.d/$MAIL_SYSTEM configtest >> $tmpfile 2>&1 + /etc/init.d/$MAIL_SYSTEM restart >> $tmpfile 2>&1 + cat $tmpfile | $send_mail -s "$subj" $email + rm -f $tmpfile +} + #----------------------------------------------------------# # Action # @@ -28,24 +40,16 @@ if [ -z "$1" ] && [ "$SCHEDULED_RESTART" = 'yes' ]; then exit fi + +if [ -z "$MAIL_SYSTEM" ]; then + exit +fi + # Restart system -if [ ! -z "$MAIL_SYSTEM" ]; then - /etc/init.d/$MAIL_SYSTEM reload >/dev/null 2>&1 - if [ $? -ne 0 ]; then - /etc/init.d/$MAIL_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): $MAIL_SYSTEM restart failed" - /etc/init.d/$MAIL_SYSTEM configtest >> $tmpfile 2>&1 - /etc/init.d/$MAIL_SYSTEM restart >> $tmpfile 2>&1 - cat $tmpfile | $send_mail -s "$subj" $email - rm -f $tmpfile - exit $E_RESTART - fi - fi +/etc/init.d/$MAIL_SYSTEM restart >/dev/null 2>&1 +if [ $? -ne 0 ]; then + send_email_report + exit $E_RESTART fi # Update restart queue diff --git a/bin/v-restart-proxy b/bin/v-restart-proxy index e66c80679..c13072a28 100755 --- a/bin/v-restart-proxy +++ b/bin/v-restart-proxy @@ -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): $PROXY_SYSTEM restart failed" + /etc/init.d/$PROXY_SYSTEM configtest >> $tmpfile 2>&1 + /etc/init.d/$PROXY_SYSTEM restart >> $tmpfile 2>&1 + cat $tmpfile | $send_mail -s "$subj" $email + rm -f $tmpfile +} + #----------------------------------------------------------# # Action # @@ -28,23 +40,17 @@ if [ -z "$1" ] && [ "$SCHEDULED_RESTART" = 'yes' ]; then exit fi +if [ -z "$PROXY_SYSTEM" ]; then + exit +fi + # Restart system -if [ ! -z "$PROXY_SYSTEM" ]; then - /etc/init.d/$PROXY_SYSTEM reload >/dev/null 2>&1 +/etc/init.d/$PROXY_SYSTEM reload >/dev/null 2>&1 +if [ $? -ne 0 ]; then + /etc/init.d/$PROXY_SYSTEM restart >/dev/null 2>&1 if [ $? -ne 0 ]; then - /etc/init.d/$PROXY_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): $PROXY_SYSTEM restart failed" - /etc/init.d/$PROXY_SYSTEM configtest >> $tmpfile 2>&1 - /etc/init.d/$PROXY_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 diff --git a/bin/v-restart-web b/bin/v-restart-web index 5a4188ecd..568db9fbb 100755 --- a/bin/v-restart-web +++ b/bin/v-restart-web @@ -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): $WEB_SYSTEM restart failed" + /etc/init.d/$WEB_SYSTEM configtest >> $tmpfile 2>&1 + /etc/init.d/$WEB_SYSTEM restart >> $tmpfile 2>&1 + cat $tmpfile | $send_mail -s "$subj" $email + rm -f $tmpfile +} + #----------------------------------------------------------# # Action # @@ -28,21 +40,28 @@ if [ -z "$1" ] && [ "$SCHEDULED_RESTART" = 'yes' ]; then exit fi + +if [ -z "$WEB_SYSTEM" ]; then + exit +fi + # Restart system -if [ ! -z "$WEB_SYSTEM" ]; then +if [ "$WEB_SYSTEM" == 'apache2' ]; then + if [ -e "/var/run/apache2.pid" ]; then + /etc/init.d/$WEB_SYSTEM reload >/dev/null 2>&1 + else + /etc/init.d/$WEB_SYSTEM restart >/dev/null 2>&1 + if [ $? -ne 0 ]; then + send_email_report + exit $E_RESTART + fi + fi +else /etc/init.d/$WEB_SYSTEM reload >/dev/null 2>&1 if [ "$?" -ne 0 ]; then /etc/init.d/$WEB_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): $WEB_SYSTEM restart failed" - /etc/init.d/$WEB_SYSTEM configtest >> $tmpfile 2>&1 - /etc/init.d/$WEB_SYSTEM restart >> $tmpfile 2>&1 - cat $tmpfile | $send_mail -s "$subj" $email - rm -f $tmpfile + send_email_report exit $E_RESTART fi fi