Browse Source

minor refactoring and bugfixes

Milen Pavlov 12 years ago
parent
commit
464e0906d5
1 changed files with 21 additions and 17 deletions
  1. 21 17
      extra/centos/celeryd.init

+ 21 - 17
extra/centos/celeryd.init

@@ -130,15 +130,18 @@ create_paths() {
 export PATH="${PATH:+$PATH:}/usr/sbin:/sbin"
 export PATH="${PATH:+$PATH:}/usr/sbin:/sbin"
 
 
 
 
+_get_pid_files() {
+    [[ ! -d "$CELERYD_PID_DIR" ]] && return
+    echo $(find "$CELERYD_PID_DIR" -name "*.pid")
+}
+
 stop() {
 stop() {
     # Configuration management packages sometimes issue a "stop" command
     # Configuration management packages sometimes issue a "stop" command
     # in preparation for installing the software for the first time.
     # in preparation for installing the software for the first time.
     # In those cases we don't need celeryd-multi to tell us celeryd is
     # In those cases we don't need celeryd-multi to tell us celeryd is
     # not running.
     # not running.
-    [[ ! -d "$CELERYD_PID_DIR" ]] && echo "celeryd is stopped" && exit 0
-
-    local pid_files=$(find "$CELERYD_PID_DIR" -name "*.pid")
-    [[ -z $pid_files ]] && echo "celeryd is stopped" && exit 0
+    local pid_files=$(_get_pid_files)
+    [[ -z "$pid_files" ]] && echo "celeryd is stopped" && exit 0
 
 
     local one_failed=
     local one_failed=
     for pid_file in $pid_files; do
     for pid_file in $pid_files; do
@@ -153,7 +156,7 @@ stop() {
         echo
         echo
     done
     done
 
 
-    [[ "$one_failed" ]] && RETVAL=1 || RETVAL=0
+    [[ "$one_failed" ]] && exit 1 || exit 0
 }
 }
 
 
 start() {
 start() {
@@ -175,9 +178,8 @@ start() {
                          --cmd="$CELERYD"                   \
                          --cmd="$CELERYD"                   \
                          --quiet                            \
                          --quiet                            \
                          $CELERYD_OPTS
                          $CELERYD_OPTS
-    RETVAL=$?
 
 
-    if [[ "$RETVAL" == "0" ]]; then
+    if [[ "$?" == "0" ]]; then
         # Sleep a few seconds to give Celery a chance to initialize itself.
         # Sleep a few seconds to give Celery a chance to initialize itself.
         # This is useful to prevent scripts following this one from trying to
         # This is useful to prevent scripts following this one from trying to
         # use Celery (or its pid files) too early.
         # use Celery (or its pid files) too early.
@@ -185,30 +187,32 @@ start() {
         pid_files=$(find "$CELERYD_PID_DIR" -name "*.pid")
         pid_files=$(find "$CELERYD_PID_DIR" -name "*.pid")
         if [[ "$pid_files" ]]; then
         if [[ "$pid_files" ]]; then
             for pid_file in $pid_files; do
             for pid_file in $pid_files; do
+                local node=$(basename "$pid_file" .pid)
                 local pid=$(cat "$pid_file")
                 local pid=$(cat "$pid_file")
                 echo
                 echo
-                echo -n "    Node (pid $pid):"
+                echo -n "    $node (pid $pid):"
                 success
                 success
             done
             done
+            echo
+            exit 0
         else  # celeryd_multi succeeded but no pid files found
         else  # celeryd_multi succeeded but no pid files found
             failure
             failure
-            RETVAL=1
         fi
         fi
-    else
+    else  # celeryd_multi did not succeed
         failure
         failure
     fi
     fi
     echo
     echo
+    exit 1
 }
 }
 
 
 check_status() {
 check_status() {
-    [[ ! -d "$CELERYD_PID_DIR" ]] && echo "celeryd is stopped" && exit 1
-    local pid_files=$(find "$CELERYD_PID_DIR" -name "*.pid")
-    [[ -z $pid_files ]] && echo "celeryd is stopped" && exit 1
+    local pid_files=$(_get_pid_files)
+    [[ -z "$pid_files" ]] && echo "celeryd is stopped" && exit 1
     for pid_file in $pid_files; do
     for pid_file in $pid_files; do
-        local pid_basename=$(basename "$pid_file")
-        status -p "$pid_file" $"celeryd ($pid_basename)" || return 1  # if one node is down celeryd is down
+        local node=$(basename "$pid_file" .pid)
+        status -p "$pid_file" $"celeryd (node $node)" || exit 1  # if one node is down celeryd is down
     done
     done
-    return 0
+    exit 0
 }
 }
 
 
 case "$1" in
 case "$1" in
@@ -241,4 +245,4 @@ case "$1" in
     ;;
     ;;
 esac
 esac
 
 
-exit $RETVAL
+exit 1  # we should never get here