Changed NO_NGINX to NGINX_START, added REDIS/MEMCACHED startup

This commit is contained in:
Deon George 2021-06-09 12:12:06 +10:00
parent 45d16b63cb
commit 1111afcb5f
2 changed files with 22 additions and 6 deletions

View File

@ -34,7 +34,10 @@ RUN apt-get update && apt-get install -y openssh-server libpq5 libpq-dev unzip g
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# Enable phpredis # Enable phpredis
RUN pecl install -o -f igbinary && pecl install -o -f redis && docker-php-ext-enable redis igbinary && rm -rf /tmp/* RUN apt-get update && apt-get install -y redis \
&& pecl install -o -f igbinary && pecl install -o -f redis && docker-php-ext-enable redis igbinary \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# Enable phpmemcache # Enable phpmemcache
RUN apt-get update && apt-get install -y memcached libmemcachedutil2 zlib1g-dev libmemcached-dev \ RUN apt-get update && apt-get install -y memcached libmemcachedutil2 zlib1g-dev libmemcached-dev \

23
init
View File

@ -6,12 +6,14 @@ env=${APP_ENV:-live}
php=${PHP_DIR:-/var/www/html} php=${PHP_DIR:-/var/www/html}
composer=${COMPOSER_DIR:-/var/www/.composer} composer=${COMPOSER_DIR:-/var/www/.composer}
NO_NGINX=${NO_NGINX:-TRUE} NGINX_START=${NGINX_START:-TRUE}
SSH_START=${SSH_START:-FALSE} SSH_START=${SSH_START:-FALSE}
REDIS_START=${SSH_START:-FALSE}
# To run a local queue, running jobs from the queue "hostname" # To run a local queue, running jobs from the queue "hostname"
LOCAL_QUEUE=${LOCAL_QUEUE:-FALSE} LOCAL_QUEUE=${LOCAL_QUEUE:-FALSE}
#LOCAL_QUEUES= Optional additional queues to run for # Optional additional queues to run for
#LOCAL_QUEUES=
function mp() { function mp() {
set +e set +e
@ -23,18 +25,26 @@ function mp() {
function nginx_start() { function nginx_start() {
# Start NGINX # Start NGINX
if [ -x /usr/sbin/nginx -a "${NO_NGINX}" != "TRUE" ]; then if [ -x /usr/sbin/nginx -a "${NGINX_START}" == "TRUE" ]; then
echo "* Starting NGINX..." echo "* Starting NGINX..."
start-stop-daemon --start --pidfile /var/run/nginx.pid --exec /usr/sbin/nginx -- -g 'daemon on; master_process on;' start-stop-daemon --start --pidfile /var/run/nginx.pid --exec /usr/sbin/nginx -- -g 'daemon on; master_process on;'
fi fi
} }
# General Setup # General Setup
if [ -x /usr/sbin/sshd -a "${SSH_START}" = "TRUE" ]; then if [ -x /usr/sbin/sshd -a "${SSH_START}" == "TRUE" ]; then
[ ! -d /var/run/sshd ] && mkdir /var/run/sshd [ ! -d /var/run/sshd ] && mkdir /var/run/sshd
start-stop-daemon --start --pidfile /var/run/sshd.pid --exec /usr/sbin/sshd -- -p 22 start-stop-daemon --start --pidfile /var/run/sshd.pid --exec /usr/sbin/sshd -- -p 22
fi fi
if [ -x /usr/bin/redis-server -a "${REDIS_START}" == "TRUE" ]; then
start-stop-daemon --start --quiet --oknodo --umask 007 --pidfile /var/run/redis-server.pid --chuid redis:redis --exec /usr/bin/redis-server -- /etc/redis/redis.conf
fi
if [ -x /usr/bin/memcached -a "${REDIS_START}" == "TRUE" ]; then
start-stop-daemon --start --quiet --exec "/usr/share/memcached/scripts/start-memcached" -- /etc/memcached.conf /var/run/memcached.pid
fi
# Laravel Specific # Laravel Specific
if [ "${role}" = "app" -a -e artisan ]; then if [ "${role}" = "app" -a -e artisan ]; then
if [ ! -e ${php}/.env ]; then if [ ! -e ${php}/.env ]; then
@ -62,6 +72,8 @@ if [ "${role}" = "app" -a -e artisan ]; then
if [ "${env}" != "local" -a -r "artisan" ]; then if [ "${env}" != "local" -a -r "artisan" ]; then
# See if we need to refresh our dependancies # See if we need to refresh our dependancies
if [[ -r composer.json && ( -e .composer.refresh || ! -d vendor ) ]]; then if [[ -r composer.json && ( -e .composer.refresh || ! -d vendor ) ]]; then
echo "* Composer installing dependancies..."
rm -f ${php}/bootstrap/cache/*.php rm -f ${php}/bootstrap/cache/*.php
if [ "${env}" != "local" ]; then if [ "${env}" != "local" ]; then
NODEV="--no-dev" NODEV="--no-dev"
@ -110,8 +122,9 @@ if [ "${role}" = "app" -a -e artisan ]; then
fi fi
nginx_start nginx_start
if [ "${LOCAL_QUEUE}" = "TRUE" ]; then if [ "${LOCAL_QUEUE}" = "TRUE" ]; then
echo "* Starting local queue for [${LOCAL_QUEUES}]..." echo "* Starting local queue for [$(hostname)${LOCAL_QUEUES:+,${LOCAL_QUEUES}}] with job timeout of [${WORK_TIMEOUT:-90}], trying [${WORK_TRIES:-1}] times..."
su www-data -s /bin/sh -c " su www-data -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) & (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) &
" "