diff --git a/bin/v-add-sys-ip b/bin/v-add-sys-ip index e3e63d5cb..6bb0c6df1 100755 --- a/bin/v-add-sys-ip +++ b/bin/v-add-sys-ip @@ -1,6 +1,6 @@ #!/bin/bash # info: add system ip address -# options: IP NETMASK [INTERFACE] [USER] [STATUS] [NAME] [NAT_IP] +# options: IP NETMASK [INTERFACE] [USER] [IP_STATUS] [IP_NAME] [NAT_IP] # # The function adds ip address into a system. It also creates rc scripts. You # can specify ip name which will be used as root domain for temporary aliases. @@ -34,7 +34,7 @@ source $VESTA/conf/vesta.conf # Verifications # #----------------------------------------------------------# -check_args '2' "$#" 'IP NETMASK [INTERFACE] [USER] [STATUS] [NAME] [NAT_IP]' +check_args '2' "$#" 'IP NETMASK [INTERFACE] [USER] [STATUS] [NAME] [NATED_IP]' validate_format 'ip' 'netmask' 'interface' 'user' 'ip_status' is_ip_free is_object_valid 'user' 'USER' "$user" @@ -50,18 +50,15 @@ fi #----------------------------------------------------------# # Action # #----------------------------------------------------------# - -# Converting netmask to CIDR format and calculating broadcast address +iface=$(get_ip_iface) cidr=$(convert_netmask $netmask) broadcast=$(get_broadcast $ip $netmask) -iface=$(get_ip_iface) -sys_ip_check=$(/sbin/ip addr | grep "$ip/$cidr") +sys_ip_check=$(/sbin/ip addr | grep "$ip") if [ -z "$sys_ip_check" ]; then - - # Adding system ip - /sbin/ip addr add $ip/$cidr broadcast $broadcast \ - dev $interface label $iface + # Adding sys ip + /sbin/ip addr add $ip/$cidr dev $interface \ + broadcast $broadcast label $iface # Adding RHEL/CentOS/Fedora startup script if [ -e "/etc/redhat-release" ]; then @@ -101,14 +98,19 @@ chmod 660 $VESTA/data/ips/$ip # WEB support if [ ! -z "$WEB_SYSTEM" ]; then web_conf="/etc/$WEB_SYSTEM/conf.d/$ip.conf" + rm -f $web_conf if [ "$WEB_SYSTEM" = 'httpd' ] || [ "$WEB_SYSTEM" = 'apache2' ]; then - echo "NameVirtualHost $ip:$WEB_PORT" > $web_conf + if [ -z "$(/usr/sbin/apachectl -v | grep Apache/2.4)" ]; then + echo "NameVirtualHost $ip:$WEB_PORT" > $web_conf + fi echo "Listen $ip:$WEB_PORT" >> $web_conf fi if [ "$WEB_SSL" = 'mod_ssl' ]; then - echo "NameVirtualHost $ip:$WEB_SSL_PORT" >> $web_conf + if [ -z "$(/usr/sbin/apachectl -v | grep Apache/2.4)" ]; then + echo "NameVirtualHost $ip:$WEB_SSL_PORT" >> $web_conf + fi echo "Listen $ip:$WEB_SSL_PORT" >> $web_conf fi fi diff --git a/bin/v-restart-cron b/bin/v-restart-cron index a30278aa0..232e359c2 100755 --- a/bin/v-restart-cron +++ b/bin/v-restart-cron @@ -19,8 +19,8 @@ send_email_report() { 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 + service $CRON_SYSTEM configtest >> $tmpfile 2>&1 + service $CRON_SYSTEM restart >> $tmpfile 2>&1 cat $tmpfile | $send_mail -s "$subj" $email rm -f $tmpfile } @@ -45,11 +45,9 @@ if [ -z "$CRON_SYSTEM" ] || [ "$CRON_SYSTEM" = 'remote' ]; then fi # Restart system -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 +service $CRON_SYSTEM reload >/dev/null 2>&1 +if [ $? -ne 0 ]; then + service $CRON_SYSTEM restart >/dev/null 2>&1 if [ $? -ne 0 ]; then send_email_report exit $E_RESTART diff --git a/bin/v-restart-dns b/bin/v-restart-dns index 7dc7a9bab..fe960e269 100755 --- a/bin/v-restart-dns +++ b/bin/v-restart-dns @@ -26,7 +26,7 @@ send_email_report() { tmpfile=$(mktemp) subj="$(hostname): $DNS_SYSTEM restart failed" named-checkconf $dns_conf >> $tmpfile 2>&1 - /etc/init.d/$DNS_SYSTEM restart >> $tmpfile 2>&1 + service $DNS_SYSTEM restart >> $tmpfile 2>&1 cat $tmpfile | $send_mail -s "$subj" $email rm -f $tmpfile } @@ -51,9 +51,9 @@ if [ -z "$DNS_SYSTEM" ] || [ "$DNS_SYSTEM" = 'remote' ] ; then fi # Restart system -/etc/init.d/$DNS_SYSTEM reload >/dev/null 2>&1 +service $DNS_SYSTEM reload >/dev/null 2>&1 if [ $? -ne 0 ]; then - /etc/init.d/$DNS_SYSTEM restart >/dev/null 2>&1 + service $DNS_SYSTEM restart >/dev/null 2>&1 if [ $? -ne 0 ]; then send_email_report echo "Error: $DNS_SYSTEM restart failed" diff --git a/bin/v-restart-ftp b/bin/v-restart-ftp index 611672797..ab0c78abb 100755 --- a/bin/v-restart-ftp +++ b/bin/v-restart-ftp @@ -19,8 +19,8 @@ send_email_report() { 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 + service $FTP_SYSTEM configtest >> $tmpfile 2>&1 + service $FTP_SYSTEM restart >> $tmpfile 2>&1 cat $tmpfile | $send_mail -s "$subj" $email rm -f $tmpfile } diff --git a/bin/v-restart-mail b/bin/v-restart-mail index 325f0f0f8..fc8f339f9 100755 --- a/bin/v-restart-mail +++ b/bin/v-restart-mail @@ -19,8 +19,8 @@ send_email_report() { 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 + service $MAIL_SYSTEM configtest >> $tmpfile 2>&1 + service $MAIL_SYSTEM restart >> $tmpfile 2>&1 cat $tmpfile | $send_mail -s "$subj" $email rm -f $tmpfile } diff --git a/bin/v-restart-proxy b/bin/v-restart-proxy index c3be9aedd..31fcddc74 100755 --- a/bin/v-restart-proxy +++ b/bin/v-restart-proxy @@ -19,8 +19,8 @@ send_email_report() { 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 + service $PROXY_SYSTEM configtest >> $tmpfile 2>&1 + service $PROXY_SYSTEM restart >> $tmpfile 2>&1 cat $tmpfile | $send_mail -s "$subj" $email rm -f $tmpfile } @@ -45,7 +45,7 @@ if [ -z "$PROXY_SYSTEM" ] || [ "$PROXY_SYSTEM" = 'remote' ]; then fi # Restart system -/etc/init.d/$PROXY_SYSTEM restart >/dev/null 2>&1 +service $PROXY_SYSTEM restart >/dev/null 2>&1 if [ $? -ne 0 ]; then send_email_report echo "Error: $PROXY_SYSTEM restart failed" diff --git a/bin/v-restart-web b/bin/v-restart-web index 180ed6f86..7962b3020 100755 --- a/bin/v-restart-web +++ b/bin/v-restart-web @@ -19,8 +19,8 @@ send_email_report() { 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 + service $WEB_SYSTEM configtest >> $tmpfile 2>&1 + service $WEB_SYSTEM restart >> $tmpfile 2>&1 cat $tmpfile | $send_mail -s "$subj" $email rm -f $tmpfile } @@ -44,27 +44,24 @@ if [ -z "$WEB_SYSTEM" ] || [ "$WEB_SYSTEM" = 'remote' ]; then exit fi -# Restart system +# Reload web system +service $WEB_SYSTEM reload >/dev/null 2>&1 +rc=$? + +# Workaround for Ubuntu 12.04 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 - echo "Error: $WEB_SYSTEM restart failed" - exit $E_RESTART - fi + if [ ! -e "/var/run/apache2.pid" ]; then + rc=1 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_email_report - echo "Error: $WEB_SYSTEM restart failed" - exit $E_RESTART - fi +fi + +# Resart web system if reload didn't work +if [ "$rc" -ne 0 ]; then + service $WEB_SYSTEM restart >/dev/null 2>&1 + if [ $? -ne 0 ]; then + send_email_report + echo "Error: $WEB_SYSTEM restart failed" + exit $E_RESTART fi fi diff --git a/bin/v-update-web-templates b/bin/v-update-web-templates index 65c2d0a3a..617a7e27a 100755 --- a/bin/v-update-web-templates +++ b/bin/v-update-web-templates @@ -44,10 +44,10 @@ fi tar -xzpf templates.tar.gz -C $VESTA/data/ templates/web # Replace includes for apache2.4 -if [ "$os" = 'ubuntu' ]; then - if [ ! -z "$(apache2 -v|grep 'Apache/2.4')" ]; then +if [ "$WEB_SYSTEM" = 'httpd' ] || [ "$WEB_SYSTEM" = 'apache2' ]; then + if [ ! -z "$(/usr/sbin/apachectl -v | grep 'Apache/2.4')" ]; then sed -i "s/Include /IncludeOptional /g" \ - $VESTA/data/templates/web/apache2/*tpl + $VESTA/data/templates/web/$WEB_SYSTEM/*tpl fi fi