summaryrefslogtreecommitdiffstats
path: root/roles/docker_img_puppet/files
diff options
context:
space:
mode:
Diffstat (limited to 'roles/docker_img_puppet/files')
-rw-r--r--roles/docker_img_puppet/files/puppet_container/Dockerfile32
-rwxr-xr-xroles/docker_img_puppet/files/puppet_container/service.rb18
-rwxr-xr-xroles/docker_img_puppet/files/puppet_container/start.rb86
3 files changed, 136 insertions, 0 deletions
diff --git a/roles/docker_img_puppet/files/puppet_container/Dockerfile b/roles/docker_img_puppet/files/puppet_container/Dockerfile
new file mode 100644
index 000000000..0bc72d389
--- /dev/null
+++ b/roles/docker_img_puppet/files/puppet_container/Dockerfile
@@ -0,0 +1,32 @@
+# This FROM gives us the proper oo-rhui certs, basic runtime env vars, basic repos, etc.
+# Otherwise we can't install anything
+FROM rhel6ops
+
+MAINTAINER Thomas Wiest <twiest@redhat.com>
+
+RUN yum -y update ; yum clean all
+
+# Container Specific RPMs
+RUN yum -y install puppet3 crontabs cronie-anacron cronie system-config-firewall-base httpd mod_ssl ruby193-rubygem-zbxapi mod_security rhc-site-static; yum clean all
+
+# BEGIN: These are to fake out puppet
+
+RUN rm /usr/sbin/lokkit ; ln -s /bin/true /usr/sbin/lokkit
+
+# END: These are to fake out puppet
+
+# Container specific files
+ADD start.rb /usr/local/sbin/start.rb
+ADD service.rb /sbin/service
+
+# Ensure the scripts are executable
+RUN chmod 755 /sbin/service /usr/local/sbin/start.rb
+
+RUN yum -y install strace ; yum clean all
+
+# Get rid of puppet deprecation warnings
+RUN sed -i 's/^.*manifest =.*$//' /etc/puppet/puppet.conf ; \
+ sed -i 's/^.*manifestdir =.*$//' /etc/puppet/puppet.conf ; \
+ sed -i 's/^.*modulepath =.*$//' /etc/puppet/puppet.conf
+
+CMD ["/usr/local/sbin/start.rb"]
diff --git a/roles/docker_img_puppet/files/puppet_container/service.rb b/roles/docker_img_puppet/files/puppet_container/service.rb
new file mode 100755
index 000000000..40779c270
--- /dev/null
+++ b/roles/docker_img_puppet/files/puppet_container/service.rb
@@ -0,0 +1,18 @@
+#!/usr/bin/env ruby
+
+require 'fileutils'
+
+if __FILE__ == $0
+ abort "\nUsage: #{File.basename($0)} <name> <action>\n\n" unless ARGV.size == 2
+
+ name = ARGV[0]
+ action = ARGV[1]
+
+ SERVICE_IPC_DIR = '/var/run/ctr-ipc/service'
+
+ FileUtils.mkdir_p(SERVICE_IPC_DIR)
+
+ File.open("#{SERVICE_IPC_DIR}/#{name}", 'w') do |f|
+ f.print action
+ end
+end
diff --git a/roles/docker_img_puppet/files/puppet_container/start.rb b/roles/docker_img_puppet/files/puppet_container/start.rb
new file mode 100755
index 000000000..f1dd940ba
--- /dev/null
+++ b/roles/docker_img_puppet/files/puppet_container/start.rb
@@ -0,0 +1,86 @@
+#!/usr/bin/env ruby
+
+require 'fileutils'
+
+CTR_CONFIG_FLAG = '/shared/var/run/ctr-ipc/flag/ctr_configured'
+
+
+class Start
+ def self.setup_shared_dirs()
+ puts '_'
+ puts 'Setting up dirs in shared volume'
+ puts '--------------------------------'
+ mtab = File.read('/etc/mtab')
+
+ shared_dirs = mtab.grep(/ \/shared\//).collect { |line| line.split(' ')[1] }
+
+ shared_dirs.each do |sh_dir|
+ orig_dir = sh_dir.gsub(/^\/shared/,'')
+
+ next if File.symlink?(orig_dir)
+
+ if File.exist?(orig_dir)
+ cmd = "cp -vaf #{orig_dir} #{File.dirname(sh_dir)}"
+ puts "Running: #{cmd}"
+ system(cmd)
+
+ cmd = "rm -vrf #{orig_dir}"
+ puts "Running: #{cmd}"
+ system(cmd)
+ end
+
+ FileUtils.ln_s(sh_dir, orig_dir, {:verbose => true})
+ end
+ puts 'Done.'
+ puts '_'
+ end
+
+ def self.run_puppet_agent()
+ puts '_'
+ puts 'Running Puppet Agent'
+ puts '--------------------'
+ exitcode = nil
+ 1.upto(3) do |ctr|
+ unless ctr == 1
+ puts '_'
+ puts "Previous puppet run failed with exit code [#{exitcode}], running again..."
+ puts '_'
+ end
+
+ system("bash -c 'time /usr/bin/puppet agent -t'")
+ exitcode = $?.exitstatus
+ puts "Exit Code [#{exitcode}]"
+
+ break if exitcode == 0 || exitcode == 2
+ end
+
+ raise "Puppet run failed, retries exhausted." if exitcode != 0 && exitcode != 2
+
+ puts 'Done.'
+ puts '_'
+
+ puts '_'
+ puts 'Creating ctr_configured flag'
+ FileUtils.mkdir_p(File.dirname(CTR_CONFIG_FLAG))
+ FileUtils.touch(CTR_CONFIG_FLAG)
+ puts 'Done.'
+ puts '_'
+ end
+
+ def self.exec_puppetd()
+ puts '_'
+ puts 'Exec-ing puppet daemon'
+ puts '---------------------'
+ puts "Starting puppet agent..."
+ exec("bash -c '/usr/bin/puppet agent --no-daemonize --detailed-exitcodes --verbose'")
+ end
+end
+
+if __FILE__ == $0
+ $stdout.sync = true
+ $stderr.sync = true
+
+ Start.setup_shared_dirs()
+ Start.run_puppet_agent()
+ Start.exec_puppetd()
+end