v-update-sys-ip 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #!/bin/bash
  2. # info: update system ip
  3. # options: [USER] [IP_STATUS]
  4. #
  5. # The function scans configured ip in the system and register them with vesta
  6. # internal database. This call is intended for use on vps servers, where ip is
  7. # set by hypervizor.
  8. #----------------------------------------------------------#
  9. # Variable&Function #
  10. #----------------------------------------------------------#
  11. # Argument defenition
  12. user=${1-admin}
  13. ip_status=${2-shared}
  14. # Includes
  15. source $VESTA/func/main.sh
  16. source $VESTA/conf/vesta.conf
  17. #----------------------------------------------------------#
  18. # Verifications #
  19. #----------------------------------------------------------#
  20. check_args '0' "$#" '[USER] [IP_STATUS]'
  21. validate_format 'user' 'ip_status'
  22. is_object_valid 'user' 'USER' "$user" "$user"
  23. #----------------------------------------------------------#
  24. # Action #
  25. #----------------------------------------------------------#
  26. # Get list of ip addresses
  27. ip_list=$(/sbin/ifconfig | grep 'inet addr:' | cut -f 2 -d : | \
  28. cut -f 1 -d ' '| grep -v 127.0.0.1)
  29. ip_num=$(echo "$ip_list" | wc -l)
  30. # WorkAround for Amazon stop/start issue
  31. vst_ip_list=$(ls $VESTA/data/ips/)
  32. vst_ip_num=$(echo "$vst_ip_list" | wc -l)
  33. if [ ! -z "$vst_ip_list" ] && [ "$vst_ip_num" -eq '1' ]; then
  34. if [ $ip_num -eq 1 ] && [ "$ip_list" != "$vst_ip_list" ]; then
  35. new=$ip_list
  36. old=$vst_ip_list
  37. mv $VESTA/data/ips/$old $VESTA/data/ips/$new
  38. if [ ! -z "$PROXY_SYSTEM" ]; then
  39. mv /etc/$PROXY_SYSTEM/conf.d/$old.conf \
  40. /etc/$PROXY_SYSTEM/conf.d/$new.conf
  41. sed -i "s/$old/$new/g" /etc/$PROXY_SYSTEM/conf.d/$new.conf
  42. $BIN/v-restart-proxy
  43. fi
  44. if [ ! -z "$WEB_SYSTEM" ]; then
  45. mv /etc/$WEB_SYSTEM/conf.d/$old.conf \
  46. /etc/$WEB_SYSTEM/conf.d/$new.conf
  47. sed -i "s/$old/$new/g" /etc/$WEB_SYSTEM/conf.d/$new.conf
  48. sed -i "s/$old/$new/g" $VESTA/data/users/*/web.conf
  49. # Rebuild web domains
  50. for user in $(ls $VESTA/data/users/); do
  51. $BIN/v-rebuild-web-domains $user no
  52. done
  53. $BIN/v-restart-web
  54. fi
  55. if [ ! -z "$DNS_SYSTEM" ]; then
  56. # Rebuild dns domains
  57. for user in $(ls $VESTA/data/users/); do
  58. sed -i "s/$old/$new/g" $VESTA/data/users/$user/dns.conf
  59. sed -i "s/$old/$new/g" $VESTA/data/users/$user/dns/*.conf
  60. $BIN/v-rebuild-dns-domains $user no
  61. done
  62. $BIN/v-restart-dns
  63. fi
  64. # No further comparation is needed
  65. exit
  66. fi
  67. fi
  68. # Compare ips
  69. for ip in $ip_list; do
  70. if [ ! -e "$VESTA/data/ips/$ip" ]; then
  71. iface=$(/sbin/ifconfig |grep -B1 -w $ip |head -n1 |cut -f1 -d ' ')
  72. interface=$(echo "$iface" | cut -f 1 -d :)
  73. mask=$(/sbin/ifconfig |grep -w $ip |awk -F "Mask:" '{print $2}')
  74. $BIN/v-add-sys-ip $ip $mask $interface
  75. fi
  76. done
  77. #----------------------------------------------------------#
  78. # Vesta #
  79. #----------------------------------------------------------#
  80. exit