Browse Source

Merge pull request #255 from henri-hulski/issue_247

Adds systemd compatible service status check. Closes #247.
Serghey Rodin 11 năm trước cách đây
mục cha
commit
b7dbf07373
1 tập tin đã thay đổi với 10 bổ sung3 xóa
  1. 10 3
      bin/v-list-sys-services

+ 10 - 3
bin/v-list-sys-services

@@ -23,9 +23,16 @@ get_srv_state() {
     proc_name=${2-$1}
     proc_name=${2-$1}
 
 
     # Check service status
     # Check service status
-    status=$(service $srv status 2>/dev/null)
-    rc=$?
-    stopped=$(echo $status| grep stop)
+
+    # Check if systemd is used as init system
+    if [[ $(systemctl) =~ -\.mount ]]; then 
+        $(systemctl -q is-active $srv)
+        rc=$?
+    else
+        status=$(service $srv status 2>/dev/null)
+        rc=$?
+        stopped=$(echo $status| grep stop)
+    fi
 
 
     if [ "$rc" -eq 0 ] && [ -z "$stopped" ]; then
     if [ "$rc" -eq 0 ] && [ -z "$stopped" ]; then
         state='running'
         state='running'