From 1ebfedcfb59102a6ae67050e5154c19bab0144df Mon Sep 17 00:00:00 2001 From: Michael Hobbs Date: Wed, 16 Sep 2015 15:33:01 -0700 Subject: [PATCH 1/2] [ci skip] make the default scaling logic clearer --- docs/process-management.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/process-management.md b/docs/process-management.md index ca0510f05..7a1380477 100644 --- a/docs/process-management.md +++ b/docs/process-management.md @@ -15,7 +15,7 @@ ps:stop Stop app container(s) ## Scaling -Dokku allows you to run multiple process types at different container counts. For example, if you had an app that contained 1 web app listener and 1 background job processor, dokku can, spin up 1 container for each process type defined in the Procfile. *By default, dokku will only start a single web process.* However, if you wanted 2 job processors running simultaneously, you can modify this behavior in a few ways. +Dokku allows you to run multiple process types at different container counts. For example, if you had an app that contained 1 web app listener and 1 background job processor, dokku can, spin up 1 container for each process type defined in the Procfile. *By default, dokku will only start a single web process (if defined.)* However, if you wanted, for example, 2 job processors running simultaneously, you can modify this behavior in one of the following ways. ### DOKKU_SCALE file From c8b8b9bb930059acad58a70b0b5e2f55bda0889d Mon Sep 17 00:00:00 2001 From: Michael Hobbs Date: Wed, 16 Sep 2015 17:15:06 -0700 Subject: [PATCH 2/2] generate DOKKU_SCALE based on Procfile if DOKKU_SCALE is not found. closes #1442 --- plugins/ps/commands | 17 ++++++++++++----- plugins/ps/functions | 22 ++++++++++++++++++---- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/plugins/ps/commands b/plugins/ps/commands index 271816ee8..d9614c623 100755 --- a/plugins/ps/commands +++ b/plugins/ps/commands @@ -90,10 +90,17 @@ case "$1" in DOKKU_SCALE_FILE="$DOKKU_ROOT/$APP/DOKKU_SCALE" shift 2 - generate_scale_file "$APP" "$IMAGE_TAG" - if [[ -z "$@" ]]; then - dokku_log_info1 "Scaling for $APP" - dokku_log_info2 "$(< $DOKKU_SCALE_FILE)" + [[ ! -e $DOKKU_SCALE_FILE ]] && generate_scale_file "$APP" "$IMAGE_TAG" + if [[ -z "$@" ]];then + dokku_log_info1_quiet "Scaling for $APP" + dokku_col_log_info1_quiet "proctype" "qty" + dokku_col_log_info1_quiet "--------" "---" + while read line || [[ -n "$line" ]]; do + [[ -z "$line" ]] && continue + PROC_NAME=${line%%=*} + PROC_COUNT=${line#*=} + dokku_col_log_info1 "$PROC_NAME" "$PROC_COUNT" + done < "$DOKKU_SCALE_FILE" else set_scale "$APP" "$@" release_and_deploy "$APP" "$IMAGE_TAG" @@ -103,7 +110,7 @@ case "$1" in help | ps:help) cat<, List processes running in app container(s) - ps:scale = [=], Set how many instances of a given process to run + ps:scale [ = [=]], Get/Set how many instances of a given process to run ps:start , Start app container(s) ps:stop , Stop app container(s) ps:rebuild , Rebuild an app diff --git a/plugins/ps/functions b/plugins/ps/functions index 47961de76..eafc19916 100755 --- a/plugins/ps/functions +++ b/plugins/ps/functions @@ -15,15 +15,29 @@ generate_scale_file() { copy_from_image "$IMAGE" "/app/DOKKU_SCALE" "$DOKKU_ROOT/$APP" 2>/dev/null || true if [[ ! -f $DOKKU_SCALE_FILE ]]; then - dokku_log_info1_quiet "DOKKU_SCALE file not found in app image. Defaulting to a single web process" - echo "web=1" >> $DOKKU_SCALE_FILE + dokku_log_info1_quiet "DOKKU_SCALE file not found in app image. Generating one based on Procfile..." + TMP_WORK_DIR=$(mktemp -d) + trap 'rm -rf "$TMP_WORK_DIR" > /dev/null' RETURN + + copy_from_image "$IMAGE" "/app/Procfile" "$TMP_WORK_DIR" 2>/dev/null || true + local PROCFILE="$TMP_WORK_DIR/Procfile" + if [[ ! -e "$PROCFILE" ]]; then + echo "web=1" >> $DOKKU_SCALE_FILE + else + while read line || [[ -n "$line" ]]; do + [[ -z "$line" ]] && continue + NAME=${line%%:*} + NUM_PROCS=0 + [[ "$NAME" == "web" ]] && NUM_PROCS=1 + echo "$NAME=$NUM_PROCS" >> $DOKKU_SCALE_FILE + done < "$PROCFILE" + fi dokku_log_info1_quiet "New DOKKU_SCALE file generated" - else dokku_log_info1_quiet "DOKKU_SCALE file found" - print_dokku_scale_file $APP fi + print_dokku_scale_file $APP } set_scale() {