Victor Morales | 89ce321 | 2017-06-16 18:32:48 -0500 | [diff] [blame^] | 1 | #!/bin/bash |
| 2 | |
| 3 | set -o xtrace |
| 4 | |
| 5 | # mount_external_partition() - Create partition and mount the external volume |
| 6 | function mount_external_partition { |
| 7 | cat <<EOL > /tmp/asdc_ext_volume_partitions.txt |
| 8 | # partition table of /dev/sdb |
| 9 | unit: sectors |
| 10 | |
| 11 | /dev/sdb1 : start= 2048, size=209713152, Id=83 |
| 12 | /dev/sdb2 : start= 0, size= 0, Id= 0 |
| 13 | /dev/sdb3 : start= 0, size= 0, Id= 0 |
| 14 | /dev/sdb4 : start= 0, size= 0, Id= 0 |
| 15 | EOL |
| 16 | sfdisk --force /dev/sdb < /tmp/asdc_ext_volume_partitions.txt |
| 17 | mkfs -t ext4 /dev/sdb1 |
| 18 | mkdir -p /data |
| 19 | mount /dev/sdb1 /data |
| 20 | echo "/dev/sdb1 /data ext4 errors=remount-ro,noatime,barrier=0 0 1" >> /etc/fstab |
| 21 | } |
| 22 | |
| 23 | # init_data_folders() - Function that initialize the data folders |
| 24 | function init_data_folders { |
| 25 | mkdir -p /data/environments |
| 26 | mkdir -p /data/scripts |
| 27 | mkdir -p /data/logs/BE |
| 28 | mkdir -p /data/logs/FE |
| 29 | chmod 777 /data |
| 30 | chmod 777 /data/logs/BE |
| 31 | chmod 777 /data/logs/FE |
| 32 | } |
| 33 | |
| 34 | # setup_docker_aliases() - Function that setups the aliases required by sdc scripts |
| 35 | function setup_docker_aliases { |
| 36 | cat <<EOL > /root/.bash_aliases |
| 37 | alias dcls='/data/scripts/docker_clean.sh \$1' |
| 38 | alias dlog='/data/scripts/docker_login.sh \$1' |
| 39 | alias rund='/data/scripts/docker_run.sh' |
| 40 | alias health='/data/scripts/docker_health.sh' |
| 41 | EOL |
| 42 | } |
| 43 | |
| 44 | # install_sdc() - Function that pull templates and executes |
| 45 | function install_sdc { |
| 46 | IP_ADDRESS=$(ifconfig eth0 | grep "inet addr" | tr -s ' ' | cut -d' ' -f3 | cut -d':' -f2) |
| 47 | local ENV_NAME=$dmaap_topic |
| 48 | local MR_IP_ADDR='10.0.11.1' |
| 49 | local RELEASE=$docker_version |
| 50 | NEXUS_DOCKER_PORT=$(echo $nexus_docker_repo | cut -d':' -f2) |
| 51 | local src_folder=/opt/sdc |
| 52 | clone_repo sdc $src_folder |
| 53 | if [[ "$build_image" == "True" ]]; then |
| 54 | compile_src $src_folder |
| 55 | build_docker_image $src_folder/sdc-os-chef |
| 56 | fi |
| 57 | cp $src_folder/sdc-os-chef/environments/Template.json /data/environments |
| 58 | cp $src_folder/sdc-os-chef/scripts/docker_run.sh /data/scripts |
| 59 | cp $src_folder/sdc-os-chef/scripts/docker_health.sh /data/scripts |
| 60 | chmod +x /data/scripts/docker_run.sh |
| 61 | chmod +x /data/scripts/docker_health.sh |
| 62 | |
| 63 | cat /data/environments/Template.json | sed "s/yyy/"$IP_ADDRESS"/g" > /data/environments/$ENV_NAME.json |
| 64 | sed -i "s/xxx/"$ENV_NAME"/g" /data/environments/$ENV_NAME.json |
| 65 | sed -i "s/\"ueb_url_list\":.*/\"ueb_url_list\": \""$MR_IP_ADDR","$MR_IP_ADDR"\",/g" /data/environments/$ENV_NAME.json |
| 66 | sed -i "s/\"fqdn\":.*/\"fqdn\": [\""$MR_IP_ADDR"\", \""$MR_IP_ADDR"\"]/g" /data/environments/$ENV_NAME.json |
| 67 | |
| 68 | is_package_installed docker-ce || install_docker |
| 69 | docker login -u $nexus_username -p $nexus_password $nexus_docker_repo |
| 70 | bash /data/scripts/docker_run.sh -e $ENV_NAME -r $RELEASE -p $NEXUS_DOCKER_PORT |
| 71 | } |
| 72 | |
| 73 | # init_sdc() - Function that initialize SDC services |
| 74 | function init_sdc { |
| 75 | mount_external_partition |
| 76 | init_data_folders |
| 77 | setup_docker_aliases |
| 78 | install_sdc |
| 79 | } |