Skip to content

Commit c81a2bf

Browse files
committed
simplified way to manage system services
1 parent 96019af commit c81a2bf

File tree

4 files changed

+12
-47
lines changed

4 files changed

+12
-47
lines changed

bin/v-list-sys-services

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,9 @@ get_srv_state() {
2323
proc_name=${2-$1}
2424

2525
# Check service status
26-
if [ -e "/etc/init.d/$srv" ]; then
27-
/etc/init.d/$srv status > /dev/null 2>&1
28-
status=$?
29-
else
30-
status=1
31-
if [ ! -z "$(service $srv status| grep running)" ]; then
32-
status=0
33-
fi
26+
status=1
27+
if [ ! -z "$(service $srv status| grep running)" ]; then
28+
status=0
3429
fi
3530

3631
if [ $status -eq 0 ]; then

bin/v-restart-service

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,9 @@ check_args '1' "$#" 'SERVICE'
2727
# Action #
2828
#----------------------------------------------------------#
2929

30-
if [ -x "/etc/init.d/$service" ]; then
31-
/etc/init.d/$service restart >/dev/null 2>&1
32-
if [ $? -ne 0 ]; then
33-
send_mail="$VESTA/web/inc/mail-wrapper.php"
34-
email=$(grep CONTACT $VESTA/data/users/admin/user.conf)
35-
email=$(echo "$email" | cut -f 2 -d "'")
36-
tmpfile=$(mktemp)
37-
subj="$(hostname): $service restart failed"
38-
/etc/init.d/$service configtest >> $tmpfile 2>&1
39-
/etc/init.d/$service restart >> $tmpfile 2>&1
40-
cat $tmpfile | $send_mail -s "$subj" $email
41-
rm -f $tmpfile
42-
exit $E_RESTART
43-
fi
44-
else
45-
service $service restart >/dev/null 2>&1
46-
if [ $? -ne 0 ]; then
47-
exit $E_RESTART
48-
fi
30+
service $service restart >/dev/null 2>&1
31+
if [ $? -ne 0 ]; then
32+
exit $E_RESTART
4933
fi
5034

5135

bin/v-start-service

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,9 @@ check_args '1' "$#" 'SERVICE'
2727
# Action #
2828
#----------------------------------------------------------#
2929

30-
if [ -x "/etc/init.d/$service" ]; then
31-
/etc/init.d/$service start >/dev/null 2>&1
32-
if [ $? -ne 0 ]; then
33-
exit $E_RESTART
34-
fi
35-
else
36-
service $service start >/dev/null 2>&1
37-
if [ $? -ne 0 ]; then
38-
exit $E_RESTART
39-
fi
30+
service $service start >/dev/null 2>&1
31+
if [ $? -ne 0 ]; then
32+
exit $E_RESTART
4033
fi
4134

4235

bin/v-stop-service

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,9 @@ check_args '1' "$#" 'SERVICE'
2727
# Action #
2828
#----------------------------------------------------------#
2929

30-
if [ -x "/etc/init.d/$service" ]; then
31-
/etc/init.d/$service stop >/dev/null 2>&1
32-
if [ $? -ne 0 ]; then
33-
exit $E_RESTART
34-
fi
35-
else
36-
service $service stop >/dev/null 2>&1
37-
if [ $? -ne 0 ]; then
38-
exit $E_RESTART
39-
fi
30+
service $service stop >/dev/null 2>&1
31+
if [ $? -ne 0 ]; then
32+
exit $E_RESTART
4033
fi
4134

4235

0 commit comments

Comments
 (0)