Last active
June 1, 2016 21:50
-
-
Save khalib/890265a112e61b049df3 to your computer and use it in GitHub Desktop.
Dev Sandbox Deploy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ########### | |
| # LOCAL # | |
| ########### | |
| # Copy Acquia ssh key for Git access. | |
| scp -i ~/.ssh/cs_education.key ~/.ssh/acquia_graphite_rs* root@ec2-54-215-27-192.us-west-1.compute.amazonaws.com:/root/.ssh/ | |
| ############ | |
| # SERVER # | |
| ############ | |
| # Change ssh key access. | |
| chmod 600 ~/.ssh/acquia_graphite_rs* | |
| # Prepare the mount. | |
| mkfs -t xfs /dev/sdf1 | |
| mkdir /mnt/soma | |
| mount -t xfs /dev/sdf1 /mnt/soma | |
| # Create folders. | |
| mkdir -p /mnt/soma/data | |
| mkdir -p /mnt/soma/source/graphite | |
| mkdir -p /mnt/soma/assets/graphite/files | |
| mkdir -p /opt/www/ | |
| mkdir -p /etc/nginx/sites-available | |
| mkdir -p /etc/nginx/sites-enabled | |
| # Simlink nginx source folder. | |
| ln -s /mnt/soma/source/graphite/ /opt/www/graphite | |
| # Install drush. | |
| cd /tmp | |
| wget http://ftp.drupal.org/files/projects/drush-7.x-5.9.tar.gz | |
| tar -zxf drush-7.x-5.9.tar.gz -C /opt/www/graphite/ | |
| rm -rf /tmp/drush-7.x-5.9.tar.gz | |
| # Set bash profile. | |
| echo 'export INSTANCE_COUNT=5 | |
| alias s-stop="service nginx stop; service php-fpm stop; service mysql stop; service memcached stop;" | |
| alias s-start="service nginx start; service php-fpm start; service mysql start; service memcached start;" | |
| alias s-reload="service nginx stop; service php-fpm stop; service mysql stop; service memcached stop; service nginx start; service php-fpm start; service mysql start; service memcached start;" | |
| alias sync-assets-graphite="time rsync -av --exclude=js --exclude=advagg_css --exclude=advagg_js --exclude=css --exclude=imagecache --exclude=migrations csmgraphite@graphite-acquia:/mnt/files/csmgraphite.prod/sites/default/files/ /mnt/soma/assets/graphite/files; wait; chmod -R 777 /mnt/soma/assets/graphite/files;" | |
| alias drush="php /opt/www/graphite/drush/drush.php"' >> ~/.bash_profile | |
| source ~/.bash_profile | |
| # Remove packages. | |
| yum -y remove httpd* | |
| yum -y remove php* | |
| yum -y remove mysql* | |
| # Install packages. | |
| # https://gist.github.com/mywarr/5611352 | |
| rpm -Uvh http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm | |
| rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-5.rpm | |
| yum -y install nginx | |
| yum -y install memcached | |
| yum -y --enablerepo=remi,remi-test install nginx php-fpm php-common | |
| yum -y --enablerepo=remi install php-pecl-apc php-cli php-soap php-pear php-pdo php-mysql php-pgsql php-pecl-mongo php-sqlite php-pecl-memcache php-pecl-memcached php-gd php-mbstring php-mcrypt php-xml | |
| yum -y install mysql-client | |
| # Configure nginx. | |
| sed -i "s/*.conf;/*.conf;\n include \/etc\/nginx\/sites-enabled\/*;/" /etc/nginx/nginx.conf | |
| # Move and simlink mysql data to the mount. | |
| s-stop | |
| mv /var/lib/mysql /mnt/soma/data/ | |
| ln -s /mnt/soma/data/mysql /var/lib/mysql | |
| chown -R mysql:mysql /var/lib/mysql | |
| s-start | |
| # Create config file for git. | |
| echo 'Host graphite-acquia-git | |
| Hostname svn-3224.prod.hosting.acquia.com | |
| User csmgraphite | |
| IdentityFile ~/.ssh/acquia_graphite_rs | |
| Host graphite-acquia | |
| Hostname web-5921.prod.hosting.acquia.com | |
| User csmgraphite | |
| IdentityFile ~/.ssh/acquia_graphite_rs' > ~/.ssh/config | |
| # Create dev instances. | |
| for i in $(seq 1 $INSTANCE_COUNT) | |
| do | |
| # Clone source code. | |
| git clone csmgraphite@graphite-acquia-git:csmgraphite.git /mnt/soma/source/graphite/dev${i}; wait; | |
| # Setup nginx config. | |
| echo "server { | |
| listen 80; | |
| server_name dev${i}.graphite.org; | |
| access_log /var/log/nginx/dev${i}.graphite.access.log; | |
| error_log /var/log/nginx/dev${i}.graphite.error.log; | |
| root /opt/www/graphite/dev${i}/docroot; | |
| location / { | |
| try_files \$uri @rewrite; | |
| auth_basic "Restricted Area"; | |
| auth_basic_user_file /opt/www/graphite/.htpasswd; | |
| } | |
| location @rewrite { | |
| rewrite ^/(.*)\$ /index.php?q=\$1 last; | |
| } | |
| location ~ .php\$ { | |
| fastcgi_pass 127.0.0.1:9000; | |
| fastcgi_index index.php; | |
| fastcgi_param SCRIPT_FILENAME /opt/www/graphite/dev${i}/docroot\$fastcgi_script_name; | |
| include fastcgi_params; | |
| } | |
| }" > /etc/nginx/sites-available/dev${i}.graphite.org | |
| ln -s /etc/nginx/sites-available/dev${i}.graphite.org /etc/nginx/sites-enabled/dev${i}.graphite.org | |
| # Create drupal host setting. | |
| mkdir -p /opt/www/graphite/dev${i}/docroot/sites/dev${i}.graphite.org | |
| cp /opt/www/graphite/dev${i}/docroot/sites/graphite.org/settings.php /opt/www/graphite/dev${i}/docroot/sites/dev${i}.graphite.org/ | |
| ln -s /opt/www/graphite/dev${i}/docroot/sites/graphite.org/modules /opt/www/graphite/dev${i}/docroot/sites/dev${i}.graphite.org/ | |
| ln -s /opt/www/graphite/dev${i}/docroot/sites/graphite.org/libraries /opt/www/graphite/dev${i}/docroot/sites/dev${i}.graphite.org/ | |
| # Modify the settings.php file | |
| sed -i "s/'database' => 'csmgraphite'/'database' => 'graphite_dev${i}'/" /opt/www/graphite/dev${i}/docroot/sites/dev${i}.graphite.org/settings.php | |
| sed -i "s/'username' => 'csmgraphite'/'username' => 'graphite'/" /opt/www/graphite/dev${i}/docroot/sites/dev${i}.graphite.org/settings.php | |
| sed -i "s/'password' => 'JCxoSQTtbuJ2cXS'/'password' => 'graphite'/" /opt/www/graphite/dev${i}/docroot/sites/dev${i}.graphite.org/settings.php | |
| sed -i "s/'host' => 'fsdb-5919.prod.hosting.acquia.com'/'host' => 'localhost'/" /opt/www/graphite/dev${i}/docroot/sites/dev${i}.graphite.org/settings.php | |
| sed -i "s/\['memcache_key_prefix'] = 'd7'/\['memcache_key_prefix'] = 'graphite-dev${i}'/" /opt/www/graphite/dev${i}/docroot/sites/dev${i}.graphite.org/settings.php | |
| echo "ini_set('memory_limit', '1024M'); | |
| error_reporting(E_ERROR | E_WARNING | E_PARSE); | |
| ini_set('display_errors', 1); | |
| set_time_limit(120);" >> /opt/www/graphite/dev${i}/docroot/sites/dev${i}.graphite.org/settings.php | |
| # Create simlink to assets. | |
| ln -s /mnt/soma/assets/graphite/files /opt/www/graphite/dev${i}/docroot/sites/default/files | |
| # Add domain settings to the git exclude. | |
| echo "docroot/sites/dev${i}.graphite.org" >> /opt/www/graphite/dev${i}/.git/info/exclude | |
| done | |
| # Modify MySQL config. | |
| sed -i "s/socket=\/var\/lib\/mysql\/mysql.sock/socket=\/var\/lib\/mysql\/mysql.sock\nmax_allowed_packet = 128M/" /etc/my.cnf | |
| # Reload services. | |
| s-reload | |
| # MySQL setup. | |
| mysql -e "CREATE USER 'graphite'@'localhost' IDENTIFIED BY 'graphite'" | |
| DB_DATE=$(date +'%m/%d/%Y') | |
| IFS='/' read -a db_date <<< "$DB_DATE" | |
| DB_FILE="prod-csmgraphite-csmgraphite-${db_date[2]}-${db_date[0]}-${db_date[1]}.sql" | |
| # Download the database. | |
| time scp -i ~/.ssh/acquia_rs_server csmgraphite.prod@web-5921.prod.hosting.acquia.com:/mnt/files/csmgraphite.prod/backups/${DB_FILE}.gz /tmp/${DB_FILE}.gz; wait; | |
| time gunzip /tmp/${DB_FILE}.gz; wait; | |
| for i in $(seq 1 $INSTANCE_COUNT) | |
| do | |
| DB_NAME="graphite_dev${i}" | |
| mysql -e "DROP DATABASE ${DB_NAME}; GRANT ALL ON ${DB_NAME}.* TO 'graphite'@'localhost';"; wait; | |
| mysql -e "CREATE DATABASE ${DB_NAME}; GRANT ALL ON ${DB_NAME}.* TO 'graphite'@'localhost';"; wait; | |
| time mysql ${DB_NAME} < /tmp/${DB_FILE}; wait; | |
| # Run some drush for each instance. | |
| cd /opt/www/graphite/dev${i}/docroot/ | |
| drush -l dev${i}.graphite.org vset preprocess_js 0 --yes; wait; | |
| drush -l dev${i}.graphite.org vset preprocess_css 0 --yes; wait; | |
| drush -l dev${i}.graphite.org pm-disable -y masquerade; wait; | |
| drush -l dev${i}.graphite.org pm-disable -y cdn; wait; | |
| drush -l dev${i}.graphite.org vset honeypot_time_limit 0 --yes; wait; | |
| drush -l dev${i}.graphite.org vset error_level 2 --yes; wait; | |
| drush -l dev${i}.graphite.org vset csm_migration_d6_hostname local.csm.org --yes; wait; | |
| drush -l dev${i}.graphite.org vset tlr_csm_sync_csm_api_host local.csm.org --yes; wait; | |
| drush -l dev${i}.graphite.org php-eval "variable_set('csm_api_info', array('hostname' => 'https://graphite-api-dev.commonsense.org', 'clientId' => 'b13a2cfd6b5b0085d35843b9d3aaf6ec', 'appId' => '1c34a90620e2a4015b3b0439cadf5da3'))"; wait; | |
| drush -l dev${i}.graphite.org cc all; wait; | |
| done | |
| rm -rf /tmp/${DB_FILE}*; wait; | |
| time sync-assets-graphite | |
| # Setup directory password. | |
| yum install -y httpd | |
| htpasswd -c /opt/www/graphite/.htpasswd graphite | |
| ######################################################### | |
| ######################################################### | |
| export i=5 | |
| DB_DATE=$(date +'%m/%d/%Y') | |
| IFS='/' read -a db_date <<< "$DB_DATE" | |
| DB_FILE="prod-csmgraphite-csmgraphite-${db_date[2]}-${db_date[0]}-${db_date[1]}.sql" | |
| # Download the database. | |
| time scp -i ~/.ssh/acquia_rs_server csmgraphite.prod@web-5921.prod.hosting.acquia.com:/mnt/files/csmgraphite.prod/backups/${DB_FILE}.gz /tmp/${DB_FILE}.gz; wait; | |
| time gunzip /tmp/${DB_FILE}.gz; wait; | |
| DB_NAME="graphite_dev${i}" | |
| mysql -e "DROP DATABASE ${DB_NAME}; GRANT ALL ON ${DB_NAME}.* TO 'graphite'@'localhost';"; wait; | |
| mysql -e "CREATE DATABASE ${DB_NAME}; GRANT ALL ON ${DB_NAME}.* TO 'graphite'@'localhost';"; wait; | |
| time mysql ${DB_NAME} < /tmp/${DB_FILE}; wait; | |
| # Run some drush for each instance. | |
| cd /opt/www/graphite/dev${i}/docroot/ | |
| drush -l dev${i}.graphite.org vset preprocess_js 0 --yes; wait; | |
| drush -l dev${i}.graphite.org vset preprocess_css 0 --yes; wait; | |
| drush -l dev${i}.graphite.org pm-disable -y masquerade; wait; | |
| drush -l dev${i}.graphite.org pm-disable -y cdn; wait; | |
| drush -l dev${i}.graphite.org vset honeypot_time_limit 0 --yes; wait; | |
| drush -l dev${i}.graphite.org vset error_level 2 --yes; wait; | |
| drush -l dev${i}.graphite.org vset csm_migration_d6_hostname local.csm.org --yes; wait; | |
| drush -l dev${i}.graphite.org vset tlr_csm_sync_csm_api_host local.csm.org --yes; wait; | |
| drush -l dev${i}.graphite.org php-eval "variable_set('csm_api_info', array('hostname' => 'https://graphite-api-dev.commonsense.org', 'clientId' => 'b13a2cfd6b5b0085d35843b9d3aaf6ec', 'appId' => '1c34a90620e2a4015b3b0439cadf5da3'))"; wait; | |
| drush -l dev${i}.graphite.org cc all; wait; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment