|
| 1 | +# |
| 2 | +# Cookbook Name:: aws-parallelcluster |
| 3 | +# Recipe:: setup_raid_on_master |
| 4 | +# |
| 5 | +# Copyright 2013-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 6 | +# |
| 7 | +# Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with the |
| 8 | +# License. A copy of the License is located at |
| 9 | +# |
| 10 | +# http://aws.amazon.com/apache2.0/ |
| 11 | +# |
| 12 | +# or in the "LICENSE.txt" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES |
| 13 | +# OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | + |
| 16 | +# RAID RELATED |
| 17 | +# Parse and get RAID shared directory info and turn into an array |
| 18 | +raid_shared_dir = node['cfncluster']['cfn_raid_parameters'].split(',')[0] |
| 19 | + |
| 20 | +if raid_shared_dir != "NONE" |
| 21 | + |
| 22 | + # Parse and determine RAID type (cast into integer) |
| 23 | + raid_type = node['cfncluster']['cfn_raid_parameters'].split(',')[1].strip.to_i |
| 24 | + |
| 25 | + # Parse volume info into an array |
| 26 | + raid_vol_array = node['cfncluster']['cfn_raid_vol_ids'].split(',') |
| 27 | + raid_vol_array.each_with_index do |vol, index| |
| 28 | + raid_vol_array[index] = vol.strip |
| 29 | + end |
| 30 | + |
| 31 | + # Attach each volume |
| 32 | + raid_dev_path = [] |
| 33 | + raid_vol_array.each_with_index do |volumeid, index| |
| 34 | + raid_dev_path[index] = "/dev/disk/by-ebs-volumeid/#{volumeid}" |
| 35 | + |
| 36 | + # Attach RAID EBS volume |
| 37 | + execute "attach_raid_volume_#{index}" do |
| 38 | + command "/usr/local/sbin/attachVolume.py #{volumeid}" |
| 39 | + creates raid_dev_path[index] |
| 40 | + end |
| 41 | + |
| 42 | + # wait for the drive to attach |
| 43 | + ruby_block "sleeping_for_raid_volume_#{index}" do |
| 44 | + block do |
| 45 | + wait_for_block_dev(raid_dev_path[index]) |
| 46 | + puts "Attached index: #{index}, VolID: #{volumeid}" |
| 47 | + end |
| 48 | + action :nothing |
| 49 | + subscribes :run, "execute[attach_raid_volume_#{index}]", :immediately |
| 50 | + end |
| 51 | + end |
| 52 | + |
| 53 | + raid_dev = "/dev/md0" |
| 54 | + |
| 55 | + # Create RAID device with mdadm |
| 56 | + mdadm "MY_RAID" do |
| 57 | + raid_device raid_dev |
| 58 | + level raid_type |
| 59 | + devices raid_dev_path |
| 60 | + end |
| 61 | + |
| 62 | + # Wait for RAID to initialize |
| 63 | + ruby_block "sleeping_for_raid_block" do |
| 64 | + block do |
| 65 | + wait_for_block_dev(raid_dev) |
| 66 | + end |
| 67 | + action :nothing |
| 68 | + subscribes :run, "mdadm[MY_RAID]", :immediately |
| 69 | + end |
| 70 | + |
| 71 | + # Setup RAID disk, create ext4 filesystem on RAID array |
| 72 | + execute "setup_raid_disk" do |
| 73 | + command "sudo mkfs.ext4 #{raid_dev}" |
| 74 | + action :nothing |
| 75 | + subscribes :run, "ruby_block[sleeping_for_raid_block]", :immediately |
| 76 | + end |
| 77 | + |
| 78 | + |
| 79 | + # Create a configuration file to contain the RAID info, so the RAID array is reassembled automatically on boot |
| 80 | + if node['cfncluster']['cfn_base_os'] != "ubuntu1404" |
| 81 | + execute "create_raid_config" do |
| 82 | + command "sudo mdadm --detail --scan | sudo tee -a /etc/mdadm.conf" |
| 83 | + action :nothing |
| 84 | + subscribes :run, "execute[setup_raid_disk]", :immediately |
| 85 | + end |
| 86 | + |
| 87 | + else |
| 88 | + # Put config file in /etc/mdadm/mdadm.conf, Ubuntu1404 specific |
| 89 | + execute "create_raid_config" do |
| 90 | + command "sudo mdadm --detail --scan | sudo tee -a /etc/mdadm/mdadm.conf" |
| 91 | + action :nothing |
| 92 | + subscribes :run, "execute[setup_raid_disk]", :immediately |
| 93 | + end |
| 94 | + # Update initramfs to contain mdadm.conf settings, Ubuntu1404 specific |
| 95 | + execute "update_raid_config" do |
| 96 | + command "sudo update-initramfs -u" |
| 97 | + action :nothing |
| 98 | + subscribes :run, "execute[setup_raid_disk]", :immediately |
| 99 | + end |
| 100 | + end |
| 101 | + |
| 102 | + # Create the shared directory |
| 103 | + directory raid_shared_dir do |
| 104 | + owner 'root' |
| 105 | + group 'root' |
| 106 | + mode '1777' |
| 107 | + recursive true |
| 108 | + action :create |
| 109 | + end |
| 110 | + |
| 111 | + # Add volume to /etc/fstab |
| 112 | + mount raid_shared_dir do |
| 113 | + device "/dev/md0" |
| 114 | + fstype "ext4" |
| 115 | + options "defaults,nofail,_netdev" |
| 116 | + action %i[mount enable] |
| 117 | + end |
| 118 | + |
| 119 | + # Make sure shared directory permissions are correct |
| 120 | + directory raid_shared_dir do |
| 121 | + owner 'root' |
| 122 | + group 'root' |
| 123 | + mode '1777' |
| 124 | + end |
| 125 | + |
| 126 | + # Export RAID directory via nfs |
| 127 | + nfs_export raid_shared_dir do |
| 128 | + network node['cfncluster']['ec2-metadata']['vpc-ipv4-cidr-block'] |
| 129 | + writeable true |
| 130 | + options ['no_root_squash'] |
| 131 | + end |
| 132 | +end |
0 commit comments