From c81a2bf123adaa31b0e744ce86422be7e9ed1f0f Mon Sep 17 00:00:00 2001 From: Serghey Rodin Date: Fri, 16 May 2014 21:41:50 +0300 Subject: [PATCH] simplified way to manage system services --- bin/v-list-sys-services | 11 +++-------- bin/v-restart-service | 22 +++------------------- bin/v-start-service | 13 +++---------- bin/v-stop-service | 13 +++---------- 4 files changed, 12 insertions(+), 47 deletions(-) diff --git a/bin/v-list-sys-services b/bin/v-list-sys-services index 87f57ffe..7bed1437 100755 --- a/bin/v-list-sys-services +++ b/bin/v-list-sys-services @@ -23,14 +23,9 @@ get_srv_state() { proc_name=${2-$1} # Check service status - if [ -e "/etc/init.d/$srv" ]; then - /etc/init.d/$srv status > /dev/null 2>&1 - status=$? - else - status=1 - if [ ! -z "$(service $srv status| grep running)" ]; then - status=0 - fi + status=1 + if [ ! -z "$(service $srv status| grep running)" ]; then + status=0 fi if [ $status -eq 0 ]; then diff --git a/bin/v-restart-service b/bin/v-restart-service index d2ad93b8..ff69ba4b 100755 --- a/bin/v-restart-service +++ b/bin/v-restart-service @@ -27,25 +27,9 @@ 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 - send_mail="$VESTA/web/inc/mail-wrapper.php" - email=$(grep CONTACT $VESTA/data/users/admin/user.conf) - email=$(echo "$email" | cut -f 2 -d "'") - tmpfile=$(mktemp) - subj="$(hostname): $service restart failed" - /etc/init.d/$service configtest >> $tmpfile 2>&1 - /etc/init.d/$service restart >> $tmpfile 2>&1 - cat $tmpfile | $send_mail -s "$subj" $email - rm -f $tmpfile - exit $E_RESTART - fi -else - service $service restart >/dev/null 2>&1 - if [ $? -ne 0 ]; then - exit $E_RESTART - fi +service $service restart >/dev/null 2>&1 +if [ $? -ne 0 ]; then + exit $E_RESTART fi diff --git a/bin/v-start-service b/bin/v-start-service index 340f8b27..e07717a7 100755 --- a/bin/v-start-service +++ b/bin/v-start-service @@ -27,16 +27,9 @@ 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 -else - service $service start >/dev/null 2>&1 - if [ $? -ne 0 ]; then - exit $E_RESTART - fi +service $service start >/dev/null 2>&1 +if [ $? -ne 0 ]; then + exit $E_RESTART fi diff --git a/bin/v-stop-service b/bin/v-stop-service index 60c98fcf..8e2d4b87 100755 --- a/bin/v-stop-service +++ b/bin/v-stop-service @@ -27,16 +27,9 @@ 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 -else - service $service stop >/dev/null 2>&1 - if [ $? -ne 0 ]; then - exit $E_RESTART - fi +service $service stop >/dev/null 2>&1 +if [ $? -ne 0 ]; then + exit $E_RESTART fi