Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding start timeout parameter #549

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions bin/heroku-php-apache2
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ fi
bp_dir=$(cd $(dirname $(realpath $0)); cd ..; pwd)

verbose=
timeout=25

php_passthrough() {
local dir=$(dirname "$1")
Expand Down Expand Up @@ -71,28 +72,28 @@ findconfig() {

wait_pidfile() {
i=0
while ! test -f "$1" && (( i < 25 )); do
while ! test -f "$1" && (( i < $timeout )); do
[[ $verbose && ${2:-} ]] && echo "$2" >&2
sleep 0.1
((++i)) # don't do i++, that is a post increment operation, and will return status 1, since the expression evaluates to 0...
done
if (( i == 25 )); then
if (( i == $timeout )); then
# we timed out
return 1;
fi
}

wait_pid_and_pidfile() {
i=0
while ! test -f "$2" && (( i < 25 )); do
while ! test -f "$2" && (( i < $timeout )); do
if ! kill -0 "$1" 2> /dev/null; then # kill -0 checks if process exists
break;
fi
[[ $verbose && ${3:-} ]] && echo "$3" >&2
sleep 0.1
((++i)) # don't do i++, that is a post increment operation, and will return status 1, since the expression evaluates to 0...
done
if (( i == 25 )); then
if (( i == $timeout )); then
# we timed out
return 1;
fi
Expand Down Expand Up @@ -143,6 +144,7 @@ print_help() {
is not given, then the port number to use is read from
the \$PORT environment variable, or a random port is
chosen if that variable does not exist.
-t <retries> Set start timeout
-v, --verbose Be more verbose during startup.

The <BPDIR> placeholder above represents the base directory of this buildpack:
Expand Down Expand Up @@ -193,7 +195,7 @@ export PHP_INI_SCAN_DIR="${PHP_INI_SCAN_DIR}${bp_dir}/conf/php/apm-nostart-overr
# init logs array here as empty before parsing options; -l could append to it, but the default list gets added later since we use $PORT in there and that can be set using -p
declare -a logs

optstring=":-:C:c:F:f:i:l:p:vh"
optstring=":-:C:c:F:f:i:l:p:t:vh"

# process flags first
while getopts "$optstring" opt; do
Expand Down Expand Up @@ -260,6 +262,9 @@ while getopts "$optstring" opt; do
p)
PORT="$OPTARG"
;;
t)
timeout=$OPTARG
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 2
Expand Down
15 changes: 10 additions & 5 deletions bin/heroku-php-nginx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ fi
bp_dir=$(cd $(dirname $(realpath $0)); cd ..; pwd)

verbose=
timeout=25

php_passthrough() {
local dir=$(dirname "$1")
Expand Down Expand Up @@ -71,28 +72,28 @@ findconfig() {

wait_pidfile() {
i=0
while ! test -f "$1" && (( i < 25 )); do
while ! test -f "$1" && (( i < $timeout )); do
[[ $verbose && ${2:-} ]] && echo "$2" >&2
sleep 0.1
((++i)) # don't do i++, that is a post increment operation, and will return status 1, since the expression evaluates to 0...
done
if (( i == 25 )); then
if (( i == $timeout )); then
# we timed out
return 1;
fi
}

wait_pid_and_pidfile() {
i=0
while ! test -f "$2" && (( i < 25 )); do
while ! test -f "$2" && (( i < $timeout )); do
if ! kill -0 "$1" 2> /dev/null; then # kill -0 checks if process exists
break;
fi
[[ $verbose && ${3:-} ]] && echo "$3" >&2
sleep 0.1
((++i)) # don't do i++, that is a post increment operation, and will return status 1, since the expression evaluates to 0...
done
if (( i == 25 )); then
if (( i == $timeout )); then
# we timed out
return 1;
fi
Expand Down Expand Up @@ -143,6 +144,7 @@ print_help() {
is not given, then the port number to use is read from
the \$PORT environment variable, or a random port is
chosen if that variable does not exist.
-t <retries> Set start timeout
-v, --verbose Be more verbose during startup.

The <BPDIR> placeholder above represents the base directory of this buildpack:
Expand Down Expand Up @@ -192,7 +194,7 @@ export PHP_INI_SCAN_DIR="${PHP_INI_SCAN_DIR}${bp_dir}/conf/php/apm-nostart-overr
# init logs array here as empty before parsing options; -l could append to it, but the default list gets added later since we use $PORT in there and that can be set using -p
declare -a logs

optstring=":-:C:c:F:f:i:l:p:vh"
optstring=":-:C:c:F:f:i:l:p:t:vh"

# process flags first
while getopts "$optstring" opt; do
Expand Down Expand Up @@ -259,6 +261,9 @@ while getopts "$optstring" opt; do
p)
PORT="$OPTARG"
;;
t)
timeout=$OPTARG
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 2
Expand Down