Re: mkfs and mdadm support


Chronological Thread 
  • From: Ezra Zygmuntowicz <ez@engineyard.com>
  • To: chef@lists.opscode.com
  • Subject: Re: mkfs and mdadm support
  • Date: Fri, 12 Jun 2009 23:41:11 -0700


On Jun 12, 2009, at 11:23 PM, snacktime wrote:

One issue I'm running into is how to handle potentially dangerous operations like mkfs. mkfs will fail without a force flag if you try to run it on a device that is already initialized with the same filesystem type, but if you run mkfs.ext3 on an xfs filesystem, it will happily create it without any warning. I know there are other checks that can be done, but one bad regex and bye bye filesystem. Using lvm or raid helps some because you could probably have a rule that if a device exists, it has a filesystem. Your recipes for creating filesystems always create the device and filesystem in one operation, or not at all.

Another option would be to have a role just for initializing servers. You put a server into that role to initialize it, and manually take it out once you know it's initialized correctly. Other roles would not have recipes that run mkfs at all. 'Normal' roles would only do things like assembling/stopping raid arrays, mounting/unmounting filesystems, etc.. If I need to add a volume to an existing raid array or lvm group, I do that manually, add it to my json ball, and it just works. Next reboot chef has the data it needs to bring everything up correctly.

This is one reason why I'm considering have a completely separate resource/provider for mkfs and friends. I don't want it anywhere near critical data, and the thought of an automated script checking to see if my filesystem needs to be initialized would keep me up at night.

Chris


The way I'm working with EBS volumes on ec2 where I want it to format the EBS device as ext3 *only* if it is not already formatted and then ensure it is properly mounted, I also want to grow the filesystem to fill the space in case i booted from a snapshot with a larger volume size.

 This works perfectly:

if (`grep /dev/sdz1 /etc/fstab` == "")
  Chef::Log.info("EBS device being configured")

  loop do
# loop until /dev/sdz1 is attached before we allow execution of our recipes to continue
    if File.exists?("/dev/sdz1")
        directory "/data" do
          owner 'root'
          group 'root'
          mode 0755
        end

        bash "format-data-ebs" do
          code "mkfs.ext3 -j -F /dev/sdz1"
          not_if "e2label /dev/sdz1"
        end

        bash "mount-data-ebs" do
          code "mount -t ext3 /dev/sdz1 /data"
        end

        bash "grow-data-ebs" do
          code "resize2fs /dev/sdz1"
        end

        bash "add-data-to-fstab" do
          code "echo '/dev/sdz1 /data ext3 noatime 0 0' >> /etc/fstab"
          not_if "grep /dev/sdz1 /etc/fstab"
        end

      break
    end
    Chef::Log.info("EBS device /dev/sdz1 not available yet...")
    sleep 5
  end
end

You could easily wrap that up in a more abstract resource or definition.

Cheers-

Ezra Zygmuntowicz
ez@engineyard.com






Archive powered by MHonArc 2.6.16.

§