andsens / build-debian-cloud

This project has been superseeded by andsens/bootstrap-vz and is no longer maintained - Script to create Debian Squeeze & Wheezy Amazon Machine Images (AMIs) and Google Compute Engine images
Other
117 stars 43 forks source link

run user data script doesn't correctly run compressed user data. #103

Closed andrewfenn closed 10 years ago

andrewfenn commented 10 years ago

I had to replace the decompression part of the code in /etc/init.d/ec2-run-user-data with the following..

if [ $(file -b --mime-type $user_data_file) = 'application/x-gzip' ]; then
        $logger "Uncompressing gzip'd user-data"
        user_data_dir=$user_data_file.d
        mkdir -p $user_data_dir
        cat $user_data_file | gzip -d 2>/dev/null | munpack -t -q -C $user_data_dir 2>/dev/null > $user_data_dir/files
        run_file=`grep 'text/x-shellscript' $user_data_dir/files`
        run_file=$user_data_dir/${run_file%%(*}
        mv $run_file $user_data_file
        rm -R $user_data_dir
fi

With services like OpsWorks simply decompressing the user data isn't enough because they pack mime multipart files into the user-data text.

I use the munpack command to expand the files list then using the munpack output which gives you the mime type to select the correct file for execution. If you use this code you need to make sure that the mpack package is installed.

I've created a new temporary directory here since munpack expands the user-data to multiple files and I wanted to keep things clean.

There is more information about the format here: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AmazonLinuxAMIBasics.html#CloudInit

andsens commented 10 years ago

I'm marking this "python", because we'll be adding a cloud-init plugin to the python branch very soon, which will fix this issue.

andsens commented 10 years ago

cloud-init now works in the python branch.