github.com/drud/ddev@v1.21.5-alpha1.0.20230226034409-94fcc4b94453/containers/ddev-webserver/ddev-webserver-base-scripts/start.sh (about)

     1  #!/bin/bash
     2  set -x
     3  set -o errexit nounset pipefail
     4  
     5  rm -f /tmp/healthy
     6  
     7  export ENTRYPOINT=/mnt/ddev_config/web-entrypoint.d
     8  
     9  source /functions.sh
    10  
    11  # If user has not been created via normal template (like uid 999)
    12  # then try to grab the required files from /etc/skel
    13  if [ ! -f ~/.gitconfig ]; then (sudo cp -r /etc/skel/. ~/ && sudo chown -R "$(id -u -n)" ~ ) || true; fi
    14  
    15  # If DDEV_PHP_VERSION isn't set, use a reasonable default
    16  DDEV_PHP_VERSION="${DDEV_PHP_VERSION:-$PHP_DEFAULT_VERSION}"
    17  
    18  # If DDEV_WEBSERVER_TYPE isn't set, use a reasonable default
    19  DDEV_WEBSERVER_TYPE="${DDEV_WEBSERVER_TYPE:-nginx-fpm}"
    20  
    21  # Update the default PHP and FPM versions a DDEV_PHP_VERSION like '5.6' or '7.0' is provided
    22  # Otherwise it will use the default version configured in the Dockerfile
    23  if [ -n "$DDEV_PHP_VERSION" ] ; then
    24  	update-alternatives --set php /usr/bin/php${DDEV_PHP_VERSION}
    25  	ln -sf /usr/sbin/php-fpm${DDEV_PHP_VERSION} /usr/sbin/php-fpm
    26  	export PHP_INI=/etc/php/${DDEV_PHP_VERSION}/fpm/php.ini
    27  fi
    28  
    29  # Set PHP timezone to configured $TZ if there is one
    30  if [ ! -z ${TZ} ]; then
    31      perl -pi -e "s%date.timezone *=.*$%date.timezone = $TZ%g" $(find /etc/php -name php.ini)
    32  fi
    33  
    34  # If the user has provided custom PHP configuration, copy it into a directory
    35  # where PHP will automatically include it.
    36  if [ -d /mnt/ddev_config/php ] ; then
    37      # If there are files in the mount
    38      if [ -n "$(ls -A /mnt/ddev_config/php/*.ini 2>/dev/null)" ]; then
    39          cp /mnt/ddev_config/php/*.ini /etc/php/${DDEV_PHP_VERSION}/cli/conf.d/
    40          cp /mnt/ddev_config/php/*.ini /etc/php/${DDEV_PHP_VERSION}/fpm/conf.d/
    41      fi
    42  fi
    43  
    44  if [ -d /mnt/ddev_config/nginx_full ]; then
    45    rm -rf /etc/nginx/sites-enabled
    46    cp -r /mnt/ddev_config/nginx_full /etc/nginx/sites-enabled/
    47  fi
    48  if [ -d /mnt/ddev_config/apache ]; then
    49    rm -rf /etc/apache2/sites-enabled
    50    cp -r /mnt/ddev_config/apache /etc/apache2/sites-enabled
    51  fi
    52  
    53  if [ "$DDEV_PROJECT_TYPE" = "backdrop" ] ; then
    54      # Start can be executed when the container is already running.
    55      mkdir -p ~/.drush/commands && ln -s /var/tmp/backdrop_drush_commands ~/.drush/commands/backdrop
    56  fi
    57  
    58  if [ "${DDEV_PROJECT_TYPE}" = "drupal6" ] || [ "${DDEV_PROJECT_TYPE}" = "drupal7" ] || [ "${DDEV_PROJECT_TYPE}" = "backdrop" ]; then
    59    ln -sf /usr/local/bin/drush8 /usr/local/bin/drush
    60  fi
    61  
    62  # Change the apache run user to current user/group
    63  printf "\nexport APACHE_RUN_USER=$(id -un)\nexport APACHE_RUN_GROUP=$(id -gn)\n" >>/etc/apache2/envvars
    64  
    65  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
    66  a2enconf charset localized-error-pages other-vhosts-access-log security serve-cgi-bin
    67  
    68  if [ "$DDEV_WEBSERVER_TYPE" = "apache-fpm" ] ; then
    69      a2enmod proxy_fcgi
    70      a2enconf php${DDEV_PHP_VERSION}-fpm
    71      a2dissite 000-default
    72  fi
    73  
    74  # Disable xdebug by default. Users can enable with /usr/local/bin/enable_xdebug
    75  if [ "$DDEV_XDEBUG_ENABLED" = "true" ]; then
    76    enable_xdebug
    77  else
    78    disable_xdebug
    79  fi
    80  
    81  # Enable assertions by default.
    82  phpenmod assert
    83  
    84  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)
    85  
    86  # Make sure the TERMINUS_CACHE_DIR (/mnt/ddev-global-cache/terminus/cache) exists
    87  sudo mkdir -p ${TERMINUS_CACHE_DIR}
    88  
    89  sudo mkdir -p /mnt/ddev-global-cache/{bashhistory/${HOSTNAME},mysqlhistory/${HOSTNAME},nvm_dir/${HOSTNAME},npm,yarn/classic,yarn/berry}
    90  sudo chown -R "$(id -u):$(id -g)" /mnt/ddev-global-cache/ /var/lib/php
    91  # The following ensures a persistent and shared "global" cache for
    92  # yarn1 (classic) and yarn2 (berry). In the case of yarn2, the global cache
    93  # will only be used if the project is configured to use it through it's own
    94  # enableGlobalCache configuration option. Assumes ~/.yarn/berry as the default
    95  # global folder.
    96  ( (cd ~ || echo "unable to cd to home directory"; exit 22) && yarn config set cache-folder /mnt/ddev-global-cache/yarn/classic || true)
    97  # ensure default yarn2 global folder is there to symlink cache afterwards
    98  mkdir -p ~/.yarn/berry
    99  ln -sf /mnt/ddev-global-cache/yarn/berry ~/.yarn/berry/cache
   100  ln -sf /mnt/ddev-global-cache/nvm_dir/${HOSTNAME} ~/.nvm
   101  if [ ! -f ~/.nvm/nvm.sh ]; then (install_nvm.sh || true); fi
   102  
   103  # /mnt/ddev_config/.homeadditions may be either
   104  # a bind-mount, or a volume mount, but we don't care,
   105  # should all be set up with both global and local
   106  # either way.
   107  if [ -d /mnt/ddev_config/.homeadditions ]; then
   108      cp -r /mnt/ddev_config/.homeadditions/. ~/
   109  fi
   110  
   111  # It's possible CAROOT does not exist or is not writeable (if host-side mkcert -install not run yet)
   112  sudo mkdir -p ${CAROOT} && sudo chown -R "$(id -u):$(id -g)" /mnt/ddev-global-cache/
   113  # This will install the certs from $CAROOT (/mnt/ddev-global-cache/mkcert)
   114  # It also creates them if they don't already exist
   115  if [ ! -f  "${CAROOT}/rootCA.pem" ]; then
   116    echo "rootCA.pem not found in ${CAROOT}"
   117  fi
   118  mkcert -install
   119  
   120  # VIRTUAL_HOST is a comma-delimited set of fqdns, convert it to space-separated and mkcert
   121  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
   122  echo 'Server started'
   123  
   124  # We don't want the various daemons to know about PHP_IDE_CONFIG
   125  unset PHP_IDE_CONFIG
   126  
   127  # Run any custom init scripts (.ddev/.web-entrypoint.d/*.sh)
   128  if [ -d ${ENTRYPOINT} ]; then
   129    if [[ -n $(find ${ENTRYPOINT} -type f -regex ".*\.\(sh\)") ]] && [[ ! -f "${ENTRYPOINT}/.user_scripts_initialized" ]] ; then
   130      # For web-entrypoint.d to work with code already loaded, if mutagen is enabled,
   131      # the code may not yet be in /var/www/html, so boost it along early
   132      # The .start-synced file is created after mutagen sync is done, and deleted early
   133      # in `ddev start`.
   134      if [ "${DDEV_MUTAGEN_ENABLED}" = "true" ] && [ ! -f /var/www/html/.ddev/mutagen/.start-synced ]; then
   135        RSYNC_CMD="sudo rsync -a /var/tmp/html/ /var/www/html/"
   136        if [ "${DDEV_FILES_DIR:-}" != "" ]; then
   137          RSYNC_CMD="${RSYNC_CMD} --exclude ${DDEV_FILES_DIR#/var/www/html/} --exclude=.git --exclude=.tarballs --exclude=.idea"
   138        fi
   139        time ${RSYNC_CMD} || true
   140      fi
   141      ddev_custom_init_scripts;
   142    fi
   143  fi
   144  exec /usr/bin/supervisord -n -c "/etc/supervisor/supervisord-${DDEV_WEBSERVER_TYPE}.conf"