github.com/swiftstack/ProxyFS@v0.0.0-20210203235616-4017c267d62f/cookbooks/swift/recipes/data.rb (about)

     1  # Copyright (c) 2015-2021, NVIDIA CORPORATION.
     2  # SPDX-License-Identifier: Apache-2.0
     3  
     4  
     5  # setup up some disk
     6  
     7  [
     8    "/var/lib/swift",
     9    "/mnt/swift-disk",
    10  ].each do |d|
    11    directory d do
    12      action :create
    13    end
    14  end
    15  
    16  execute "create sparse file" do
    17    command "truncate -s #{node['loopback_gb']}GB /var/lib/swift/disk"
    18    creates "/var/lib/swift/disk"
    19    action :run
    20  end
    21  
    22  execute "create file system" do
    23    command "mkfs.xfs /var/lib/swift/disk"
    24    not_if "xfs_admin -l /var/lib/swift/disk"
    25    action :run
    26  
    27    notifies :run, "execute[set xfs uuid]", :immediately
    28  end
    29  
    30  execute "set xfs uuid" do
    31    # the string "generate" is treated specially by xfs_admin and means
    32    # "make one up for me"
    33    command "xfs_admin -U generate /var/lib/swift/disk"
    34    action :nothing
    35  end
    36  
    37  execute "update fstab" do
    38    command "echo '/var/lib/swift/disk /mnt/swift-disk xfs " \
    39      "loop,noatime,nouuid,nodiratime,nobarrier,logbufs=8 0 0' >> /etc/fstab"
    40    not_if "grep swift-disk /etc/fstab"
    41    action :run
    42  end
    43  
    44  execute "mount" do
    45    command "mount /mnt/swift-disk"
    46    not_if "mountpoint /mnt/swift-disk"
    47  end
    48  
    49  if node['ec_policy'].empty? then
    50    num_disks = node['disks']
    51  else
    52    num_disks = [node['disks'], node['ec_disks']].max
    53  end
    54  
    55  (1..num_disks).each do |i|
    56    j = ((i - 1) % node['nodes']) + 1
    57    disk_path = "/mnt/swift-disk/sdb#{i}"
    58    node_path = "/srv/node#{j}"
    59    srv_path = node_path + "/sdb#{i}"
    60    directory disk_path do
    61      owner "#{node['swift_user']}"
    62      group "#{node['swift_group']}"
    63      action :create
    64    end
    65    directory node_path do
    66      owner "#{node['swift_user']}"
    67      group "#{node['swift_group']}"
    68      action :create
    69    end
    70    link srv_path do
    71      to disk_path 
    72    end
    73  end
    74  
    75  # run dirs
    76  
    77  [
    78    "/var/run/swift",
    79    "/var/cache/swift",
    80  ].each do |d|
    81    directory d do
    82      owner "#{node['swift_user']}"
    83      group "#{node['swift_group']}"
    84      action :create
    85    end
    86  end
    87  
    88  (1..node['nodes']).each do |i|
    89    recon_cache_path = "/var/cache/swift/node#{i}"
    90    directory recon_cache_path do
    91      owner "#{node['swift_user']}"
    92      group "#{node['swift_group']}"
    93      recursive true
    94    end
    95  end
    96  
    97  # make $swift_user able to read /var/log/syslog
    98  group "adm" do
    99    action :modify
   100    members "#{node['swift_user']}"
   101    append true
   102  end