From fc80b0949a132798eb22dd9e9265e167a5abdf99 Mon Sep 17 00:00:00 2001 From: Serghey Rodin Date: Wed, 16 Jan 2013 01:51:02 +0200 Subject: [PATCH] service manager --- bin/v-list-sys-services | 85 ++++++-------- bin/v-restart-cron | 6 +- bin/v-restart-dns | 7 +- bin/v-restart-mail | 7 +- bin/v-restart-service | 42 +++++++ bin/v-restart-web | 22 ++-- bin/v-start-service | 42 +++++++ bin/v-stop-service | 42 +++++++ web/bulk/service/index.php | 28 +++++ web/images/start.png | Bin 0 -> 208 bytes web/images/stop.png | Bin 0 -> 150 bytes web/inc/main.php | 24 +++- web/js/events.js | 6 +- web/list/services/index.php | 23 ++++ web/restart/service/index.php | 22 ++++ web/start/service/index.php | 22 ++++ web/stop/service/index.php | 22 ++++ web/templates/admin/list_services.html | 152 +++++++++++++++++++++++++ web/templates/header.html | 2 +- 19 files changed, 471 insertions(+), 83 deletions(-) create mode 100755 bin/v-restart-service create mode 100755 bin/v-start-service create mode 100755 bin/v-stop-service create mode 100644 web/bulk/service/index.php create mode 100644 web/images/start.png create mode 100644 web/images/stop.png create mode 100644 web/list/services/index.php create mode 100644 web/restart/service/index.php create mode 100644 web/start/service/index.php create mode 100644 web/stop/service/index.php create mode 100644 web/templates/admin/list_services.html diff --git a/bin/v-list-sys-services b/bin/v-list-sys-services index f04eb3d74..dd269d20f 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 458aa4bf6..deac9a6ad 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 8fc51dd2a..e9cf4e572 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 d1467be1a..cc2a9db3c 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 000000000..cf41b4931 --- /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 7ad083380..1c71d90b4 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 000000000..69cbfea62 --- /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 000000000..3984a36a6 --- /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 000000000..395504982 --- /dev/null +++ b/web/bulk/service/index.php @@ -0,0 +1,28 @@ +$3n-jKx9jP7LeL$-D%~CV9KNF#HF> z1$&oI28wVNctjR6FmMZlFeAgPITAoY_7YEDSN1zB;yj8vYS#8;K%oFn7sn8e>!s&5 zayB@KG(Y6ux@G&;5(f4HhVKQo?iT|2bV?YiXA8@pg)5E literal 0 HcmV?d00001 diff --git a/web/images/stop.png b/web/images/stop.png new file mode 100644 index 0000000000000000000000000000000000000000..808e605b6ba47cf368345e32c7bdb17271a3bb25 GIT binary patch literal 150 zcmeAS@N?(olHy`uVBq!ia0vp^Y#_`5A|IT2?*XJ3i-X*q7}lMWc?pt9@^*J&_z!{$ z_AZ|c6yYrJh%9Dc;1&j9Muu5)B!GhKC7!;n>~|UYM3lLE=f_P43W<5TIEHXsPfkfl kSdn;uX@*1rLlw|?uS*Oar&H>W0aY+~y85}Sb4q9e05Lr#mH+?% literal 0 HcmV?d00001 diff --git a/web/inc/main.php b/web/inc/main.php index f48dc05b5..4e663e4dc 100644 --- a/web/inc/main.php +++ b/web/inc/main.php @@ -44,10 +44,28 @@ function top_panel($user, $TAB) { function humanize_time($usage) { if ( $usage > 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 ccbf89abf..f524a66d4 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 000000000..e5a28fe9f --- /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 000000000..4767d534c --- /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 000000000..58b11337b --- /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 000000000..cb4700ee8 --- /dev/null +++ b/web/templates/admin/list_services.html @@ -0,0 +1,152 @@ + + + + + + + + + + +
+ + + $value) { + ++$i; + if ($data[$key]['STATE'] == 'running') { + $status = 'active'; + $action = 'stop'; + } else { + $status = 'suspended'; + $action = 'start'; + } + + $cpu = $data[$key]['CPU'] / 10; + $cpu = number_format($cpu, 1); + if ($cpu == '0.0') $cpu = 0; + ?> + + + + + + + +
+ + + +
+
+ + + + + + +
restart
+ + + + + + + + + + + +
+ +
+ + + + +
+ +
+
+ + + + + +
+ CPU: + + % +
+
+ + + + + +
+ Memory: + + mb +
+
+ + + + + +
+ Run Time: + + +
+
+
+ + +
diff --git a/web/templates/header.html b/web/templates/header.html index 5bb1e34f6..f85516a41 100644 --- a/web/templates/header.html +++ b/web/templates/header.html @@ -311,7 +311,7 @@ .data-suspended { font-size: 8pt; letter-spacing: 0.1em; - color: #de6c5d; + color: #de5543; padding: 0 0 13 18; }