Refactoring stage IV (sys)

This commit is contained in:
Serghey Rodin 2012-03-31 22:55:50 +03:00
commit 3ba10cdc6e
25 changed files with 141 additions and 351 deletions

View file

@ -22,34 +22,22 @@ user="${4-admin}"
ip_status="${5-shared}"
ip_name=$6
# Importing variables
# Includes
source $VESTA/conf/vesta.conf
source $VESTA/func/shared.sh
source $VESTA/func/ip.sh
source $VESTA/func/domain.sh # for namehosting
source $VESTA/func/domain.sh
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
# Checking arg number
check_args '2' "$#" 'ip mask [interface] [user] [ip_status] [ip_name]'
# Checking argument format
validate_format 'ip' 'mask' 'interface' 'user'
# Checking system ip
is_sys_ip_free
# Checking user
is_object_valid 'user' 'USER' "$user" "$user"
# Checking ip_status
if [ ! -z "$ip_status" ]; then
validate_format 'ip_status'
fi
# Checking ip_name
validate_format 'ip' 'mask' 'interface' 'user' 'ip_status'
is_ip_free
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
if [ ! -z "$ip_name" ] ; then
validate_format 'ip_name'
fi
@ -59,9 +47,8 @@ fi
# Action #
#----------------------------------------------------------#
# Get interface number
i_number=$(get_next_interface_number)
iface="$interface$i_number"
# Get full interface name
get_ip_iface
# Defining config paths
conf='/etc/httpd/conf.d/vesta.conf'
@ -73,15 +60,12 @@ rconf='/etc/httpd/conf.d/rpaf.conf'
/sbin/ifconfig "$iface" "$ip" netmask "$mask"
# Adding startup script
ip_add_startup
create_ip_startup
# Adding vesta ip
ip_add_vesta
create_vesta_ip
# Importing main config
source $VESTA/conf/vesta.conf
# Adding namehosting support
# Namehosting support
namehost_ip_support
@ -93,7 +77,7 @@ namehost_ip_support
increase_user_value "$user" '$IP_OWNED'
if [ "$user" = 'admin' ]; then
if [ "$ip_status" = 'shared' ]; then
for user in $(ls $V_USERS/); do
for user in $(ls $VESTA/data/users); do
increase_user_value "$user" '$IP_AVAIL'
done
else
@ -104,7 +88,7 @@ else
increase_user_value 'admin' '$IP_AVAIL'
fi
# Adding task to the vesta pipe
# Restart web server
if [ "$web_restart" = 'yes' ]; then
$BIN/v_restart_web "$EVENT"
fi

View file

@ -40,7 +40,7 @@ is_object_unsuspended 'user' 'USER' "$user"
is_object_valid 'web' 'DOMAIN' "$domain"
is_object_unsuspended 'web' 'DOMAIN' "$domain"
is_object_value_empty 'web' 'DOMAIN' "$domain" '$SSL'
is_sys_ip_owner
is_ip_owner
is_web_domain_cert_valid

View file

@ -14,7 +14,7 @@
key=$(echo "$1" | tr '[:lower:]' '[:upper:]' )
value=$2
# Importing variables
# Includes
source $VESTA/conf/vesta.conf
source $VESTA/func/shared.sh
@ -23,17 +23,12 @@ source $VESTA/func/shared.sh
# Verifications #
#----------------------------------------------------------#
# Checking args
check_args '2' "$#" 'key value'
# Checking argument format
validate_format 'key'
# Checking key existance
check_ckey=$(grep "^$key='" $VESTA/conf/vesta.conf)
if [ -z "$check_ckey" ]; then
echo "Error: key not found"
log_event 'debug' "$E_INVALID $EVENT"
echo "Error: key $key not found"
log_event "$E_INVALID" "$EVENT"
exit $E_INVALID
fi

View file

@ -13,7 +13,7 @@
ip=$1
ip_name=$2
# Importing variables
# Includes
source $VESTA/conf/vesta.conf
source $VESTA/func/shared.sh
source $VESTA/func/ip.sh
@ -23,14 +23,9 @@ source $VESTA/func/ip.sh
# Verifications #
#----------------------------------------------------------#
# Checking arg number
check_args '2' "$#" 'ip ip_name'
# Checking argument format
validate_format 'ip' 'ip_name'
# Checking system ip
is_sys_ip_valid
is_ip_valid
#----------------------------------------------------------#
@ -38,7 +33,7 @@ is_sys_ip_valid
#----------------------------------------------------------#
# Changing ip name
update_sys_ip_value '$NAME' "$ip_name"
update_ip_value '$NAME' "$ip_name"
#----------------------------------------------------------#

View file

@ -14,7 +14,6 @@ ip=$1
user=$2
# Importing variables
source $VESTA/conf/vesta.conf
source $VESTA/func/shared.sh
source $VESTA/func/ip.sh
@ -23,25 +22,12 @@ source $VESTA/func/ip.sh
# Verifications #
#----------------------------------------------------------#
# Checking arg number
check_args '2' "$#" 'ip user'
# Checking argument format
validate_format 'ip' 'user'
# Checking user
is_object_valid 'user' 'USER' "$user"
# Checking user is active
is_object_unsuspended 'user' 'USER' "$user"
# Checking system ip
is_sys_ip_valid
# Checking webdomains on ip
is_ip_valid
is_ip_key_empty '$U_WEB_DOMAINS'
# Checking users on ip
is_ip_key_empty '$U_SYS_USERS'
@ -50,14 +36,14 @@ is_ip_key_empty '$U_SYS_USERS'
#----------------------------------------------------------#
# Changing ip owner
ip_owner=$(get_sys_ip_value '$OWNER')
ip_owner=$(get_ip_value '$OWNER')
if [ "$ip_owner" != "$user" ]; then
ip_status="$(get_sys_ip_value '$STATUS')"
update_sys_ip_value '$OWNER' "$user"
ip_status="$(get_ip_value '$STATUS')"
update_ip_value '$OWNER' "$user"
decrease_user_value "$ip_owner" '$IP_OWNED'
if [ "$ip_owner" = 'admin' ]; then
if [ "$ip_status" = 'shared' ]; then
for vesta_user in $(ls $V_USERS/); do
for vesta_user in $(ls $VESTA/data/users); do
decrease_user_value "$vesta_user" '$IP_AVAIL'
done
else
@ -71,7 +57,7 @@ if [ "$ip_owner" != "$user" ]; then
increase_user_value "$user" '$IP_OWNED'
if [ "$user" = 'admin' ]; then
if [ "$ip_status" = 'shared' ]; then
for user in $(ls $V_USERS/); do
for user in $(ls $VESTA/data/users); do
increase_user_value "$user" '$IP_AVAIL'
done
else

View file

@ -13,8 +13,7 @@
ip=$1
ip_status=$2
# Importing variables
source $VESTA/conf/vesta.conf
# Includes
source $VESTA/func/shared.sh
source $VESTA/func/ip.sh
@ -23,32 +22,21 @@ source $VESTA/func/ip.sh
# Verifications #
#----------------------------------------------------------#
# Checking arg number
check_args '2' "$#" 'ip ip_status'
# Checking argument format
validate_format 'ip' 'ip_status'
# Checking system ip
is_sys_ip_valid
# Checking current status
current_status=$(get_sys_ip_value '$STATUS')
if [ "$ip_status" = "$current_status" ]; then
echo "Error: status is already set"
log_event 'debug' "$E_EXISTS $EVENT"
is_ip_valid
if [ "$ip_status" = "$(get_ip_value '$STATUS')" ]; then
echo "Error: status $ip_status is already set"
log_event "$E_EXISTS" "$EVENT"
exit $E_EXISTS
fi
# Parsing current ip usage
web_domains=$(get_sys_ip_value '$U_WEB_DOMAINS')
sys_user=$(get_sys_ip_value '$U_SYS_USERS')
ip_owner=$(get_sys_ip_value '$OWNER')
# Checking condition
web_domains=$(get_ip_value '$U_WEB_DOMAINS')
sys_user=$(get_ip_value '$U_SYS_USERS')
ip_owner=$(get_ip_value '$OWNER')
if [ "$web_domains" -ne '0' ] && [ "$sys_user" != "$ip_owner" ]; then
echo "Error: ip is used"
log_event 'debug' "$E_INUSE $EVENT"
echo "Error: ip $ip is used"
log_event "$E_INUSE" "$EVENT"
exit $E_INUSE
fi
@ -58,7 +46,7 @@ fi
#----------------------------------------------------------#
# Changing ip name
update_sys_ip_value '$STATUS' "$ip_status"
update_ip_value '$STATUS' "$ip_status"
#----------------------------------------------------------#

View file

@ -24,24 +24,12 @@ source $VESTA/func/domain.sh
# Verifications #
#----------------------------------------------------------#
# Checking arg number
check_args '1' "$#" 'ip'
# Checking argument format
validate_format 'ip'
# Checking system ip
is_sys_ip_valid "$ip"
# Checking webdomains on ip
is_ip_valid "$ip"
is_ip_key_empty '$U_WEB_DOMAINS'
# Checking users on ip
is_ip_key_empty '$U_SYS_USERS'
# Checking interface
interface=$(get_current_interface)
#----------------------------------------------------------#
# Action #
@ -54,10 +42,11 @@ iconf='/etc/sysconfig/network-scripts/ifcfg'
rconf='/etc/httpd/conf.d/rpaf.conf'
# Get ip owner
user="$(get_sys_ip_value '$OWNER')"
ip_status="$(get_sys_ip_value '$STATUS')"
user="$(get_ip_value '$OWNER')"
ip_status="$(get_ip_value '$STATUS')"
# Deleting interface
get_current_interface
/sbin/ifconfig "$interface" down
# Deleting startup script
@ -66,9 +55,6 @@ rm -f $iconf-$interface
# Deleting vesta ip
rm -f $VESTA/data/ips/$ip
# Importing main config
source $VESTA/conf/vesta.conf
# Deleting namehosting support
namehost_ip_disable
@ -84,7 +70,7 @@ fi
if [ "$user" = 'admin' ]; then
if [ "$ip_status" = 'shared' ]; then
for user in $(ls $V_USERS/); do
for user in $(ls $VESTA/data/users/); do
decrease_user_value "$user" '$IP_AVAIL'
done
else

View file

@ -12,7 +12,7 @@
# Argument defenition
format=${1-shell}
# Importing variables
# Includes
source $VESTA/func/shared.sh
# Json function
@ -21,8 +21,6 @@ json_list_iface() {
int_counter=$(echo "$interfaces" | wc -l)
i=1
echo '['
# Listing ifaces
for interface in $interfaces; do
if [ "$i" -lt "$int_counter" ]; then
echo -e "\t\"$interface\","
@ -41,7 +39,6 @@ shell_list_iface() {
echo "INTERFACES"
echo "----------"
fi
for interface in $interfaces; do
echo "$interface"
done

View file

@ -14,7 +14,7 @@ ip=$1
IP=$ip
format=${2-shell}
# Importing variables
# Includes
source $VESTA/func/shared.sh
source $VESTA/func/ip.sh
@ -23,17 +23,10 @@ json_list_ip() {
i=1
fileds_count=$(echo "$fields" | wc -w)
ip_data=$(cat $VESTA/data/ips/$IP)
# Print top bracket
echo '{'
# Assign key=value
eval $ip_data
for field in $fields; do
eval value=$field
# Checking first field
if [ $i -eq 1 ]; then
echo -e "\t\"$value\": {"
else
@ -45,26 +38,21 @@ json_list_ip() {
fi
(( ++i))
done
# If there was any output
if [ -n "$value" ]; then
echo -e ' }'
fi
# Printing bottom json bracket
echo -e '}'
}
# Shell function
shell_list_ip() {
line=$(cat $VESTA/data/ips/$IP)
# Assing key=value
eval $line
# Print result line
for field in $fields; do
eval key="$field"
if [ -z "$key" ]; then
key='NULL'
fi
echo "${field//$/}: $key "
done
}
@ -76,12 +64,8 @@ shell_list_ip() {
# Checking args
check_args '1' "$#" 'ip [format]'
# Checking argument format
validate_format 'ip'
# Checking ip
is_sys_ip_valid
is_ip_valid
#----------------------------------------------------------#
# Action #
@ -89,8 +73,8 @@ is_sys_ip_valid
conf=$VESTA/data/ips/$IP
# Defining fileds to select
fields='$IP $OWNER $STATUS $NAME $U_SYS_USERS $U_WEB_DOMAINS
$INTERFACE $NETMASK $DATE'
fields='$IP $OWNER $STATUS $NAME $U_SYS_USERS $U_WEB_DOMAINS $INTERFACE
$NETMASK $DATE'
# Listing ip
case $format in

View file

@ -12,39 +12,27 @@
# Argument defenition
format=${1-shell}
# Importing variables
# Includes
source $VESTA/func/shared.sh
# Json function
json_list_ips() {
# Print top bracket
echo '{'
# Definining ip list
ip_list=$(ls $VESTA/data/ips/)
fileds_count=$(echo "$fields" | wc -w)
# Starting main loop
for IP in $ip_list; do
# Assing key=value
ip_data=$(cat $VESTA/data/ips/$IP)
eval $ip_data
# Closing bracket if there already was output
if [ -n "$data" ]; then
echo -e ' },'
fi
i=1
for field in $fields; do
eval value=$field
if [ $i -eq 1 ]; then
# Printing parrent
(( ++i))
echo -e "\t\"$value\": {"
else
# Printing child
if [ $i -lt $fileds_count ]; then
(( ++i))
echo -e "\t\t\"${field//$/}\": \"${value//,/, }\","
@ -55,22 +43,16 @@ json_list_ips() {
fi
done
done
# Closing bracket if there was output
if [ -n "$data" ]; then
echo -e ' }'
fi
# Printing bottom bracket
echo -e '}'
}
# Shell function
shell_list_ips() {
ip_list=$(ls $VESTA/data/ips/)
if [ -z "$nohead" ]; then
# Print brief info
echo "${fields//$/}"
for a in $fields; do
echo -e "--------- \c"
@ -78,15 +60,9 @@ shell_list_ips() {
echo
fi
# Starting main loop
for IP in $ip_list; do
# Reading user data
ip_data=$(cat $VESTA/data/ips/$IP)
# Assign key/value config
eval $ip_data
# Print result line
eval echo "$fields"
done
}
@ -95,9 +71,9 @@ shell_list_ips() {
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
conf=$VESTA/data/ips/*
# Defining fileds to select
conf=$VESTA/data/ips/*
fields="\$IP \$OWNER \$STATUS \$NAME \$U_SYS_USERS \$U_WEB_DOMAINS"
fields="$fields \$INTERFACE \$NETMASK \$DATE"

View file

@ -22,32 +22,25 @@ json_list_rrd() {
if [ "$i" -ne 1 ]; then
echo -e "\t},"
fi
# Define title
if [ "$type" = 'la' ]; then
title="Load Average"
fi
if [ "$type" = 'mem' ]; then
title="Memory Usage"
fi
if [ "$type" = 'net' ]; then
title="Bandwidth Usage $rrd"
fi
if [ "$type" = 'web' ] || [ "$type" = 'ftp' ] ||\
[ "$type" = 'ssh' ]; then
title="$(echo $rrd| tr '[:lower:]' '[:upper:]') Usage"
fi
if [ "$type" = 'db' ]; then
db_type=$(echo $rrd|cut -f 1 -d _ |sed -e 's/mysql/MySQL/g' \
-e 's/pgsql/PostgreSQL/g' )
db_host=$(echo $rrd|cut -f 2 -d _ )
title="$db_type Usage on $db_host"
fi
echo -e "\t\"$i\": {"
echo -e "\t\t\"TYPE\": \"$type\"",
echo -e "\t\t\"RRD\": \"$rrd\"",
@ -55,7 +48,6 @@ json_list_rrd() {
(( ++i))
done
done
if [ "$i" -gt 1 ]; then
echo -e "\t}"
fi
@ -65,11 +57,9 @@ json_list_rrd() {
# Define jshell function
shell_list_rrd() {
if [ -z "$nohead" ]; then
# Print brief info
echo "PATH"
echo "---------"
fi
for type in $rrd_types; do
for rrd in $(ls $RRD/$type |grep rrd$ |sed "s/\.rrd$//g"); do
echo "$RRD/$type/$rrd.rrd"
@ -101,6 +91,7 @@ fi
if [ -n "$FTP_SYSTEM" ] && [ "$FTP_SYSTEM" != 'no' ]; then
rrd_types="$rrd_types ftp"
fi
rrd_types="$rrd_types ssh"

View file

@ -15,7 +15,7 @@
user=${1-admin}
ip_status=${2-shared}
# Importing variables
# Includes
source $VESTA/conf/vesta.conf # include for internal func
source $VESTA/func/shared.sh
source $VESTA/func/ip.sh
@ -26,19 +26,9 @@ source $VESTA/func/domain.sh
# Verifications #
#----------------------------------------------------------#
# Checking arg number
check_args '0' "$#" '[user] [ip_status]'
# Checking user
if [ ! -z "$1" ]; then
validate_format 'user'
is_object_valid 'user' 'USER' "$user" "$user"
fi
# Checking ip_status
if [ ! -z "$2" ]; then
validate_format 'ip_status'
fi
validate_format 'user' 'ip_status'
is_object_valid 'user' 'USER' "$user" "$user"
#----------------------------------------------------------#
@ -46,7 +36,7 @@ fi
#----------------------------------------------------------#
# Get ip list
ip_list=$(/sbin/ifconfig |grep 'inet addr:'|cut -f 2 -d :|\
ip_list=$(/sbin/ifconfig | grep 'inet addr:' | cut -f 2 -d : | \
cut -f 1 -d ' '| grep -v 127.0.0.1)
# Get vesta registered ip list
@ -60,15 +50,14 @@ rconf='/etc/httpd/conf.d/rpaf.conf'
# Comparing each ip
for ip in $ip_list; do
check_ip=$(echo $vesta_ip_list|grep -w "$ip")
check_ip=$(echo $vesta_ip_list | grep -w "$ip")
# Checking ip registered
if [ -z "$check_ip" ]; then
# Parsing additional params
iface=$(/sbin/ifconfig|grep -B1 -w "$ip"|head -n 1|cut -f 1 -d ' ')
iface=$(/sbin/ifconfig |grep -B1 -w $ip |head -n 1 |cut -f 1 -d ' ')
interface=$(echo "$iface" | cut -f 1 -d :)
mask=$(/sbin/ifconfig |grep -w "$ip"|awk -F "Mask:" '{print $2}')
mask=$(/sbin/ifconfig |grep -w $ip |awk -F "Mask:" '{print $2}')
# Adding vesta ip
ip_add_vesta
@ -82,7 +71,7 @@ for ip in $ip_list; do
fi
fi
# NOTE: later we'll make revers comparation
# TBD: revers comparation
done
@ -93,7 +82,7 @@ done
# Updating user conf
increase_user_value "$user" '$IP_OWNED'
# Adding task to the vesta pipe
# Restart web server
if [ "$web_restart" = 'yes' ]; then
$BIN/v_restart_web "$EVENT"
fi

View file

@ -19,43 +19,18 @@ queue=$1
# mostly by cron wich not read it by itself
source /etc/profile.d/vesta.sh
# Importing variables
# Includes
source $VESTA/conf/vesta.conf
source $VESTA/func/shared.sh
# Export PATH for cron
PATH=$PATH:$BIN
# Defining pipe functions
restart_pipe() {
bash $VESTA/data/queue/restart.pipe
rm $VESTA/data/queue/restart.pipe
touch $VESTA/data/queue/restart.pipe
}
stats_pipe() {
bash $VESTA/data/queue/stats.pipe
}
disk_pipe() {
bash $VESTA/data/queue/disk.pipe
}
traff_pipe() {
bash $VESTA/data/queue/traffic.pipe
}
backup_pipe() {
bash $VESTA/data/queue/backup.pip
}
export $PATH
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
# Checking arg number
check_args '1' "$#" 'queue'
@ -63,12 +38,15 @@ check_args '1' "$#" 'queue'
# Action #
#----------------------------------------------------------#
# Defining pipe functions
case $queue in
restart) restart_pipe ;;
stats) stats_pipe ;;
backup) backup_pipe ;;
disk) disk_pipe ;;
traffic) traff_pipe ;;
restart) bash $VESTA/data/queue/restart.pipe;
rm $VESTA/data/queue/restart.pipe;
touch $VESTA/data/queue/restart.pipe;;
stats) bash $VESTA/data/queue/stats.pipe;;
backup) bash $VESTA/data/queue/backup.pip;;
disk) bash $VESTA/data/queue/disk.pipe;;
traffic) bash $VESTA/data/queue/traffic.pipe;;
*) check_args '1' '0' 'queue'
esac

View file

@ -11,11 +11,10 @@
#----------------------------------------------------------#
# Importing system enviroment as we run this script
# mostly by cron wich do not read it by itself
# mostly by cron wich do not read it by itself
source /etc/profile.d/vesta.sh
# Importing variables
# Includes
source $VESTA/conf/vesta.conf
source $VESTA/func/shared.sh

View file

@ -13,8 +13,9 @@
update=$1
period=${1-daily}
# Importing variables
# Includes
source $VESTA/conf/vesta.conf
source $VESTA/func/shared.sh
#----------------------------------------------------------#

View file

@ -13,7 +13,9 @@
update=$1
period=${1-daily}
# Importing variables
# Includes
source $VESTA/conf/vesta.conf
source $VESTA/func/shared.sh
#----------------------------------------------------------#

View file

@ -13,7 +13,9 @@
update=$1
period=${1-daily}
# Importing variables
# Includes
source $VESTA/conf/vesta.conf
source $VESTA/func/shared.sh
#----------------------------------------------------------#

View file

@ -13,7 +13,9 @@
update=$1
period=${1-daily}
# Importing variables
# Includes
source $VESTA/conf/vesta.conf
source $VESTA/func/shared.sh
#----------------------------------------------------------#

View file

@ -13,7 +13,8 @@
update=$1
period=${1-daily}
# Importing variables
# Includes
source $VESTA/conf/vesta.conf
source $VESTA/func/shared.sh
@ -79,7 +80,7 @@ for host in $hosts; do
if [ -z $HOST ] || [ -z $USER ] || [ -z $PASSWORD ] || [ -z $PORT ]
then
echo "Error: config is broken"
log_event 'debug' "$E_PARSING $EVENT"
log_event "$E_PARSING" "$EVENT"
exit $E_PARSING
fi

View file

@ -13,7 +13,9 @@
update=$1
period=${1-daily}
# Importing variables
# Includes
source $VESTA/conf/vesta.conf
source $VESTA/func/shared.sh
#----------------------------------------------------------#

View file

@ -13,7 +13,9 @@
update=$1
period=${1-daily}
# Importing variables
# Includes
source $VESTA/conf/vesta.conf
source $VESTA/func/shared.sh
#----------------------------------------------------------#

View file

@ -13,7 +13,8 @@
update=$1
period=${1-daily}
# Importing variables
# Includes
source $VESTA/conf/vesta.conf
source $VESTA/func/shared.sh
@ -81,11 +82,10 @@ for host in $hosts; do
if [ -z $HOST ] || [ -z $USER ] || [ -z $PASSWORD ] || [ -z $TPL ]
then
echo "Error: config is broken"
log_event 'debug' "$E_PARSING $EVENT"
log_event "$E_PARSING" "$EVENT"
exit $E_PARSING
fi
# Parsing data
q='SELECT SUM(xact_commit + xact_rollback), SUM(numbackends)
FROM pg_stat_database;'

View file

@ -13,7 +13,9 @@
update=$1
period=${1-daily}
# Importing variables
# Includes
source $VESTA/conf/vesta.conf
source $VESTA/func/shared.sh
#----------------------------------------------------------#

View file

@ -17,7 +17,7 @@ updates=''
# Importing system enviroment
source /etc/profile.d/vesta.sh
# Importing variables
# Includes
source $VESTA/conf/vesta.conf
source $VESTA/func/shared.sh