github.com/swiftstack/proxyfs@v0.0.0-20201223034610-5434d919416e/cookbooks/proxyfs_swift/recipes/default.rb (about)

     1  # Copyright (c) 2017 SwiftStack, Inc.
     2  #
     3  # Licensed under the Apache License, Version 2.0 (the "License");
     4  # you may not use this file except in compliance with the License.
     5  # You may obtain a copy of the License at
     6  #
     7  #    http://www.apache.org/licenses/LICENSE-2.0
     8  #
     9  # Unless required by applicable law or agreed to in writing, software
    10  # distributed under the License is distributed on an "AS IS" BASIS,
    11  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
    12  # implied.
    13  # See the License for the specific language governing permissions and
    14  # limitations under the License.
    15  
    16  # rsync
    17  
    18  rsync_service = "rsync"
    19  if node[:platform_family].include?("rhel")
    20    rsync_service = "rsyncd"
    21  end
    22  
    23  template "/etc/rsyncd.conf" do
    24    source "etc/rsyncd.conf.erb"
    25    notifies :restart, "service[#{rsync_service}]"
    26    variables({
    27      :swift_user => node['swift_user'],
    28      :swift_group => node['swift_group'],
    29    })
    30  end
    31  
    32  # TODO:  I suppose this should be a file rather than a template
    33  template "/etc/default/#{rsync_service}" do
    34    source "etc/default/#{rsync_service}.erb"
    35    notifies :restart, "service[#{rsync_service}]"
    36    not_if { ::File.exist?("/etc/default/#{rsync_service}") }
    37    variables({
    38    })
    39  end
    40  
    41  execute "enable-rsync" do
    42    command "sed -i 's/ENABLE=false/ENABLE=true/' /etc/default/#{rsync_service}"
    43    not_if "grep ENABLE=true /etc/default/#{rsync_service}"
    44    action :run
    45  end
    46  
    47  [
    48    "#{rsync_service}",
    49    "memcached",
    50    "rsyslog",
    51  ].each do |daemon|
    52    service daemon do
    53      action :start
    54    end
    55  end
    56  
    57  ruby_block "update_proxy_server_pipeline" do
    58    block do
    59      proxy_server_conf = "/etc/swift/proxy-server.conf"
    60  
    61      if File.file?(proxy_server_conf)
    62        file = Chef::Util::FileEdit.new(proxy_server_conf)
    63        file.search_file_replace(/^( *pipeline\s*=.*?)\s+dlo\s+(?:pfs\s+)?(.*)$/, '\1 dlo pfs \2')
    64        file.insert_line_if_no_match(/filter.pfs/, "")
    65        file.insert_line_if_no_match(/filter.pfs/, "[filter:pfs]")
    66        file.insert_line_if_no_match(/egg.pfs_middleware/, "use = egg:pfs_middleware#pfs")
    67        file.insert_line_if_no_match(/proxyfsd_host/, "proxyfsd_host = 127.0.0.1")
    68        file.insert_line_if_no_match(/proxyfsd_port/, "proxyfsd_port = 12345")
    69        file.insert_line_if_no_match(/bypass_mode/, "bypass_mode = read-write")
    70        file.write_file
    71      end
    72    end
    73  end
    74  
    75  proxy_conf_dir = "etc/swift/proxy-server/proxy-noauth.conf.d"
    76  %w[ etc/swift/proxy-server etc/swift/proxy-server/proxy-noauth.conf.d ].each do |path|
    77    directory path do
    78      owner "#{node['swift_user']}"
    79      group "#{node['swift_group']}"
    80      action :create
    81    end
    82  end
    83  template "/#{proxy_conf_dir}/00_base.conf" do
    84    source "etc/swift/base.conf-template.erb"
    85    owner "#{node['swift_user']}"
    86    group "#{node['swift_group']}"
    87    variables({
    88      :swift_user => node['swift_user'],
    89      :swift_group => node['swift_group'],
    90    })
    91  end
    92  template "/#{proxy_conf_dir}/10_default.conf" do
    93    source "etc/swift/proxy-server/default.conf-template.erb"
    94    owner "#{node['swift_user']}"
    95    group "#{node['swift_group']}"
    96    variables({
    97      :post_as_copy => node['post_as_copy'],
    98    })
    99  end
   100  cookbook_file "#{proxy_conf_dir}/20_settings.conf" do
   101    source "#{proxy_conf_dir}/20_settings.conf"
   102    owner "#{node['swift_user']}"
   103    group "#{node['swift_group']}"
   104  end
   105  
   106  ruby_block "update_noauth_proxy_server_pipeline" do
   107    block do
   108      noauth_proxy_server_conf = "/etc/swift/proxy-server/proxy-noauth.conf.d/20_settings.conf"
   109  
   110      if File.file?(noauth_proxy_server_conf)
   111        file = Chef::Util::FileEdit.new(noauth_proxy_server_conf)
   112        file.search_file_replace(/ dlo /, " dlo meta ")
   113        file.insert_line_if_no_match(/filter.meta/, "")
   114        file.insert_line_if_no_match(/filter.meta/, "[filter:meta]")
   115        file.insert_line_if_no_match(/egg.meta_middleware/, "use = egg:meta_middleware#meta")
   116        file.write_file
   117      end
   118    end
   119  end
   120  
   121  # start main
   122  
   123  cookbook_file "/usr/lib/systemd/system/swift.service" do
   124    source "usr/lib/systemd/system/swift.service"
   125    # notifies :restart, 'service[swift]'
   126    only_if { ::File.directory?("/usr/lib/systemd/system/") }
   127  end
   128  
   129  # Enable Swift to start at bootup on Centos
   130  #
   131  #
   132  if node[:platform_family].include?("rhel")
   133    execute "Enable Swift to start at bootup on Centos" do
   134    command "/usr/bin/systemctl enable swift.service"
   135    end
   136  end
   137  
   138  cookbook_file "/etc/init/swift.conf" do
   139    source "etc/init/swift.upstart"
   140    # notifies :restart, 'service[swift]'
   141    only_if { ::File.directory?("/etc/init") }
   142  end
   143  
   144  execute "startmain" do
   145    command "swift-init start main"
   146  end