Skip to content

Commit b89f602

Browse files
author
Serghey Rodin
committed
Service config feature
1 parent 9873dfa commit b89f602

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+3499
-2
lines changed

bin/v-change-sys-config-value

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ value=$2
1818
source $VESTA/func/main.sh
1919
source $VESTA/conf/vesta.conf
2020

21+
PATH="$PATH:/usr/local/sbin:/sbin:/usr/sbin:/root/bin"
22+
2123

2224
#----------------------------------------------------------#
2325
# Verifications #

bin/v-change-sys-service-config

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

bin/v-list-sys-clamd-config

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/bin/bash
2+
# info: list clamd config parameters
3+
# options: [FORMAT]
4+
#
5+
# The function for obtaining the list of clamd config parameters.
6+
7+
8+
#----------------------------------------------------------#
9+
# Variable&Function #
10+
#----------------------------------------------------------#
11+
12+
# Argument definition
13+
format=${1-shell}
14+
15+
# Includes
16+
source $VESTA/func/main.sh
17+
18+
# JSON list function
19+
json_list() {
20+
echo '{
21+
"CONFIG": {
22+
"config_path": "'$config_path'"
23+
}
24+
}'
25+
}
26+
27+
# SHELL list function
28+
shell_list() {
29+
echo "config_path: $config_path"
30+
}
31+
32+
# PLAIN list function
33+
plain_list() {
34+
echo "$config_path"
35+
}
36+
37+
# CSV list function
38+
csv_list() {
39+
echo "config_path"
40+
echo "$config_path"
41+
}
42+
43+
44+
#----------------------------------------------------------#
45+
# Action #
46+
#----------------------------------------------------------#
47+
48+
# Defining config path
49+
if [ -e '/etc/clamav/clamd.conf' ]; then
50+
config_path='/etc/clamav/clamd.conf'
51+
else
52+
if [ -e '/etc/clamd.conf' ]; then
53+
config_path='/etc/clamd.conf'
54+
fi
55+
if [ -e '/etc/clamd.d/clamd.conf' ]; then
56+
config_path='/etc/clamav/clamd.conf'
57+
fi
58+
fi
59+
60+
# Listing data
61+
case $format in
62+
json) json_list ;;
63+
plain) plain_list ;;
64+
csv) csv_list ;;
65+
shell) shell_list;;
66+
esac
67+
68+
69+
#----------------------------------------------------------#
70+
# Vesta #
71+
#----------------------------------------------------------#
72+
73+
exit

bin/v-list-sys-dovecot-config

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
#!/bin/bash
2+
# info: list dovecot config parameters
3+
# options: [FORMAT]
4+
#
5+
# The function for obtaining the list of dovecot config parameters.
6+
7+
8+
#----------------------------------------------------------#
9+
# Variable&Function #
10+
#----------------------------------------------------------#
11+
12+
# Argument definition
13+
format=${1-shell}
14+
15+
# Includes
16+
source $VESTA/func/main.sh
17+
18+
# JSON list function
19+
json_list() {
20+
echo '{
21+
"CONFIG": {
22+
"config_path": "'$config_path'",
23+
"config_path1": "'$config_path1'",
24+
"config_path2": "'$config_path2'",
25+
"config_path3": "'$config_path3'",
26+
"config_path4": "'$config_path4'",
27+
"config_path5": "'$config_path5'",
28+
"config_path6": "'$config_path6'",
29+
"config_path7": "'$config_path7'",
30+
"config_path8": "'$config_path8'"
31+
}
32+
}'
33+
}
34+
35+
# SHELL list function
36+
shell_list() {
37+
echo "config_path: $config_path"
38+
echo "config_path1: $config_path1"
39+
echo "config_path2: $config_path2"
40+
echo "config_path3: $config_path3"
41+
echo "config_path4: $config_path4"
42+
echo "config_path5: $config_path5"
43+
echo "config_path6: $config_path6"
44+
echo "config_path7: $config_path7"
45+
echo "config_path8: $config_path8"
46+
}
47+
48+
# PLAIN list function
49+
plain_list() {
50+
echo -en "$config_path\t"
51+
echo -en "$config_path1\t"
52+
echo -en "$config_path2\t"
53+
echo -en "$config_path3\t"
54+
echo -en "$config_path4\t"
55+
echo -en "$config_path5\t"
56+
echo -en "$config_path6\t"
57+
echo -en "$config_path7\t"
58+
echo -e "$config_path8\t"
59+
}
60+
61+
# CSV list function
62+
csv_list() {
63+
echo -n "config_path,config_path1,config_path2,config_path3,"
64+
echo "config_path4,config_path5,config_path6,config_path7,config_path8"
65+
echo -n "$config_path,$config_path1,$config_path2,$config_path3,"
66+
echo -n "$config_path4,$config_path5,$config_path6,$config_path7,"
67+
echo "$config_path8"
68+
}
69+
70+
71+
#----------------------------------------------------------#
72+
# Action #
73+
#----------------------------------------------------------#
74+
75+
# Defining config path
76+
if [ -e '/etc/dovecot.conf' ]; then
77+
config_path='/etc/dovecot.conf'
78+
else
79+
config_path='/etc/dovecot/dovecot.conf'
80+
config_path1='/etc/dovecot/conf.d/10-auth.conf'
81+
config_path2='/etc/dovecot/conf.d/10-logging.conf'
82+
config_path3='/etc/dovecot/conf.d/10-mail.conf'
83+
config_path4='/etc/dovecot/conf.d/10-master.conf'
84+
config_path5='/etc/dovecot/conf.d/10-ssl.conf'
85+
config_path6='/etc/dovecot/conf.d/20-imap.conf'
86+
config_path7='/etc/dovecot/conf.d/20-pop3.conf'
87+
config_path8='/etc/dovecot/conf.d/auth-passwdfile.conf.ext'
88+
fi
89+
90+
# Listing data
91+
case $format in
92+
json) json_list ;;
93+
plain) plain_list ;;
94+
csv) csv_list ;;
95+
shell) shell_list;;
96+
esac
97+
98+
99+
#----------------------------------------------------------#
100+
# Vesta #
101+
#----------------------------------------------------------#
102+
103+
exit

bin/v-list-sys-mysql-config

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#!/bin/bash
2+
# info: list mysql config parameters
3+
# options: [FORMAT]
4+
#
5+
# The function for obtaining the list of mysql config parameters.
6+
7+
8+
#----------------------------------------------------------#
9+
# Variable&Function #
10+
#----------------------------------------------------------#
11+
12+
# Argument definition
13+
format=${1-shell}
14+
15+
# Includes
16+
source $VESTA/func/main.sh
17+
source $VESTA/conf/vesta.conf
18+
19+
# JSON list function
20+
json_list() {
21+
eval $(echo "$config"|egrep "$keys"|\
22+
sed -e "s/[ ]*=/=/" -e "s/=[ ]*/=\'/" -e "s/$/'/")
23+
echo '{
24+
"CONFIG": {
25+
"max_user_connections": "'$max_user_connections'",
26+
"max_connections": "'$max_connections'",
27+
"wait_timeout": "'$wait_timeout'",
28+
"interactive_timeout": "'$interactive_timeout'",
29+
"max_allowed_packet": "'$max_allowed_packet'",
30+
"config_path": "'$config_path'"
31+
}
32+
}'
33+
}
34+
35+
# SHELL list function
36+
shell_list() {
37+
echo "$config" |egrep "$keys" |tr '=' ' '
38+
echo "config_path $config_path"
39+
}
40+
41+
# PLAIN list function
42+
plain_list() {
43+
echo "$config" |egrep "$keys" |tr '=' ' '
44+
echo "config_path $config_path"
45+
}
46+
47+
# CSV list function
48+
csv_list() {
49+
echo "$keys" |sed "s/|/,/g"
50+
echo "$config" |egrep "$keys" |tr '=' ' ' |awk '{print $2}' |tr '\n' ','
51+
echo
52+
}
53+
54+
55+
#----------------------------------------------------------#
56+
# Action #
57+
#----------------------------------------------------------#
58+
59+
# Defining config path
60+
config_path=$(find /etc/my* -name my.cnf)
61+
62+
# Defining keys
63+
keys="max_user_connections|max_connections|wait_timeout|interactive_timeout"
64+
keys="${keys}|max_allowed_packet"
65+
66+
# Reading config
67+
config=$(cat $config_path|grep -v "^;")
68+
69+
# Listing data
70+
case $format in
71+
json) json_list ;;
72+
plain) plain_list ;;
73+
csv) csv_list ;;
74+
shell) shell_list |column -t;;
75+
esac
76+
77+
78+
#----------------------------------------------------------#
79+
# Vesta #
80+
#----------------------------------------------------------#
81+
82+
exit

0 commit comments

Comments
 (0)