@@ -45,11 +45,37 @@ case "$available_manager" in
45
45
fi
46
46
;;
47
47
48
- # These commands seem to only differ slightly in their invocation
49
- " service" |" initctl" )
50
- if [[ $service == " service" ]]; then
51
- cmd=(" $service " " $name " " $action " )
52
- cmd_status=(" $service " " $name " " status" )
48
+ " initctl" )
49
+ cmd=(" $service " " $action " " $name " )
50
+ cmd_status=(" $service " " status" " $name " )
51
+
52
+ # The initctl show-config output has 'interesting' spacing/tabs, use word splitting to have single spaces
53
+ word_split=($( " $service " show-config " $name " 2>&1 ) )
54
+ enabled_out=" ${word_split[@]} "
55
+
56
+ if [[ $action != " status" ]]; then
57
+ # service and initctl may return non-zero if the service is already started or stopped
58
+ # If so, check for either "already running" or "Unknown instance" or "is not running" in the output before failing
59
+ " ${cmd[@]} " & > " $_tmp " || {
60
+ grep -q " already running" " $_tmp " || grep -q " Unknown instance:" " $_tmp " || grep -q " is not running" " $_tmp " || fail
61
+ }
62
+
63
+ cmd_out=" $( " ${cmd_status[@]} " 2>&1 ) "
64
+ success " { \" status\" : \" ${cmd_out} \" }"
65
+ fi
66
+
67
+ # "status" is already pretty terse for these commands
68
+ cmd_out=" $( " ${cmd_status[@]} " 2>&1 ) "
69
+ success " { \" status\" : \" ${cmd_out} \" , \" enabled\" : \" ${enabled_out} \" }"
70
+ ;;
71
+
72
+ " service" )
73
+ cmd=(" $service " " $name " " $action " )
74
+ cmd_status=(" $service " " $name " " status" )
75
+
76
+ # Several possibilities: chkconfig may be installed, the service may be a SysV job, or it may have been converted to Upstart
77
+ # This is exactly why we have systemd now
78
+ if type chkconfig & > /dev/null; then
53
79
# The chkconfig output has 'interesting' spacing/tabs, use word splitting to have single spaces
54
80
word_split=($( chkconfig --list " $name " 2>&1 ) )
55
81
else
0 commit comments