mount

in cookbooks/fb_fstab/libraries/provider.rb [20:137]


    def mount(mount_data, in_maint_disks, in_maint_mounts)
      if in_maint_mounts.include?(mount_data['mount_point'])
        Chef::Log.warn(
          "fb_fstab: Skipping mount of #{mount_data['mount_point']} because " +
          'the mount is marked as in-maintenance',
        )
        return true
      end

      relevant_disk = nil
      in_maint_disks.each do |disk|
        if mount_data['device'].start_with?(disk)
          relevant_disk = disk
          break
        end
      end
      if relevant_disk
        Chef::Log.warn(
          "fb_fstab: Skipping mount of #{mount_data['mount_point']} because " +
          " device #{relevant_disk} is marked as in-maintenance",
        )
        return true
      end

      
      
      
      
      
      
      
      
      Chef::Log.info("fb_fstab: Mounting #{mount_data['mount_point']}")
      if ::File.exist?(mount_data['mount_point'])
        if ::File.symlink?(mount_data['mount_point'])
          if mount_data['allow_mount_failure']
            msg = "fb_fstab: #{mount_data['mount_point']} is a symlink. " +
                  'This is probably not what you want and could cause SEVs.'
            Chef::Log.warn(msg)
            return false
          else
            fail "fb_fstab: #{mount_data['mount_point']} is a symlink, thus" +
              ' I will not mount over it.'
          end
        end
      else
        
        
        
        FileUtils.mkdir_p(mount_data['mount_point'], :mode => 0o755)
        if mount_data['mp_perms']
          FileUtils.chmod(mount_data['mp_perms'].to_i(8),
                          mount_data['mount_point'])
        end
        if mount_data['mp_owner'] || mount_data['mp_group']
          FileUtils.chown(mount_data['mp_owner'], mount_data['mp_group'],
                          mount_data['mount_point'])
        end
        if mount_data['mp_immutable']
          readme = File.join(mount_data['mount_point'], 'README.txt')
          readme_body = 'This directory was created by chef to be an ' +
            'immutable mountpoint.  If you can see this, ' +
            "the mount is missing!\n"
          File.open(readme, 'w') do |f| 
            f.write(readme_body)
          end
          s = Mixlib::ShellOut.new(
            "/bin/chattr +i #{mount_data['mount_point']}",
          ).run_command
          s.error!
        end
      end
      if node.systemd?
        
        
        
        
        
        
        
        
        
        
        
        s = Mixlib::ShellOut.new(
          "/bin/systemd-escape -p --suffix=mount #{mount_data['mount_point']}",
        ).run_command
        s.error!
        mountunit = s.stdout.chomp.shellescape
        s = Mixlib::ShellOut.new("/bin/systemctl start #{mountunit}")
      else
        
        
        
        
        
        
        
        
        s = Mixlib::ShellOut.new(
          "cd /dev/shm && /bin/mount #{mount_data['mount_point']}",
        )
      end

      _run_command_flocked(s,
                           mount_data['lock_file'],
                           mount_data['mount_point'])
      if s.error? && mount_data['allow_mount_failure']
        Chef::Log.warn(
          "fb_fstab: Mounting #{mount_data['mount_point']} failed, but " +
          '"allow_mount_failure" was set, so moving on.',
        )
      else
        s.error!
      end
      true
    end