Here's what I use:
```
upgrade)
  if sig USR2
  then
    printf 'Waiting for new Unicorn workers'
    n=$TIMEOUT
    while (! (test -s $PID && ps --no-headers --ppid `cat $PID` > /dev/null)) && test $n -ge 0
    do
      printf '.' && sleep 10 && n=$(( $n - 10 ))
    done

    if test $n -lt 0 && (! (test -s $PID && ps --no-headers --ppid `cat $PID` > /dev/null))
    then
      echo >&2 "$PID process does not exist after $TIMEOUT seconds"
      exit 1
    fi
    printf '\nNew Unicorn workers started'

    if test -s $old_pid
    then
      printf '\nWaiting for old Unicorn master to stop'
      n=$TIMEOUT
      while test -s $old_pid && test $n -ge 0
      do
        printf '.' && sleep 10 && n=$(( $n - 10 ))
      done
      echo

      if test $n -lt 0 && test -s $old_pid
      then
        echo >&2 "$old_pid still exists after $TIMEOUT seconds"
        exit 1
      fi
    fi

    printf '\nOld Unicorn master stopped'
    exit 0
  fi
  echo >&2 "Couldn't upgrade, starting '$CMD' instead"
  $CMD
  ;;
```