| Lines 1-6
          
      
      
        Link Here | 
        
          | 1 | #!/bin/sh | 1 | #!/bin/sh | 
        
          | 2 | # | 2 | # | 
          
            
              | 3 | # koha-start-zebra -- Start Zebra for named Koha instandes | 3 | # koha-start-zebra -- Start Zebra for named Koha instances | 
        
          | 4 | # Copyright 2010  Catalyst IT, Ltd | 4 | # Copyright 2010  Catalyst IT, Ltd | 
        
          | 5 | #  | 5 | #  | 
        
          | 6 | # This program is free software: you can redistribute it and/or modify | 6 | # This program is free software: you can redistribute it and/or modify | 
  
    | Lines 18-37
          
      
      
        Link Here | 
        
          | 18 |  | 18 |  | 
        
          | 19 | set -e | 19 | set -e | 
        
          | 20 |  | 20 |  | 
            
              |  |  | 21 | die() | 
            
              | 22 | { | 
            
              | 23 |     echo "$@" 1>&2 | 
            
              | 24 |     exit 1 | 
            
              | 25 | } | 
            
              | 26 |  | 
            
              | 27 | warn() | 
            
              | 28 | { | 
            
              | 29 |     echo "$@" 1>&2 | 
            
              | 30 | } | 
            
              | 31 |  | 
            
              | 32 | is_enabled() | 
            
              | 33 | { | 
            
              | 34 |     local instancename=$1 | 
            
              | 35 |  | 
            
              | 36 |     if ! is_instance $instancename; then | 
            
              | 37 |         return 1 | 
            
              | 38 |     fi | 
            
              | 39 |  | 
            
              | 40 |     if grep -q '^[[:space:]]*Include /etc/koha/apache-shared-disable.conf' \ | 
            
              | 41 |             "/etc/apache2/sites-available/$instancename" ; then | 
            
              | 42 |         return 1 | 
            
              | 43 |     else | 
            
              | 44 |         return 0 | 
            
              | 45 |     fi | 
            
              | 46 | } | 
            
              | 47 |  | 
            
              | 48 | is_instance() | 
            
              | 49 | { | 
            
              | 50 |     local instancename=$1 | 
            
              | 51 |  | 
            
              | 52 |     if find /etc/koha/sites -mindepth 1 -maxdepth 1 \ | 
            
              | 53 |                          -type d -printf '%f\n'\ | 
            
              | 54 |           | grep -q -x $instancename ; then | 
            
              | 55 |         return 0 | 
            
              | 56 |     else | 
            
              | 57 |         return 1 | 
            
              | 58 |     fi | 
            
              | 59 | } | 
            
              | 60 |  | 
            
              | 61 | is_zebra_running() | 
            
              | 62 | { | 
            
              | 63 |     local instancename=$1 | 
            
              | 64 |  | 
            
              | 65 |     if daemon --name="$instancename-koha-zebra" \ | 
            
              | 66 |             --user="$instancename-koha.$instancename-koha" \ | 
            
              | 67 |             --running ; then | 
            
              | 68 |         return 0 | 
            
              | 69 |     else | 
            
              | 70 |         return 1 | 
            
              | 71 |     fi | 
            
              | 72 | } | 
            
              | 73 |  | 
            
              | 74 | start_zebra_instance() | 
            
              | 75 | { | 
            
              | 76 |     local instancename=$1 | 
            
              | 77 |  | 
            
              | 78 |     if is_enabled $instancename; then | 
            
              | 79 |         echo "Starting Zebra server for $instancename" | 
            
              | 80 |         daemon \ | 
            
              | 81 |             --name="$instancename-koha-zebra" \ | 
            
              | 82 |             --errlog="/var/log/koha/$instancename/zebra-error.log" \ | 
            
              | 83 |             --stdout="/var/log/koha/$instancename/zebra.log" \ | 
            
              | 84 |             --output="/var/log/koha/$instancename/zebra-output.log" \ | 
            
              | 85 |             --verbose=1 \ | 
            
              | 86 |             --respawn \ | 
            
              | 87 |             --delay=30 \ | 
            
              | 88 |             --user="$instancename-koha.$instancename-koha" \ | 
            
              | 89 |             -- \ | 
            
              | 90 |             zebrasrv \ | 
            
              | 91 |             -v none,fatal,warn \ | 
            
              | 92 |             -f "/etc/koha/sites/$instancename/koha-conf.xml" && \ | 
            
              | 93 |         return 0 | 
            
              | 94 |     else | 
            
              | 95 |         return 1 | 
            
              | 96 |     fi | 
            
              | 97 | } | 
            
              | 98 |  | 
            
              | 99 | # Parse command line. | 
            
              | 100 | [ "$#" > 1 ] || die "Usage: $0 instancename..." | 
            
              | 101 |  | 
            
              | 102 | # Loop through the instance names | 
        
          | 21 | for name in "$@" | 103 | for name in "$@" | 
        
          | 22 | do | 104 | do | 
          
            
              | 23 |     echo "Starting Zebra server for $name" | 105 |     if is_instance $name ; then | 
            
              | 24 |     daemon \ | 106 |         if is_enabled $name ; then | 
            
              | 25 |         --name="$name-koha-zebra" \ | 107 |             if ! is_zebra_running $name; then | 
            
              | 26 |         --errlog="/var/log/koha/$name/zebra-error.log" \ | 108 |                 if ! start_zebra_instance $name; then | 
            
              | 27 |         --stdout="/var/log/koha/$name/zebra.log" \ | 109 |                     warn "Something went wrong starting Zebra for $name." | 
            
              | 28 |         --output="/var/log/koha/$name/zebra-output.log" \ | 110 |                 fi | 
            
              | 29 |         --verbose=1 \ | 111 |             else | 
            
              | 30 |         --respawn \ | 112 |                 warn "Zebra already running for instance $name." | 
            
              | 31 |         --delay=30 \ | 113 |             fi | 
            
              | 32 |         --user="$name-koha.$name-koha" \ | 114 |         else | 
            
              | 33 |         -- \ | 115 |             warn "Instance $name disabled. No action taken." | 
            
              | 34 |         zebrasrv \ | 116 |         fi | 
            
              | 35 |         -v none,fatal,warn \ | 117 |     else | 
            
              | 36 |         -f "/etc/koha/sites/$name/koha-conf.xml" | 118 |         warn "Unknown instance $name." | 
            
              |  |  | 119 |     fi | 
        
          | 37 | done | 120 | done | 
          
            
              | 38 | -  | 121 |  | 
            
              |  |  | 122 | exit 0 |