Created
October 5, 2015 22:50
-
-
Save eheydrick/c16f85f7ab8a2a9d3c5d to your computer and use it in GitHub Desktop.
install the pg gem into sensu's ruby installation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Super hacky way to get the pg gem installed into Sensu's ruby installation. | |
| # Ripped off from https://github.com/hw-cookbooks/postgresql/blob/develop/recipes/ruby.rb | |
| # Credit to chrisroberts for this | |
| gem_installed = system("/opt/sensu/embedded/bin/ruby -e \"require 'pg'\"") | |
| pg_gem_version = '0.18.3' | |
| unless gem_installed | |
| Chef::Log.warn('pg gem is not installed in the sensu ruby installation. Installing it') | |
| g = gem_package 'pg' do | |
| version pg_gem_version | |
| gem_binary '/opt/sensu/embedded/bin/gem' | |
| ignore_failure true | |
| end | |
| g.run_action(:install) | |
| if platform_family?('ubuntu', 'debian') | |
| e = execute 'apt-get update' do | |
| action :nothing | |
| end | |
| e.run_action(:run) unless ::File.exist?('/var/lib/apt/periodic/update-success-stamp') | |
| end | |
| node.set['build-essential']['compile_time'] = true | |
| include_recipe 'build-essential' | |
| include_recipe 'postgresql::client' | |
| if node['postgresql']['enable_pgdg_yum'] | |
| repo_rpm_url, repo_rpm_filename, repo_rpm_package = pgdgrepo_rpm_info | |
| include_recipe 'postgresql::yum_pgdg_postgresql' | |
| resources("remote_file[#{Chef::Config[:file_cache_path]}/#{repo_rpm_filename}]").run_action(:create) | |
| resources("package[#{repo_rpm_package}]").run_action(:install) | |
| ENV['PATH'] = "/usr/pgsql-#{node['postgresql']['version']}/bin:#{ENV['PATH']}" | |
| end | |
| if node['postgresql']['enable_pgdg_apt'] | |
| include_recipe 'postgresql::apt_pgdg_postgresql' | |
| resources('file[remove deprecated Pitti PPA apt repository]').run_action(:delete) | |
| resources('apt_repository[apt.postgresql.org]').run_action(:add) | |
| end | |
| node['postgresql']['client']['packages'].each do |pg_pack| | |
| resources("package[#{pg_pack}]").run_action(:install) | |
| end | |
| # Still here, must be omnibus. Lets make this thing install! | |
| Chef::Log.warn 'Failed to properly build pg gem. Forcing properly linking and retrying (omnibus fix)' | |
| gem_dir = File.join('/opt/sensu/embedded/lib/ruby/gems/2.0.0/gems', 'pg-' + pg_gem_version) | |
| fail unless gem_dir | |
| gem_name = File.basename(gem_dir) | |
| ext_dir = File.join(gem_dir, 'ext') | |
| gem_exec = '/opt/sensu/embedded/bin/gem' | |
| new_content = <<-EOS | |
| require 'rbconfig' | |
| %w( | |
| configure_args | |
| LIBRUBYARG_SHARED | |
| LIBRUBYARG_STATIC | |
| LIBRUBYARG | |
| LDFLAGS | |
| ).each do |key| | |
| RbConfig::CONFIG[key].gsub!(/-Wl[^ ]+( ?\\/[^ ]+)?/, '') | |
| RbConfig::MAKEFILE_CONFIG[key].gsub!(/-Wl[^ ]+( ?\\/[^ ]+)?/, '') | |
| end | |
| RbConfig::CONFIG['RPATHFLAG'] = '' | |
| RbConfig::MAKEFILE_CONFIG['RPATHFLAG'] = '' | |
| EOS | |
| extconf_path = File.join(ext_dir, 'extconf.rb') | |
| if File.exist?(extconf_path) | |
| new_content << File.read(extconf_path) | |
| File.open(extconf_path, 'w') do |file| | |
| file.write(new_content) | |
| end | |
| lib_builder = execute 'generate pg gem Makefile' do | |
| # [COOK-3490] pg gem install requires full path on RHEL | |
| command "PATH=$PATH:/usr/pgsql-#{node['postgresql']['version']}/bin /opt/sensu/embedded/bin/ruby extconf.rb" | |
| cwd ext_dir | |
| action :nothing | |
| end | |
| lib_builder.run_action(:run) | |
| lib_maker = execute 'make pg gem lib' do | |
| command 'make' | |
| cwd ext_dir | |
| action :nothing | |
| end | |
| lib_maker.run_action(:run) | |
| lib_installer = execute 'install pg gem lib' do | |
| command 'make install' | |
| cwd ext_dir | |
| action :nothing | |
| end | |
| lib_installer.run_action(:run) | |
| spec_installer = execute 'install pg spec' do | |
| command "#{gem_exec} spec ./cache/#{gem_name}.gem --ruby > ./specifications/#{gem_name}.gemspec" | |
| cwd File.join(gem_dir, '..', '..') | |
| action :nothing | |
| end | |
| spec_installer.run_action(:run) | |
| Chef::Log.warn 'Installation of pg gem successful!' | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment