Permalink
Browse files

Various packaging issues and some error handling improved

  • Loading branch information...
1 parent f48e46d commit 0828eeab100248e6346391145cb48ee6b4b6a8c2 @ripienaar ripienaar committed Jul 5, 2010
Showing with 319 additions and 14 deletions.
  1. +14 −0 COPYING
  2. +88 −0 Rakefile
  3. +96 −0 ec2-boot-init.init
  4. +12 −0 ec2-boot-init.rb
  5. +68 −0 ec2-boot-init.spec
  6. +15 −11 lib/ec2boot/actions.rb
  7. +3 −0 lib/ec2boot/config.rb
  8. +5 −3 lib/ec2boot/util.rb
  9. +9 −0 motd.provisioned
  10. +9 −0 motd.unprovisioned
View
14 COPYING
@@ -0,0 +1,14 @@
+ Copyright 2009 R.I.Pienaar
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
View
@@ -0,0 +1,88 @@
+# Rakefile to build a project using HUDSON
+
+require 'rake/rdoctask'
+require 'rake/packagetask'
+require 'rake/clean'
+require 'find'
+
+PROJ_DOC_TITLE = "EC2 Bootstrap System"
+PROJ_VERSION = "0.0.1"
+PROJ_RELEASE = "1"
+PROJ_NAME = "ec2-boot-init"
+PROJ_RPM_NAMES = [PROJ_NAME]
+PROJ_FILES = ["#{PROJ_NAME}.spec", "#{PROJ_NAME}.rb", "#{PROJ_NAME}.init", "COPYING", "motd.provisioned", "motd.unprovisioned"]
+PROJ_SUBDIRS = ["lib", "actions"]
+
+Find.find("actions", "lib") do |f|
+ if FileTest.directory?(f) and f =~ /\.svn/
+ Find.prune
+ else
+ PROJ_FILES << f
+ end
+end
+
+ENV["RPM_VERSION"] ? CURRENT_VERSION = ENV["RPM_VERSION"] : CURRENT_VERSION = PROJ_VERSION
+ENV["BUILD_NUMBER"] ? CURRENT_RELEASE = ENV["BUILD_NUMBER"] : CURRENT_RELEASE = PROJ_RELEASE
+
+CLEAN.include("build")
+
+def announce(msg='')
+ STDERR.puts "================"
+ STDERR.puts msg
+ STDERR.puts "================"
+end
+
+def init
+ FileUtils.mkdir("build") unless File.exist?("build")
+end
+
+desc "Build documentation, tar balls and rpms"
+task :default => [:clean, :doc, :package, :rpm]
+
+# task for building docs
+rd = Rake::RDocTask.new(:doc) { |rdoc|
+ announce "Building documentation for #{CURRENT_VERSION}"
+
+ rdoc.rdoc_dir = 'doc'
+ rdoc.template = 'html'
+ rdoc.title = "#{PROJ_DOC_TITLE} version #{CURRENT_VERSION}"
+ rdoc.options << '--line-numbers' << '--inline-source' << '--main' << 'MCollective'
+}
+
+desc "Create a tarball for this release"
+task :package => [:clean, :doc] do
+ announce "Creating #{PROJ_NAME}-#{CURRENT_VERSION}.tgz"
+
+ FileUtils.mkdir_p("build/#{PROJ_NAME}-#{CURRENT_VERSION}")
+ system("cp -R #{PROJ_FILES.join(' ')} build/#{PROJ_NAME}-#{CURRENT_VERSION}")
+ system("cd build && tar --exclude .svn -cvzf #{PROJ_NAME}-#{CURRENT_VERSION}.tgz #{PROJ_NAME}-#{CURRENT_VERSION}")
+end
+
+desc "Creates a RPM"
+task :rpm => [:clean, :doc, :package] do
+ announce("Building RPM for #{PROJ_NAME}-#{CURRENT_VERSION}-#{CURRENT_RELEASE}")
+
+ sourcedir = `rpm --eval '%_sourcedir'`.chomp
+ specsdir = `rpm --eval '%_specdir'`.chomp
+ srpmsdir = `rpm --eval '%_srcrpmdir'`.chomp
+ rpmdir = `rpm --eval '%_rpmdir'`.chomp
+ lsbdistrel = `lsb_release -r -s | cut -d . -f1`.chomp
+ lsbdistro = `lsb_release -i -s`.chomp
+
+ case lsbdistro
+ when 'CentOS'
+ rpmdist = ".el#{lsbdistrel}"
+ else
+ rpmdist = ""
+ end
+
+ system %{cp build/#{PROJ_NAME}-#{CURRENT_VERSION}.tgz #{sourcedir}}
+ system %{cat #{PROJ_NAME}.spec|sed -e s/%{rpm_release}/#{CURRENT_RELEASE}/g | sed -e s/%{version}/#{CURRENT_VERSION}/g > #{specsdir}/#{PROJ_NAME}.spec}
+ system %{cd #{specsdir} && rpmbuild -D 'version #{CURRENT_VERSION}' -D 'rpm_release #{CURRENT_RELEASE}' -D 'dist #{rpmdist}' -ba #{PROJ_NAME}.spec}
+
+ system %{cp #{srpmsdir}/#{PROJ_NAME}-#{CURRENT_VERSION}-#{CURRENT_RELEASE}#{rpmdist}.src.rpm build/}
+
+ system %{cp #{rpmdir}/*/#{PROJ_NAME}*-#{CURRENT_VERSION}-#{CURRENT_RELEASE}#{rpmdist}.*.rpm build/}
+end
+
+# vi:tabstop=4:expandtab:ai
View
@@ -0,0 +1,96 @@
+#!/bin/sh
+#
+# ec2-boot-init Bootstrapper for EC2
+#
+# chkconfig: 345 24 76
+#
+# description: Bootstraps EC2 instances in a way that enables you to
+# customise a standard image into different configurations
+# via structured user data
+#
+### BEGIN INIT INFO
+# Provides: ec2-boot-init
+# Required-Start: $network $syslog
+# Required-Stop: $network $syslog
+# Default-Start: 2 3 4 5
+# Default-Stop: 0 1 6
+# Short-Description: Start daemon at boot time
+# Description: Enable service provided by daemon.
+### END INIT INFO
+
+prog="/usr/sbin/ec2-boot-init"
+
+# Lockfile
+if [ -d /var/lock/subsys ]; then
+ # RedHat/CentOS/etc who use subsys
+ lock="/var/lock/subsys/ec2-boot-init"
+else
+ # The rest of them
+ lock="/var/lock/ec2-boot-init"
+fi
+
+
+# Source function library.
+. /lib/lsb/init-functions
+
+# Check that binary exists
+if ! [ -f $prog ]
+then
+ echo "ec2-boot-init binary not found"
+ exit 0
+fi
+
+# See how we were called.
+case "$1" in
+ start)
+ echo -n "Starting ec2-boot-init: "
+
+ cp /etc/ec2-boot-init/motd.unprovisioned /etc/motd
+
+ ${prog}
+
+ if [ $? = 0 ]; then
+ cp /etc/ec2-boot-init/motd.provisioned /etc/motd
+ log_success_msg
+ touch $lock
+ exit 0
+ else
+ log_failure_msg
+ exit 1
+ fi
+ ;;
+ stop)
+ log_success_msg
+ rm -f $lock
+ ;;
+ restart)
+ $0 stop
+ sleep 2
+ $0 start
+ ;;
+ condrestart)
+ if [ -f $lock ]; then
+ $0 stop
+ # avoid race
+ sleep 2
+ $0 start
+ fi
+ ;;
+ status)
+ if [ -f ${lock} ]; then
+ echo "ec2-boot-init ran"
+ exit 0
+ else
+ echo "ec2-boot-init: service not started"
+ exit 1
+ fi
+ ;;
+ force-reload)
+ echo "not implemented"
+ ;;
+ *)
+ echo "Usage: ec2-boot-init {start|stop|restart|condrestart|status}"
+ exit 1
+ ;;
+esac
+exit 0
View
@@ -0,0 +1,12 @@
+#!/usr/bin/ruby
+
+require 'ec2boot'
+
+config = EC2Boot::Config.new
+ud = EC2Boot::UserData.new(config)
+md = EC2Boot::MetaData.new(config)
+
+EC2Boot::Util.write_facts(ud, md, config)
+
+config.actions.run_actions(ud, md, config)
+
View
@@ -0,0 +1,68 @@
+%define ruby_sitelib %(ruby -rrbconfig -e "puts Config::CONFIG['sitelibdir']")
+%define release %{rpm_release}%{?dist}
+
+Summary: EC2 Bootstrap System
+Name: ec2-boot-init
+Version: %{version}
+Release: %{release}
+Group: System Tools
+License: Apache License, Version 2
+URL: http://www.devco.net/
+Source0: %{name}-%{version}.tgz
+BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
+Requires: ruby
+Packager: R.I.Pienaar <rip@devco.net>
+BuildArch: noarch
+
+%description
+Bootstrap system for EC2 based systems.
+
+%prep
+%setup -q
+
+%build
+
+%install
+rm -rf %{buildroot}
+%{__install} -d -m0755 %{buildroot}/%{ruby_sitelib}/ec2boot
+%{__install} -d -m0755 %{buildroot}/usr/sbin
+%{__install} -d -m0755 %{buildroot}/etc/init.d
+%{__install} -d -m0755 %{buildroot}/etc/ec2-boot-init
+%{__install} -d -m0755 %{buildroot}/etc/ec2-boot-init/actions
+%{__install} -m0755 ec2-boot-init.rb %{buildroot}/usr/sbin/ec2-boot-init
+%{__install} -m0755 ec2-boot-init.init %{buildroot}/etc/init.d/ec2-boot-init
+%{__install} -m0644 motd.provisioned %{buildroot}/etc/ec2-boot-init/motd.provisioned
+%{__install} -m0644 motd.unprovisioned %{buildroot}/etc/ec2-boot-init/motd.unprovisioned
+
+
+cp -R lib/* %{buildroot}/%{ruby_sitelib}/
+cp -R actions/* %{buildroot}/etc/ec2-boot-init/actions/
+
+%clean
+rm -rf %{buildroot}
+
+%post
+cp /etc/ec2-boot-init/motd.unprovisioned /etc/motd
+/sbin/chkconfig --add ec2-boot-init || :
+
+%postun
+if [ "$1" -ge 1 ]; then
+ /sbin/service ec2-boot-init condrestart &>/dev/null || :
+fi
+
+%preun
+if [ "$1" = 0 ] ; then
+ /sbin/chkconfig --del mcollective || :
+fi
+
+%files
+%doc COPYING
+/usr/sbin/ec2-boot-init
+/etc/ec2-boot-init
+/etc/init.d/ec2-boot-init
+%{ruby_sitelib}/ec2boot.rb
+%{ruby_sitelib}/ec2boot
+
+%changelog
+* Tue Nov 03 2009 R.I.Pienaar <rip@devco.net>
+- First release
View
@@ -13,23 +13,27 @@ def load_actions
end
def run_actions(ud, md, config)
- if ud.user_data.include?(:actions)
- ud.user_data[:actions].each do |action|
- if action.include?(:type)
- type = action[:type].to_s
- meth = "#{type}_action"
+ if ud.user_data.is_a?(Hash)
+ if ud.user_data.include?(:actions)
+ ud.user_data[:actions].each do |action|
+ if action.include?(:type)
+ type = action[:type].to_s
+ meth = "#{type}_action"
- if respond_to?(meth)
- send(meth, action, ud, md, config)
+ if respond_to?(meth)
+ send(meth, action, ud, md, config)
+ else
+ # no such method
+ end
else
- # no such method
+ # no type
end
- else
- # no type
end
+ else
+ # no :actions
end
else
- # no :actions
+ # not a hash
end
end
end
View
@@ -10,6 +10,9 @@ def initialize
@facts_file = "/etc/facts.txt"
@actions = Actions.new(self)
+
+
+ FileUtils.mkdir_p(@cache_dir)
end
end
end
View
@@ -32,9 +32,11 @@ def self.write_facts(ud, md, config)
File.open(config.facts_file, "w") do |facts|
if ud.fetched?
- if ud.user_data.include?(:facts)
- ud.user_data[:facts].each_pair do |k,v|
- facts.puts("#{k}=#{v}")
+ if ud.user_data.is_a?(Hash)
+ if ud.user_data.include?(:facts)
+ ud.user_data[:facts].each_pair do |k,v|
+ facts.puts("#{k}=#{v}")
+ end
end
end
end
View
@@ -0,0 +1,9 @@
+ ___ _ _ _
+ | _ \_ _ _____ _(_)__(_)___ _ _ ___ __| |
+ | _/ '_/ _ \ V / (_-< / _ \ ' \/ -_) _` |
+ |_| |_| \___/\_/|_/__/_\___/_||_\___\__,_|
+
+ Successfully provisioned Amazon instance.
+
+ System facts are in /etc/facts.txt
+
View
@@ -0,0 +1,9 @@
+ _ _ _ _ _
+ | | | |_ _ _ __ _ _ _____ _(_)__(_)___ _ _ ___ __| |
+ | |_| | ' \| '_ \ '_/ _ \ V / (_-< / _ \ ' \/ -_) _` |
+ \___/|_||_| .__/_| \___/\_/|_/__/_\___/_||_\___\__,_|
+ |_|
+
+ Unprovisioned Amazon instance. The ec2-boot-init
+ system failed to run or has not yet been run
+

0 comments on commit 0828eea

Please sign in to comment.