v-change-sys-service-config 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #!/bin/bash
  2. # info: change service config
  3. # options: CONFIG SERVICE [RESTART]
  4. #
  5. # The function for changing service confguration.
  6. #----------------------------------------------------------#
  7. # Variable&Function #
  8. #----------------------------------------------------------#
  9. # Argument definition
  10. src=$1
  11. service=$2
  12. restart=$3
  13. echo "$0 $*" >/tmp/t.log
  14. # Includes
  15. source $VESTA/func/main.sh
  16. source $VESTA/conf/vesta.conf
  17. #----------------------------------------------------------#
  18. # Verifications #
  19. #----------------------------------------------------------#
  20. check_args '2' "$#" 'CONFIG SERVICE [RESTART]'
  21. if [ ! -e "$src" ]; then
  22. check_result "$E_NOTEXIST" "$src config doesn't exist"
  23. fi
  24. #----------------------------------------------------------#
  25. # Action #
  26. #----------------------------------------------------------#
  27. # Defining dst config path
  28. case $service in
  29. nginx) dst='/etc/nginx/nginx.conf';;
  30. httpd) dst='/etc/httpd/conf/httpd.conf';;
  31. apache2) dst='/etc/apache2/apache2.conf';;
  32. exim) dst='/etc/exim/exim.conf';;
  33. exim4) dst='/etc/exim4/exim4.conf.template';;
  34. vsftpd) dst=$(find /etc/vsftpd* -name 'vsftpd.conf');;
  35. proftpd) dst=$(find /etc/proftpd* -name 'proftpd.conf');;
  36. php) dst=$(find /etc/php* -name php.ini);;
  37. mysql) dst=$(find /etc/my* -name my.cnf);;
  38. mysqld) dst=$(find /etc/my* -name my.cnf);;
  39. mariadb) dst=$(find /etc/my* -name my.cnf);;
  40. postgresql) dst=$($BIN/v-list-sys-pgsql-config plain |cut -f 1);;
  41. postgresql-hba) dst=$($BIN/v-list-sys-pgsql-config plain |cut -f 2);;
  42. dovecot) dst=$(find /etc/dovecot* -name dovecot.conf);;
  43. dovecot-1) dst='/etc/dovecot/conf.d/10-auth.conf';;
  44. dovecot-2) dst='/etc/dovecot/conf.d/10-logging.conf';;
  45. dovecot-3) dst='/etc/dovecot/conf.d/10-mail.conf';;
  46. dovecot-4) dst='/etc/dovecot/conf.d/10-master.conf';;
  47. dovecot-5) dst='/etc/dovecot/conf.d/10-ssl.conf';;
  48. dovecot-6) dst='/etc/dovecot/conf.d/20-imap.conf';;
  49. dovecot-7) dst='/etc/dovecot/conf.d/20-pop3.conf';;
  50. dovecot-8) dst='/etc/dovecot/conf.d/auth-passwdfile.conf.ext';;
  51. named) dst='/etc/named.conf';;
  52. bind9) dst='/etc/bind/named.conf';;
  53. bind9-opt) dst='/etc/bind/named.conf.options';;
  54. spamd) dst=$($BIN/v-list-sys-spamd-config plain);;
  55. spamassassin) dst=$($BIN/v-list-sys-spamd-config plain);;
  56. clamd) dst=$($BIN/v-list-sys-clamd-config plain);;
  57. cron) dst='/etc/crontab';;
  58. crond) dst='/etc/crontab';;
  59. fail2ban) dst='/etc/fail2ban/jail.local';;
  60. *) check_result $E_NOTEXIST "service $service doesn't exist"
  61. esac
  62. # Checking config path
  63. for config in $dst; do
  64. if [ ! -e "$config" ]; then
  65. check_result $E_NOTEXIST "$service config doesn't exist"
  66. fi
  67. done
  68. # Checking diff between src and dst configs
  69. for config in $dst; do
  70. diff -q $src $config >/dev/null
  71. if [ $? -ne 0 ]; then
  72. cp $config $config.vst.back
  73. cp $src $config
  74. update="yes"
  75. fi
  76. done
  77. # Restarting service
  78. if [ "$update" = 'yes' ] && [ "$restart" != 'no' ]; then
  79. if [[ "$service" =~ - ]]; then
  80. service=$(echo ${service%-*})
  81. fi
  82. if [ "$service" = 'php' ]; then
  83. if [ "$WEB_SYSTEM" = "nginx" ]; then
  84. service=$(ls /usr/sbin/php*fpm* |cut -f 4 -d /)
  85. else
  86. service=$WEB_SYSTEM
  87. fi
  88. fi
  89. service $service restart >/dev/null 2>&1
  90. if [ $? -ne 0 ]; then
  91. for config in $dst; do
  92. mv -f $config.vst.back $config
  93. done
  94. check_result $E_RESTART "$service failed to start with new config"
  95. fi
  96. fi
  97. #----------------------------------------------------------#
  98. # Vesta #
  99. #----------------------------------------------------------#
  100. # Logging
  101. log_event "$OK" "$ARGUMENTS"
  102. exit