diff --git a/docker/init-docker b/docker/init-docker index ad3e720..00ce140 100755 --- a/docker/init-docker +++ b/docker/init-docker @@ -6,8 +6,10 @@ env=${APP_ENV:-production} php=${PHP_DIR:-/var/www/html} composer=${COMPOSER_HOME:-/var/cache/composer} +RUN_USER=$(id -u -n) SITE_USER=${SITE_USER:-www-data} MEMCACHED_START=${MEMCACHED_START:-FALSE} +[ "${RUN_USER}" = "deon" ] && USE_SU=1 # To run a local queue, running jobs from the queue "hostname" LOCAL_QUEUE=${LOCAL_QUEUE:-FALSE} @@ -87,7 +89,8 @@ if [ -r artisan -a -e ${php}/.env ]; then [ -n "${FORCE_PERMS}" -o "${env}" != "local" -a -z "${SKIP_PERM}" ] && chmod g+w ${php} fi - su ${SITE_USER} -s /bin/sh -c "composer install --optimize-autoloader ${NODEV}" && ( test -e .composer.refresh && rm -f .composer.refresh ) + CMD="composer install --optimize-autoloader ${NODEV}" + (( [ -n "${USE_SU}" ] && su ${SITE_USER} -s /bin/sh -c "${CMD}" ) || ${CMD}) && ( test -e .composer.refresh && rm -f .composer.refresh ) [ -n "${FORCE_PERMS}" -o "${env}" != "local" -a -z "${SKIP_PERM}" ] && [ ${mp} -eq 0 ] && chmod g-w ${php} fi @@ -95,7 +98,8 @@ if [ -r artisan -a -e ${php}/.env ]; then mp=$(mp ${php}) if [ ${mp} -eq 1 ]; then echo " - Caching configuration..." - su ${SITE_USER} -s /bin/sh -c "(php artisan optimize)" + CMD="php artisan optimize" + ( [ -n "${USE_SU}" ] && su ${SITE_USER} -s /bin/sh -c "${CMD}" ) || ${CMD} fi if [ "${role}" = "app" ]; then @@ -108,7 +112,8 @@ if [ -r artisan -a -e ${php}/.env ]; then wait_for_db - su ${SITE_USER} -s /bin/sh -c "php artisan migrate" && rm -f .migrate + CMD="php artisan migrate" + (( [ -n "${USE_SU}" ] && su ${SITE_USER} -s /bin/sh -c "${CMD}" ) || ${CMD}) && rm -f .migrate fi else [ -r .migrate ] && echo "! NOTE: Migration ignored due to IGNORE_MIGRATION" @@ -118,20 +123,20 @@ if [ -r artisan -a -e ${php}/.env ]; then if [ -d ${php}/vendor/laravel/passport ]; then echo " - Generating OAUTH keys ..." set +e - su ${SITE_USER} -s /bin/sh -c "php artisan passport:keys" + CMD="php artisan passport:keys" + ( [ -n "${USE_SU}" ] && su ${SITE_USER} -s /bin/sh -c "${CMD}" ) || ${CMD} set -e fi fi if [ "${LOCAL_QUEUE}" = "TRUE" ]; then echo " - Starting local queue for [$(hostname)${LOCAL_QUEUES:+,${LOCAL_QUEUES}}] with job timeout of [${WORK_TIMEOUT:-90}], trying [${WORK_TRIES:-1}] times..." - su ${SITE_USER} -s /bin/sh -c " - (while true; do php ${PHP_OPTIONS} artisan queue:work --verbose --tries=${WORK_TRIES:-1} --timeout=${WORK_TIMEOUT:-90} --queue=$(hostname)${LOCAL_QUEUES:+,${LOCAL_QUEUES}} ${WORK_MEMORY:+--memory=${WORK_MEMORY}} ${WORK_ONCE:+--once}; done) & - " + CMD="(while true; do php ${PHP_OPTIONS} artisan queue:work --verbose --tries=${WORK_TRIES:-1} --timeout=${WORK_TIMEOUT:-90} --queue=$(hostname)${LOCAL_QUEUES:+,${LOCAL_QUEUES}} ${WORK_MEMORY:+--memory=${WORK_MEMORY}} ${WORK_ONCE:+--once}; done) &" + ( [ -n "${USE_SU}" ] && su ${SITE_USER} -s /bin/sh -c "${CMD}" ) || ${CMD} fi set +e - [ -x init-php.sh ] && su ${SITE_USER} -s /bin/sh "init-php.sh" & + [ -x init-php.sh ] && (( [ -n "${USE_SU}" ] && su ${SITE_USER} -s /bin/sh -c "init-php.sh &" ) || init-php.sh &) exec /usr/local/bin/docker-php-entrypoint "$@" @@ -148,22 +153,16 @@ if [ -r artisan -a -e ${php}/.env ]; then wait_for_db - su ${SITE_USER} -s /bin/sh -c " - while true; do - php ${PHP_OPTIONS} artisan queue:${QUEUE_CMD} --verbose --tries=${WORK_TRIES:-1} --timeout=${WORK_TIMEOUT:-90} ${WORK_QUEUES:+--queue=${WORK_QUEUES}} ${WORK_MEMORY:+--memory=${WORK_MEMORY}} ${WORK_ONCE:+--once} - done - " + CMD="while true; do php ${PHP_OPTIONS} artisan queue:${QUEUE_CMD} --verbose --tries=${WORK_TRIES:-1} --timeout=${WORK_TIMEOUT:-90} ${WORK_QUEUES:+--queue=${WORK_QUEUES}} ${WORK_MEMORY:+--memory=${WORK_MEMORY}} ${WORK_ONCE:+--once}; done" + ( [ -n "${USE_SU}" ] && su ${SITE_USER} -s /bin/sh -c "${CMD}" ) || ${CMD} elif [ "$role" = "scheduler" ]; then echo " - Running the scheduler..." # We'll delay starting in case the app is caching sleep 15 - su ${SITE_USER} -s /bin/sh -c " - while true; do - php ${PHP_OPTIONS} artisan schedule:work --verbose --no-interaction - done - " + CMD="while true; do php ${PHP_OPTIONS} artisan schedule:work --verbose --no-interaction; done" + ( [ -n "${USE_SU}" ] && su ${SITE_USER} -s /bin/sh -c "${CMD}" ) || ${CMD} fi else