Bug 32465: Add 'queue' to koha-worker help documentation
[koha-ffzg.git] / debian / scripts / koha-disable
index 50785ef..c8d6994 100755 (executable)
@@ -1,6 +1,6 @@
 #!/bin/sh
 #
-# koha-disable -- disable Koha instances.
+# koha-disable - disable Koha instances.
 # Copyright 2010  Catalyst IT, Ltd
 # 
 # This program is free software: you can redistribute it and/or modify
 
 set -e
 
-
-die()
-{
-    echo "$@" 1>&2
+# include helper functions
+if [ -f "/usr/share/koha/bin/koha-functions.sh" ]; then
+    . "/usr/share/koha/bin/koha-functions.sh"
+else
+    echo "Error: /usr/share/koha/bin/koha-functions.sh not present." 1>&2
     exit 1
-}
-
-warn()
-{
-    echo "$@" 1>&2
-}
+fi
 
-is_enabled()
+disable_instance()
 {
     local instancename=$1
+    local instancefile=$(get_apache_config_for "$instancename")
 
-    if ! is_instance $instancename; then
-        return 1
-    fi
-
-    if grep -q '^[[:space:]]*Include /etc/koha/apache-shared-disable.conf' \
-            "/etc/apache2/sites-available/$instancename" ; then
-        return 1
+    if [ "$instancefile" = "" ]; then
+        echo 2
+    elif is_enabled $instancename; then
+        sed -i 's:^\s*#\(\s*Include /etc/koha/apache-shared-disable.conf\)$:\1:' "$instancefile"
+        echo 0
     else
-        return 0
+        echo 1
     fi
 }
 
-is_instance()
+usage()
 {
-    local instancename=$1
+    local scriptname=$0
+    cat <<EOF
+Disables Koha instances.
 
-    if find /etc/koha/sites -mindepth 1 -maxdepth 1 \
-                         -type d -printf '%f\n'\
-          | grep -q -x $instancename ; then
-        return 0
-    else
-        return 1
-    fi
-}
-
-disable_instance()
-{
-    local instancename=$1
+Usage: $scriptname instancename1 instancename2...
 
-    if is_enabled $instancename; then
-        sed -i 's:^\s*#\(\s*Include /etc/koha/apache-shared-disable.conf\)$:\1:' \
-          "/etc/apache2/sites-available/$instancename"
-        return 0
-    else
-        return 1
-    fi
+EOF
 }
 
 # Parse command line.
-[ "$#" > 1 ] || die "Usage: $0 instancename..."
+[ $# -ge 1 ] || ( usage ; die "Missing instance name..." )
 
 restart_apache="no"
-
 for name in "$@"
 do
     if is_instance $name ; then
-        if disable_instance $name; then
+        RET=$(disable_instance $name)
+        if [ "$RET" = 0 ]; then
             restart_apache="yes"
+            if is_sip_enabled $name; then
+                koha-sip --stop $name
+            fi
+            if is_zebra_running $name; then
+                koha-zebra --stop $name
+            fi
+            if is_indexer_running $name; then
+                koha-indexer --stop $name
+            fi
+            if is_worker_running $name; then
+                koha-worker --stop $name
+            fi
+        elif [ "$RET" = 2 ]; then
+            warn "Error: Apache configuration file not present for instance $name."
         else
-            warn "Instance $name already disabled."
+            warn "Warning: instance $name already disabled."
         fi
     else
         warn "Unknown instance $name."