diff --git a/bin/v-list-sys-services b/bin/v-list-sys-services index f04eb3d7..dd269d20 100755 --- a/bin/v-list-sys-services +++ b/bin/v-list-sys-services @@ -39,16 +39,15 @@ get_srv_state() { # Get pid date if [ ! -z $pid ] && [ -e "/proc/$pid/cmdline" ]; then mtime=$(stat -c "%Y" /proc/$pid/cmdline) - ptime=$(date -d @$mtime +%T) - pdate=$(date -d @$mtime +%F) + rtime=$((ctime - mtime)) + rtime=$((rtime / 60)) fi else # Service is stopped state='stopped' mem=0 cpu=0 - ptime="$TIME" - pdate="$DATE" + rtime="0" fi } @@ -59,139 +58,123 @@ get_srv_state() { # Save current proccess list tmp_file=$(mktemp) -ps aux | awk '{print $2" "$3}' | cut -f 1 -d '.' > $tmp_file +if [ "$format" = 'json' ]; then + ps aux | awk '{print $2" "$3}' | tr -d '.' > $tmp_file +else + ps aux | awk '{print $2" "$3}' | cut -f 1 -d '.' > $tmp_file +fi + +# Get current time +ctime=$(date +%s) # Proxy service=$PROXY_SYSTEM -spnd='yes' if [ ! -z "$service" ] && [ "$service" != 'no' ]; then - spnd='no' get_srv_state $service + str="NAME='$service' SYSTEM='reverse proxy' STATE='$state' CPU='$cpu'" + str="$str MEM='$mem' RTIME='$rtime'" fi -str="NAME='$service' SYSTEM='proxy' STATE='$state' CPU='$cpu'" -str="$str MEM='$mem' SUSPENDED='$spnd' TIME='$ptime' DATE='$pdate'" # Web service=$WEB_SYSTEM -spnd='yes' if [ ! -z "$service" ] && [ "$service" != 'no' ]; then - spnd='no' if [ "$service" == 'apache' ]; then service='httpd' fi get_srv_state $service + str="$str\nNAME='$service' SYSTEM='web server' STATE='$state' CPU='$cpu'" + str="$str MEM='$mem' RTIME='$rtime'" + fi -str="$str\nNAME='$service' SYSTEM='web' STATE='$state' CPU='$cpu'" -str="$str MEM='$mem' SUSPENDED='$spnd' TIME='$ptime' DATE='$pdate'" # DNS service=$DNS_SYSTEM -spnd='yes' if [ ! -z "$service" ] && [ "$service" != 'no' ]; then - spnd='no' if [ "$service" == 'bind' ]; then service='named' fi get_srv_state $service + str="$str\nNAME='$service' SYSTEM='dns server' STATE='$state' CPU='$cpu'" + str="$str MEM='$mem' RTIME='$rtime'" fi -str="$str\nNAME='$service' SYSTEM='dns' STATE='$state' CPU='$cpu'" -str="$str MEM='$mem' SUSPENDED='$spnd' TIME='$ptime' DATE='$pdate'" # MAIL service=$MAIL_SYSTEM -spnd='yes' if [ ! -z "$service" ] && [ "$service" != 'no' ]; then - spnd='no' get_srv_state $service + str="$str\nNAME='$service' SYSTEM='mail server' STATE='$state' CPU='$cpu'" + str="$str MEM='$mem' RTIME='$rtime'" fi -str="$str\nNAME='$service' SYSTEM='mail' STATE='$state' CPU='$cpu'" -str="$str MEM='$mem' SUSPENDED='$spnd' TIME='$ptime' DATE='$pdate'" # IMAP service=$IMAP_SYSTEM -spnd='yes' if [ ! -z "$service" ] && [ "$service" != 'no' ]; then - spnd='no' get_srv_state $service + str="$str\nNAME='$service' SYSTEM='pop/imap server' STATE='$state'" + str="$str CPU='$cpu' MEM='$mem' RTIME='$rtime'" fi -str="$str\nNAME='$service' SYSTEM='imap' STATE='$state' CPU='$cpu'" -str="$str MEM='$mem' SUSPENDED='$spnd' TIME='$ptime' DATE='$pdate'" # ANTIVIRUS service=$ANTIVIRUS_SYSTEM -spnd='yes' if [ ! -z "$service" ] && [ "$service" != 'no' ]; then - spnd='no' if [ "$ANTIVIRUS_SYSTEM" = 'clamav' ]; then service='clamd' fi get_srv_state $service + str="$str\nNAME='$service' SYSTEM='email antivirus' STATE='$state'" + str="$str CPU='$cpu' MEM='$mem' RTIME='$rtime'" fi -str="$str\nNAME='$service' SYSTEM='antivirus' STATE='$state' CPU='$cpu'" -str="$str MEM='$mem' SUSPENDED='$spnd' TIME='$ptime' DATE='$pdate'" # ANTISPAM service=$ANTISPAM_SYSTEM -spnd='yes' if [ ! -z "$service" ] && [ "$service" != 'no' ]; then - spnd='no' get_srv_state $service spamd + str="$str\nNAME='$service' SYSTEM='email antispam' STATE='$state'" + str="$str CPU='$cpu' MEM='$mem' RTIME='$rtime'" fi -str="$str\nNAME='$service' SYSTEM='antispam' STATE='$state' CPU='$cpu'" -str="$str MEM='$mem' SUSPENDED='$spnd' TIME='$ptime' DATE='$pdate'" # DB service=$DB_SYSTEM -spnd='yes' if [ ! -z "$service" ] && [ "$service" != 'no' ]; then - spnd='no' for db in ${DB_SYSTEM//,/ }; do service="$db" if [ "$service" == 'mysql' ] && [ ! -e "/etc/init.d/$service" ]; then service='mysqld' fi get_srv_state $service - str="$str\nNAME='$service' SYSTEM='db' STATE='$state' CPU='$cpu'" - str="$str MEM='$mem' SUSPENDED='$spnd' TIME='$ptime' DATE='$pdate'" + str="$str\nNAME='$service' SYSTEM='database server' STATE='$state'" + str="$str CPU='$cpu' MEM='$mem' RTIME='$rtime'" done -else - str="$str\nNAME='$service' SYSTEM='db' STATE='$state' CPU='$cpu''" - str="$str MEM='$mem' SUSPENDED='$spnd' TIME='$ptime' DATE='$pdate'" fi # FTP service=$FTP_SYSTEM -spnd='yes' if [ ! -z "$service" ] && [ "$service" != 'no' ]; then - spnd='no' get_srv_state $service + str="$str\nNAME='$service' SYSTEM='ftp server' STATE='$state' CPU='$cpu'" + str="$str MEM='$mem' RTIME='$rtime'" fi -str="$str\nNAME='$service' SYSTEM='ftp' STATE='$state' CPU='$cpu'" -str="$str MEM='$mem' SUSPENDED='$spnd' TIME='$ptime' DATE='$pdate'" # CRON service=$CRON_SYSTEM -spnd='yes' if [ ! -z "$service" ] && [ "$service" != 'no' ]; then - spnd='no' get_srv_state $service + str="$str\nNAME='$service' SYSTEM='job scheduler' STATE='$state'" + str="$str CPU='$cpu' MEM='$mem' RTIME='$rtime'" fi -str="$str\nNAME='$service' SYSTEM='ftp' STATE='$state' CPU='$cpu'" -str="$str MEM='$mem' SUSPENDED='$spnd' TIME='$ptime' DATE='$pdate'" # Defining config - echo -e "$str" > $tmp_file conf=$tmp_file # Defining fileds to select -fields="\$NAME \$SYSTEM \$STATE \$CPU \$MEM \$SUSPENDED \$TIME \$DATE" +fields="\$NAME \$SYSTEM \$STATE \$CPU \$MEM \$RTIME" # Listing services case $format in json) json_list ;; plain) nohead=1; shell_list ;; - shell) fields='$NAME $STATE $CPU $MEM $SUSPENDED $TIME $DATE' + shell) fields='$NAME $STATE $CPU $MEM $RTIME' shell_list | column -t ;; *) check_args '1' '0' 'USER [FORMAT]' esac diff --git a/bin/v-restart-cron b/bin/v-restart-cron index 458aa4bf..deac9a6a 100755 --- a/bin/v-restart-cron +++ b/bin/v-restart-cron @@ -12,7 +12,6 @@ # Includes source $VESTA/conf/vesta.conf source $VESTA/func/main.sh -EVENT=${1-$EVENT} #----------------------------------------------------------# @@ -21,11 +20,10 @@ EVENT=${1-$EVENT} # Parsing config / or just source config if [ "$CRON_SYSTEM" = 'crond' ]; then - /etc/init.d/crond 'reload' &>/dev/null + /etc/init.d/crond 'reload' >/dev/null 2>&1 if [ $? -ne 0 ]; then - /etc/init.d/crond 'restart' &>/dev/null + /etc/init.d/crond 'restart' >/dev/null 2>&1 if [ $? -ne 0 ]; then - log_event "$E_RESTART" "$EVENT" exit $E_RESTART fi fi diff --git a/bin/v-restart-dns b/bin/v-restart-dns index 8fc51dd2..e9cf4e57 100755 --- a/bin/v-restart-dns +++ b/bin/v-restart-dns @@ -12,18 +12,17 @@ # Includes source $VESTA/conf/vesta.conf source $VESTA/func/main.sh -EVENT=${1-$EVENT} + #----------------------------------------------------------# # Action # #----------------------------------------------------------# if [ "$DNS_SYSTEM" = 'bind' ]; then - /etc/init.d/named reload &>/dev/null + /etc/init.d/named reload >/dev/null 2>&1 if [ $? -ne 0 ]; then - /etc/init.d/named restart &>/dev/null + /etc/init.d/named restart >/dev/null 2>&1 if [ $? -ne 0 ]; then - log_event "$E_RESTART" "$EVENT" exit $E_RESTART fi fi diff --git a/bin/v-restart-mail b/bin/v-restart-mail index d1467be1..cc2a9db3 100755 --- a/bin/v-restart-mail +++ b/bin/v-restart-mail @@ -12,18 +12,17 @@ # Includes source $VESTA/conf/vesta.conf source $VESTA/func/main.sh -EVENT=${1-$EVENT} + #----------------------------------------------------------# # Action # #----------------------------------------------------------# if [ "$MAIL_SYSTEM" = 'exim' ]; then - /etc/init.d/exim reload &>/dev/null + /etc/init.d/exim reload >/dev/null 2>&1 if [ $? -ne 0 ]; then - /etc/init.d/exim restart &>/dev/null + /etc/init.d/exim restart >/dev/null 2>&1 if [ $? -ne 0 ]; then - log_event "$E_RESTART" "$EVENT" exit $E_RESTART fi fi diff --git a/bin/v-restart-service b/bin/v-restart-service new file mode 100755 index 00000000..cf41b493 --- /dev/null +++ b/bin/v-restart-service @@ -0,0 +1,42 @@ +#!/bin/bash +# info: restart service +# options: service +# +# The function restarts system service. + + +#----------------------------------------------------------# +# Variable&Function # +#----------------------------------------------------------# + +# Argument defenition +service=$1 + +# Includes +source $VESTA/func/main.sh + + +#----------------------------------------------------------# +# Verifications # +#----------------------------------------------------------# + +check_args '1' "$#" 'SERVICE' + + +#----------------------------------------------------------# +# Action # +#----------------------------------------------------------# + +if [ -x "/etc/init.d/$service" ]; then + /etc/init.d/$service restart >/dev/null 2>&1 + if [ $? -ne 0 ]; then + exit $E_RESTART + fi +fi + + +#----------------------------------------------------------# +# Vesta # +#----------------------------------------------------------# + +exit diff --git a/bin/v-restart-web b/bin/v-restart-web index 7ad08338..1c71d90b 100755 --- a/bin/v-restart-web +++ b/bin/v-restart-web @@ -1,8 +1,8 @@ #!/bin/bash -# info: restart dns service +# info: restart web services # options: NONE # -# The function tells BIND service to reload dns zone files. +# The function reloads web server configuration. #----------------------------------------------------------# @@ -12,41 +12,37 @@ # Includes source $VESTA/conf/vesta.conf source $VESTA/func/main.sh -EVENT=${1-$EVENT} + #----------------------------------------------------------# # Action # #----------------------------------------------------------# if [ "$WEB_SYSTEM" = 'apache' ]; then - /etc/init.d/httpd status &>/dev/null + /etc/init.d/httpd status >/dev/null 2>&1 if [ $? -eq 0 ]; then - /etc/init.d/httpd graceful &>/dev/null + /etc/init.d/httpd graceful >/dev/null 2>&1 if [ $? -ne 0 ]; then - log_event "$E_RESTART" "$EVENT" exit $E_RESTART fi else - /etc/init.d/httpd start &>/dev/null + /etc/init.d/httpd start >/dev/null 2>&1 if [ $? -ne 0 ]; then - log_event "$E_RESTART" "$EVENT" exit $E_RESTART fi fi fi if [ "$PROXY_SYSTEM" = 'nginx' ]; then - /etc/init.d/nginx status &>/dev/null + /etc/init.d/nginx status >/dev/null 2>&1 if [ $? -eq 0 ]; then - /etc/init.d/nginx reload &>/dev/null + /etc/init.d/nginx reload >/dev/null 2>&1 if [ $? -ne 0 ]; then - log_event "$E_RESTART" "$EVENT" exit $E_RESTART fi else - /etc/init.d/nginx start &>/dev/null + /etc/init.d/nginx start >/dev/null 2>&1 if [ $? -ne 0 ]; then - log_event "$E_RESTART" "$EVENT" exit $E_RESTART fi fi diff --git a/bin/v-start-service b/bin/v-start-service new file mode 100755 index 00000000..69cbfea6 --- /dev/null +++ b/bin/v-start-service @@ -0,0 +1,42 @@ +#!/bin/bash +# info: start service +# options: service +# +# The function starts system service. + + +#----------------------------------------------------------# +# Variable&Function # +#----------------------------------------------------------# + +# Argument defenition +service=$1 + +# Includes +source $VESTA/func/main.sh + + +#----------------------------------------------------------# +# Verifications # +#----------------------------------------------------------# + +check_args '1' "$#" 'SERVICE' + + +#----------------------------------------------------------# +# Action # +#----------------------------------------------------------# + +if [ -x "/etc/init.d/$service" ]; then + /etc/init.d/$service start >/dev/null 2>&1 + if [ $? -ne 0 ]; then + exit $E_RESTART + fi +fi + + +#----------------------------------------------------------# +# Vesta # +#----------------------------------------------------------# + +exit diff --git a/bin/v-stop-service b/bin/v-stop-service new file mode 100755 index 00000000..3984a36a --- /dev/null +++ b/bin/v-stop-service @@ -0,0 +1,42 @@ +#!/bin/bash +# info: stop service +# options: service +# +# The function stops system service. + + +#----------------------------------------------------------# +# Variable&Function # +#----------------------------------------------------------# + +# Argument defenition +service=$1 + +# Includes +source $VESTA/func/main.sh + + +#----------------------------------------------------------# +# Verifications # +#----------------------------------------------------------# + +check_args '1' "$#" 'SERVICE' + + +#----------------------------------------------------------# +# Action # +#----------------------------------------------------------# + +if [ -x "/etc/init.d/$service" ]; then + /etc/init.d/$service stop >/dev/null 2>&1 + if [ $? -ne 0 ]; then + exit $E_RESTART + fi +fi + + +#----------------------------------------------------------# +# Vesta # +#----------------------------------------------------------# + +exit diff --git a/web/bulk/service/index.php b/web/bulk/service/index.php new file mode 100644 index 00000000..39550498 --- /dev/null +++ b/web/bulk/service/index.php @@ -0,0 +1,28 @@ + 60 ) { $usage = $usage / 60; - $usage = number_format($usage, 2); - $usage = $usage." Hour."; + if ( $usage > 24 ) { + $usage = $usage / 24; + $usage = number_format($usage, 0); + if ( $usage == 1 ) { + $usage = $usage." day"; + } else { + $usage = $usage." days"; + } + } else { + $usage = number_format($usage, 0); + if ( $usage == 1 ) { + $usage = $usage." hour"; + } else { + $usage = $usage." hours"; + } + } } else { - $usage = $usage." Min."; + if ( $usage == 1 ) { + $usage = $usage." minute"; + } else { + $usage = $usage." minutes"; + } } return $usage; } diff --git a/web/js/events.js b/web/js/events.js index ccbf89ab..f524a66d 100644 --- a/web/js/events.js +++ b/web/js/events.js @@ -60,7 +60,7 @@ VE.callbacks.click.do_suspend = function(evt, elm) { var ref = elm.hasClass('data-controls') ? elm : elm.parents('.data-controls'); var url = $('input[name="suspend_url"]', ref).val(); var dialog_elm = ref.find('.confirmation-text-suspention'); - VE.helpers.createConfirmationDialog(dialog_elm, 'Confirm SUSPEND', url); + VE.helpers.createConfirmationDialog(dialog_elm, 'Confirm action', url); } /* @@ -70,7 +70,7 @@ VE.callbacks.click.do_unsuspend = function(evt, elm) { var ref = elm.hasClass('data-controls') ? elm : elm.parents('.data-controls'); var url = $('input[name="unsuspend_url"]', ref).val(); var dialog_elm = ref.find('.confirmation-text-suspention'); - VE.helpers.createConfirmationDialog(dialog_elm, 'Confirm UNSUSPEND', url); + VE.helpers.createConfirmationDialog(dialog_elm, 'Confirm action', url); } /* @@ -80,7 +80,7 @@ VE.callbacks.click.do_delete = function(evt, elm) { var ref = elm.hasClass('data-controls') ? elm : elm.parents('.data-controls'); var url = $('input[name="delete_url"]', ref).val(); var dialog_elm = ref.find('.confirmation-text-delete'); - VE.helpers.createConfirmationDialog(dialog_elm, 'Confirm DELETE', url); + VE.helpers.createConfirmationDialog(dialog_elm, 'Confirm action', url); } diff --git a/web/list/services/index.php b/web/list/services/index.php new file mode 100644 index 00000000..e5a28fe9 --- /dev/null +++ b/web/list/services/index.php @@ -0,0 +1,23 @@ +', $output); + if (empty($error)) $error = 'Error: service '.$v_service.' restart failed'; + $_SESSION['error_srv'] = $error; + } + unset($output); +} + +header("Location: /list/services/"); +exit; diff --git a/web/start/service/index.php b/web/start/service/index.php new file mode 100644 index 00000000..4767d534 --- /dev/null +++ b/web/start/service/index.php @@ -0,0 +1,22 @@ +', $output); + if (empty($error)) $error = 'Error: service '.$v_service.' start failed'; + $_SESSION['error_srv'] = $error; + } + unset($output); +} + +header("Location: /list/services/"); +exit; diff --git a/web/stop/service/index.php b/web/stop/service/index.php new file mode 100644 index 00000000..58b11337 --- /dev/null +++ b/web/stop/service/index.php @@ -0,0 +1,22 @@ +', $output); + if (empty($error)) $error = 'Error: service '.$v_service.' stop failed'; + $_SESSION['error_srv'] = $error; + } + unset($output); +} + +header("Location: /list/services/"); +exit; diff --git a/web/templates/admin/list_services.html b/web/templates/admin/list_services.html new file mode 100644 index 00000000..cb4700ee --- /dev/null +++ b/web/templates/admin/list_services.html @@ -0,0 +1,152 @@ + +
+
+
+
+
+
+
+
+
+
+
+
+
+
+ |
+
+ |
+
+
|
+