github.com/drud/ddev@v1.21.5-alpha1.0.20230226034409-94fcc4b94453/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 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 blackfire uid 999) 12 # then try to grab the required files from /etc/skel 13 if [ ! -f ~/.gitconfig ]; then cp -r /etc/skel/. ~/ || 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 # Disable xhprof by default. Users can enable with /usr/local/bin/enable_xhprof 82 disable_xhprof 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 mkdir -p /mnt/ddev-global-cache/{bashhistory/${HOSTNAME},mysqlhistory/${HOSTNAME},nvm_dir/${HOSTNAME},npm,yarn/classic,yarn/berry} 87 ln -sf /mnt/ddev-global-cache/nvm_dir/${HOSTNAME} ~/.nvm 88 if [ ! -f ~/.nvm/nvm.sh ]; then (install_nvm.sh || true); fi 89 90 # The following ensures a persistent and shared "global" cache for 91 # yarn1 (classic) and yarn2 (berry). In the case of yarn2, the global cache 92 # will only be used if the project is configured to use it through it's own 93 # enableGlobalCache configuration option. Assumes ~/.yarn/berry as the default 94 # global folder. 95 ( (cd ~ || echo "unable to cd to home directory"; exit 22) && yarn config set cache-folder /mnt/ddev-global-cache/yarn/classic || true) 96 # ensure default yarn2 global folder is there to symlink cache afterwards 97 mkdir -p ~/.yarn/berry 98 ln -sf /mnt/ddev-global-cache/yarn/berry ~/.yarn/berry/cache 99 ln -sf /mnt/ddev-global-cache/nvm_dir/${HOSTNAME} ~/.nvm 100 if [ ! -f ~/.nvm/nvm.sh ]; then (install_nvm.sh || true); fi 101 102 # chown of ddev-global-cache must be done with privileged container in app.Start() 103 # chown -R "$(id -u):$(id -g)" /mnt/ddev-global-cache/ 104 105 if [ -d /mnt/ddev_config/.homeadditions ]; then 106 cp -r /mnt/ddev_config/.homeadditions/. ~/ 107 fi 108 109 # It's possible CAROOT does not exist or is not writeable (if host-side mkcert -install not run yet) 110 mkdir -p ${CAROOT} 111 # This will install the certs from $CAROOT (/mnt/ddev-global-cache/mkcert) 112 mkcert -install 113 114 # VIRTUAL_HOST is a comma-delimited set of fqdns, convert it to space-separated and mkcert 115 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 116 echo 'Server started' 117 118 # We don't want the various daemons to know about PHP_IDE_CONFIG 119 unset PHP_IDE_CONFIG 120 121 if [ -d ${ENTRYPOINT} ]; then 122 if [[ -n $(find ${ENTRYPOINT} -type f -regex ".*\.\(sh\)") ]] && [[ ! -f "${ENTRYPOINT}/.user_scripts_initialized" ]] ; then 123 # For web-entrypoint.d to work with code already loaded, if mutagen is enabled, 124 # the code may not yet be in /var/www/html, so boost it along early 125 # The .start-synced file is created after mutagen sync is done, and deleted early 126 # in `ddev start`. 127 if [ "${DDEV_MUTAGEN_ENABLED}" = "true" ] && [ ! -f /var/www/html/.ddev/mutagen/.start-synced ]; then 128 RSYNC_CMD="sudo rsync -a /var/tmp/html/ /var/www/html/" 129 if [ "${DDEV_FILES_DIR:-}" != "" ]; then 130 RSYNC_CMD="${RSYNC_CMD} --exclude ${DDEV_FILES_DIR#/var/www/html/} --exclude=.git --exclude=.tarballs --exclude=.idea" 131 fi 132 time ${RSYNC_CMD} || true 133 fi 134 ddev_custom_init_scripts; 135 fi 136 fi 137 exec /usr/bin/supervisord -n -c "/etc/supervisor/supervisord-${DDEV_WEBSERVER_TYPE}.conf"