github.com/ddev/ddev@v1.23.2-0.20240519125000-d824ffe36ff3/containers/ddev-webserver/ddev-webserver-prod-scripts/start.sh (about)

     1  #!/bin/bash
     2  set -x
     3  set -o errexit nounset pipefail
     4  
     5  rm -f /tmp/healthy
     6  
     7  # If supervisord happens to be running (ddev start when already running) then kill it off
     8  if pkill -0 supervisord; then
     9    supervisorctl stop all || true
    10    supervisorctl shutdown || true
    11  fi
    12  rm -f /var/run/supervisor.sock
    13  
    14  export DDEV_WEB_ENTRYPOINT=/mnt/ddev_config/web-entrypoint.d
    15  
    16  source /functions.sh
    17  
    18  # If user has not been created via normal template (like blackfire uid 999)
    19  # then try to grab the required files from /etc/skel
    20  if [ ! -f ~/.gitconfig ]; then cp -r /etc/skel/. ~/ || true; fi
    21  
    22  # If DDEV_PHP_VERSION isn't set, use a reasonable default
    23  DDEV_PHP_VERSION="${DDEV_PHP_VERSION:-$PHP_DEFAULT_VERSION}"
    24  
    25  # If DDEV_WEBSERVER_TYPE isn't set, use a reasonable default
    26  DDEV_WEBSERVER_TYPE="${DDEV_WEBSERVER_TYPE:-nginx-fpm}"
    27  
    28  # Update the default PHP and FPM versions a DDEV_PHP_VERSION like '5.6' or '7.0' is provided
    29  # Otherwise it will use the default version configured in the Dockerfile
    30  if [ -n "$DDEV_PHP_VERSION" ] ; then
    31  	update-alternatives --set php /usr/bin/php${DDEV_PHP_VERSION}
    32  	ln -sf /usr/sbin/php-fpm${DDEV_PHP_VERSION} /usr/sbin/php-fpm
    33  	export PHP_INI=/etc/php/${DDEV_PHP_VERSION}/fpm/php.ini
    34  fi
    35  
    36  # Set PHP timezone to configured $TZ if there is one
    37  if [ ! -z ${TZ} ]; then
    38      perl -pi -e "s%date.timezone *=.*$%date.timezone = $TZ%g" $(find /etc/php -name php.ini)
    39  fi
    40  
    41  # If the user has provided custom PHP configuration, copy it into a directory
    42  # where PHP will automatically include it.
    43  if [ -d /mnt/ddev_config/php ] ; then
    44      # If there are files in the mount
    45      if [ -n "$(ls -A /mnt/ddev_config/php/*.ini 2>/dev/null)" ]; then
    46          cp /mnt/ddev_config/php/*.ini /etc/php/${DDEV_PHP_VERSION}/cli/conf.d/
    47          cp /mnt/ddev_config/php/*.ini /etc/php/${DDEV_PHP_VERSION}/fpm/conf.d/
    48      fi
    49  fi
    50  
    51  if [ -d /mnt/ddev_config/nginx_full ]; then
    52    rm -rf /etc/nginx/sites-enabled
    53    cp -r /mnt/ddev_config/nginx_full /etc/nginx/sites-enabled/
    54  fi
    55  if [ -d /mnt/ddev_config/apache ]; then
    56    rm -rf /etc/apache2/sites-enabled
    57    cp -r /mnt/ddev_config/apache /etc/apache2/sites-enabled
    58  fi
    59  
    60  if [ "$DDEV_PROJECT_TYPE" = "backdrop" ] ; then
    61      # Start can be executed when the container is already running.
    62      mkdir -p ~/.drush/commands && ln -sf /var/tmp/backdrop_drush_commands ~/.drush/commands/backdrop
    63  fi
    64  
    65  if [ "${DDEV_PROJECT_TYPE}" = "drupal6" ] || [ "${DDEV_PROJECT_TYPE}" = "drupal7" ] || [ "${DDEV_PROJECT_TYPE}" = "backdrop" ]; then
    66    ln -sf /usr/local/bin/drush8 /usr/local/bin/drush
    67  fi
    68  
    69  # Change the apache run user to current user/group
    70  printf "\nexport APACHE_RUN_USER=$(id -un)\nexport APACHE_RUN_GROUP=$(id -gn)\n" >>/etc/apache2/envvars
    71  
    72  a2enmod access_compat alias auth_basic authn_core authn_file authz_core authz_host authz_user autoindex deflate dir env filter mime mpm_prefork negotiation reqtimeout rewrite setenvif status
    73  a2enconf charset localized-error-pages other-vhosts-access-log security serve-cgi-bin
    74  
    75  if [ "$DDEV_WEBSERVER_TYPE" = "apache-fpm" ] ; then
    76      a2enmod proxy_fcgi
    77      a2enconf php${DDEV_PHP_VERSION}-fpm
    78      a2dissite 000-default
    79  fi
    80  
    81  # Disable xdebug by default. Users can enable with /usr/local/bin/enable_xdebug
    82  if [ "$DDEV_XDEBUG_ENABLED" = "true" ]; then
    83    enable_xdebug
    84  else
    85    disable_xdebug
    86  fi
    87  
    88  # Disable xhprof by default. Users can enable with /usr/local/bin/enable_xhprof
    89  disable_xhprof
    90  
    91  ls /var/www/html >/dev/null || (echo "/var/www/html does not seem to be healthy/mounted; docker may not be mounting it., exiting" && exit 101)
    92  
    93  mkdir -p /mnt/ddev-global-cache/{bashhistory/${HOSTNAME},mysqlhistory/${HOSTNAME},nvm_dir/${HOSTNAME},npm,yarn/classic,yarn/berry,corepack}
    94  
    95  # The following ensures a persistent and shared "global" cache for
    96  # yarn1 (classic) and yarn2 (berry). In the case of yarn2, the global cache
    97  # will only be used if the project is configured to use it through it's own
    98  # enableGlobalCache configuration option. Assumes ~/.yarn/berry as the default
    99  # global folder.
   100  ( (cd ~ || echo "unable to cd to home directory"; exit 22) && yarn config set cache-folder /mnt/ddev-global-cache/yarn/classic || true)
   101  # ensure default yarn2 global folder is there to symlink cache afterwards
   102  mkdir -p ~/.yarn/berry
   103  ln -sf /mnt/ddev-global-cache/yarn/berry ~/.yarn/berry/cache
   104  ln -sf /mnt/ddev-global-cache/nvm_dir/${HOSTNAME} ~/.nvm
   105  if [ ! -f ~/.nvm/nvm.sh ]; then (timeout 30 install_nvm.sh || true); fi
   106  
   107  # chown of ddev-global-cache must be done with privileged container in app.Start()
   108  # chown -R "$(id -u):$(id -g)" /mnt/ddev-global-cache/
   109  
   110  if [ -d /mnt/ddev_config/.homeadditions ]; then
   111      cp -r /mnt/ddev_config/.homeadditions/. ~/
   112  fi
   113  
   114  # It's possible CAROOT does not exist or is not writeable (if host-side mkcert -install not run yet)
   115  mkdir -p ${CAROOT}
   116  # This will install the certs from $CAROOT (/mnt/ddev-global-cache/mkcert)
   117  mkcert -install
   118  
   119  # VIRTUAL_HOST is a comma-delimited set of fqdns, convert it to space-separated and mkcert
   120  CAROOT=$CAROOT mkcert -cert-file /etc/ssl/certs/master.crt -key-file /etc/ssl/certs/master.key ${VIRTUAL_HOST//,/ } localhost 127.0.0.1 ${DOCKER_IP} web ddev-${DDEV_PROJECT:-}-web ddev-${DDEV_PROJECT:-}-web.ddev
   121  echo 'Server started'
   122  
   123  # We don't want the various daemons to know about PHP_IDE_CONFIG
   124  unset PHP_IDE_CONFIG
   125  
   126  # Run any python/django4 activities.
   127  ddev_python_setup
   128  
   129  # Run any custom init scripts (.ddev/.web-entrypoint.d/*.sh)
   130  ddev_custom_init_scripts
   131  
   132  # Make sure /var/tmp/logpipe gets logged; only for standalone non-ddev usages
   133  logpipe=/var/tmp/logpipe
   134  if [[ ! -p ${logpipe} ]]; then
   135      mkfifo ${logpipe}
   136      cat < ${logpipe} >/proc/1/fd/1 &
   137  fi
   138  
   139  exec /usr/bin/supervisord -n -c "/etc/supervisor/supervisord-${DDEV_WEBSERVER_TYPE}.conf"