Skip to content

Commit

Permalink
Service config feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Serghey Rodin committed Aug 25, 2016
1 parent 9873dfa commit b89f602
Show file tree
Hide file tree
Showing 47 changed files with 3,499 additions and 2 deletions.
2 changes: 2 additions & 0 deletions bin/v-change-sys-config-value
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ value=$2
source $VESTA/func/main.sh
source $VESTA/conf/vesta.conf

PATH="$PATH:/usr/local/sbin:/sbin:/usr/sbin:/root/bin"


#----------------------------------------------------------#
# Verifications #
Expand Down
119 changes: 119 additions & 0 deletions bin/v-change-sys-service-config
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
#!/bin/bash
# info: change service config
# options: CONFIG SERVICE [RESTART]
#
# The function for changing service confguration.


#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#

# Argument definition
src=$1
service=$2
restart=$3
echo "$0 $*" >/tmp/t.log

# Includes
source $VESTA/func/main.sh
source $VESTA/conf/vesta.conf


#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#

check_args '2' "$#" 'CONFIG SERVICE [RESTART]'
if [ ! -e "$src" ]; then
check_result "$E_NOTEXIST" "$src config doesn't exist"
fi

#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#

# Defining dst config path
case $service in
nginx) dst='/etc/nginx/nginx.conf';;
httpd) dst='/etc/httpd/conf/httpd.conf';;
apache2) dst='/etc/apache2/apache2.conf';;
exim) dst='/etc/exim/exim.conf';;
exim4) dst='/etc/exim4/exim4.conf.template';;
vsftpd) dst=$(find /etc/vsftpd* -name 'vsftpd.conf');;
proftpd) dst=$(find /etc/proftpd* -name 'proftpd.conf');;
php) dst=$(find /etc/php* -name php.ini);;
mysql) dst=$(find /etc/my* -name my.cnf);;
mariadb) dst=$(find /etc/my* -name my.cnf);;
postgresql) dst=$($BIN/v-list-sys-pgsql-config plain |cut -f 1);;
postgresql-hba) dst=$($BIN/v-list-sys-pgsql-config plain |cut -f 2);;
dovecot) dst=$(find /etc/dovecot* -name dovecot.conf);;
dovecot-1) dst='/etc/dovecot/conf.d/10-auth.conf';;
dovecot-2) dst='/etc/dovecot/conf.d/10-logging.conf';;
dovecot-3) dst='/etc/dovecot/conf.d/10-mail.conf';;
dovecot-4) dst='/etc/dovecot/conf.d/10-master.conf';;
dovecot-5) dst='/etc/dovecot/conf.d/10-ssl.conf';;
dovecot-6) dst='/etc/dovecot/conf.d/20-imap.conf';;
dovecot-7) dst='/etc/dovecot/conf.d/20-pop3.conf';;
dovecot-8) dst='/etc/dovecot/conf.d/auth-passwdfile.conf.ext';;
named) dst='/etc/named.conf';;
bind9) dst='/etc/bind/named.conf';;
bind9-opt) dst='/etc/bind/named.conf.options';;
spamd) dst=$($BIN/v-list-sys-spamd-config plain);;
spamassassin) dst=$($BIN/v-list-sys-spamd-config plain);;
clamd) dst=$($BIN/v-list-sys-clamd-config plain);;
cron) dst='/etc/crontab';;
crond) dst='/etc/crontab';;
fail2ban) dst='/etc/fail2ban/jail.local';;
*) check_result $E_NOTEXIST "service $service doesn't exist"
esac

# Checking config path
for config in $dst; do
if [ ! -e "$config" ]; then
check_result $E_NOTEXIST "$service config doesn't exist"
fi
done

# Checking diff between src and dst configs
for config in $dst; do
diff -q $src $config >/dev/null

if [ $? -ne 0 ]; then
cp $config $config.vst.back
cp $src $config
update="yes"
fi
done

# Restarting service
if [ "$update" = 'yes' ] && [ "$restart" != 'no' ]; then
if [ "$service" = 'php' ]; then
if [ "$WEB_SYSTEM" = "nginx" ]; then
service=$WEB_BACKEND
else
service=$WEB_SYSTEM
fi
fi
if [[ "$service" =~ - ]]; then
service=$(echo ${service%-*})
fi

service $service restart >/dev/null 2>&1
if [ $? -ne 0 ]; then
for config in $dst; do
mv -f $config.vst.back $config
done
check_result $E_RESTART "$service failed to start with new config"
fi
fi


#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#

# Logging
log_event "$OK" "$ARGUMENTS"

exit
73 changes: 73 additions & 0 deletions bin/v-list-sys-clamd-config
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/bin/bash
# info: list clamd config parameters
# options: [FORMAT]
#
# The function for obtaining the list of clamd config parameters.


#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#

# Argument definition
format=${1-shell}

# Includes
source $VESTA/func/main.sh

# JSON list function
json_list() {
echo '{
"CONFIG": {
"config_path": "'$config_path'"
}
}'
}

# SHELL list function
shell_list() {
echo "config_path: $config_path"
}

# PLAIN list function
plain_list() {
echo "$config_path"
}

# CSV list function
csv_list() {
echo "config_path"
echo "$config_path"
}


#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#

# Defining config path
if [ -e '/etc/clamav/clamd.conf' ]; then
config_path='/etc/clamav/clamd.conf'
else
if [ -e '/etc/clamd.conf' ]; then
config_path='/etc/clamd.conf'
fi
if [ -e '/etc/clamd.d/clamd.conf' ]; then
config_path='/etc/clamav/clamd.conf'
fi
fi

# Listing data
case $format in
json) json_list ;;
plain) plain_list ;;
csv) csv_list ;;
shell) shell_list;;
esac


#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#

exit
103 changes: 103 additions & 0 deletions bin/v-list-sys-dovecot-config
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#!/bin/bash
# info: list dovecot config parameters
# options: [FORMAT]
#
# The function for obtaining the list of dovecot config parameters.


#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#

# Argument definition
format=${1-shell}

# Includes
source $VESTA/func/main.sh

# JSON list function
json_list() {
echo '{
"CONFIG": {
"config_path": "'$config_path'",
"config_path1": "'$config_path1'",
"config_path2": "'$config_path2'",
"config_path3": "'$config_path3'",
"config_path4": "'$config_path4'",
"config_path5": "'$config_path5'",
"config_path6": "'$config_path6'",
"config_path7": "'$config_path7'",
"config_path8": "'$config_path8'"
}
}'
}

# SHELL list function
shell_list() {
echo "config_path: $config_path"
echo "config_path1: $config_path1"
echo "config_path2: $config_path2"
echo "config_path3: $config_path3"
echo "config_path4: $config_path4"
echo "config_path5: $config_path5"
echo "config_path6: $config_path6"
echo "config_path7: $config_path7"
echo "config_path8: $config_path8"
}

# PLAIN list function
plain_list() {
echo -en "$config_path\t"
echo -en "$config_path1\t"
echo -en "$config_path2\t"
echo -en "$config_path3\t"
echo -en "$config_path4\t"
echo -en "$config_path5\t"
echo -en "$config_path6\t"
echo -en "$config_path7\t"
echo -e "$config_path8\t"
}

# CSV list function
csv_list() {
echo -n "config_path,config_path1,config_path2,config_path3,"
echo "config_path4,config_path5,config_path6,config_path7,config_path8"
echo -n "$config_path,$config_path1,$config_path2,$config_path3,"
echo -n "$config_path4,$config_path5,$config_path6,$config_path7,"
echo "$config_path8"
}


#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#

# Defining config path
if [ -e '/etc/dovecot.conf' ]; then
config_path='/etc/dovecot.conf'
else
config_path='/etc/dovecot/dovecot.conf'
config_path1='/etc/dovecot/conf.d/10-auth.conf'
config_path2='/etc/dovecot/conf.d/10-logging.conf'
config_path3='/etc/dovecot/conf.d/10-mail.conf'
config_path4='/etc/dovecot/conf.d/10-master.conf'
config_path5='/etc/dovecot/conf.d/10-ssl.conf'
config_path6='/etc/dovecot/conf.d/20-imap.conf'
config_path7='/etc/dovecot/conf.d/20-pop3.conf'
config_path8='/etc/dovecot/conf.d/auth-passwdfile.conf.ext'
fi

# Listing data
case $format in
json) json_list ;;
plain) plain_list ;;
csv) csv_list ;;
shell) shell_list;;
esac


#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#

exit
82 changes: 82 additions & 0 deletions bin/v-list-sys-mysql-config
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/bin/bash
# info: list mysql config parameters
# options: [FORMAT]
#
# The function for obtaining the list of mysql config parameters.


#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#

# Argument definition
format=${1-shell}

# Includes
source $VESTA/func/main.sh
source $VESTA/conf/vesta.conf

# JSON list function
json_list() {
eval $(echo "$config"|egrep "$keys"|\
sed -e "s/[ ]*=/=/" -e "s/=[ ]*/=\'/" -e "s/$/'/")
echo '{
"CONFIG": {
"max_user_connections": "'$max_user_connections'",
"max_connections": "'$max_connections'",
"wait_timeout": "'$wait_timeout'",
"interactive_timeout": "'$interactive_timeout'",
"max_allowed_packet": "'$max_allowed_packet'",
"config_path": "'$config_path'"
}
}'
}

# SHELL list function
shell_list() {
echo "$config" |egrep "$keys" |tr '=' ' '
echo "config_path $config_path"
}

# PLAIN list function
plain_list() {
echo "$config" |egrep "$keys" |tr '=' ' '
echo "config_path $config_path"
}

# CSV list function
csv_list() {
echo "$keys" |sed "s/|/,/g"
echo "$config" |egrep "$keys" |tr '=' ' ' |awk '{print $2}' |tr '\n' ','
echo
}


#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#

# Defining config path
config_path=$(find /etc/my* -name my.cnf)

# Defining keys
keys="max_user_connections|max_connections|wait_timeout|interactive_timeout"
keys="${keys}|max_allowed_packet"

# Reading config
config=$(cat $config_path|grep -v "^;")

# Listing data
case $format in
json) json_list ;;
plain) plain_list ;;
csv) csv_list ;;
shell) shell_list |column -t;;
esac


#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#

exit
Loading

0 comments on commit b89f602

Please sign in to comment.