From 2d36a80698ec14c97a55d6cd81df9707b2e5f649 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 3 Feb 2021 13:09:21 -0500 Subject: [PATCH 1/5] Update to fit Synopsys CloudOPS environment.: --- recipes/default.rb | 18 ------------------ recipes/example.rb | 21 --------------------- recipes/kb_spider.rb | 11 +++++++++++ 3 files changed, 11 insertions(+), 39 deletions(-) create mode 100644 recipes/kb_spider.rb diff --git a/recipes/default.rb b/recipes/default.rb index 6bb3fec..42d2c8c 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -1,21 +1,3 @@ -# -# Cookbook Name:: pgbouncer -# Recipe:: default -# -# Copyright 2010-2013, Whitepages Inc. -# -# 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. -# # disable default system pgbouncer service if node['platform'] == 'ubuntu' diff --git a/recipes/example.rb b/recipes/example.rb index 4f09dcd..ce453ed 100644 --- a/recipes/example.rb +++ b/recipes/example.rb @@ -1,24 +1,3 @@ -# -# Cookbook Name:: pgbouncer -# Recipe:: example -# -# Copyright 2010-2013, Whitepages Inc. -# -# 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. -# - -# NOTE: -# This is an example of how to leverage the included resource pgbouncer_connection "database_example_com_ro" do db_host "database.example.com" diff --git a/recipes/kb_spider.rb b/recipes/kb_spider.rb new file mode 100644 index 0000000..d375f69 --- /dev/null +++ b/recipes/kb_spider.rb @@ -0,0 +1,11 @@ + +pgbouncer_connection "kb_spider" do + db_host "localhost" + db_port "5433" + listen_port "5432" + db_name "kb_spider" + userlist "apitest" => "md5f72b9285fd6b4f628c78cb4a17488c2c", "readonly_user" => "md500000000000000000000000000000000" + max_client_conn 100 + default_pool_size 20 + action [ :setup, :restart ] +end From 563bf1ec8f5c1c8529f01bbe99a610e8d0b1923a Mon Sep 17 00:00:00 2001 From: root Date: Wed, 3 Feb 2021 13:13:46 -0500 Subject: [PATCH 2/5] Update to fit Synopsys CloudOPS environment --- README.md | 54 +---------------------------------------------------- metadata.rb | 10 +++------- 2 files changed, 4 insertions(+), 60 deletions(-) diff --git a/README.md b/README.md index 57d89e0..d11e587 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ exposing a local *nix socket that routes to a downstream database on another hos Requirements ============ -Chef 0.7+ +Chef 1.4+ Platform -------- @@ -82,7 +82,6 @@ Multiple aliases may be supported on a single host. action :stop end - # TODO: include more examples Recipes ======= @@ -90,55 +89,4 @@ Recipes default ------- -Empty: this is a resource-only cookbook -example -------- - -Example of how to use the resource; also exercised in the spec/ tests - -Testing -======= - -This cookbook has been "Tested in Production"™, but also has some basic RSpec tests. - -**NOTE**: because Chef 10 has cookbook naming expectations, the root repo expects to be in a folder -named 'pgbouncer'. - - bundle install - bundle exec rake spec - -The cookbook is clean under FoodCritic. - - bundle install - bundle exec rake foodcritic - -To see the installation end to end, we've also got a rake task that spins up a [chef-zero](https://github.com/jkeiser/chef-zero) -local instance, uploads the cookbooks via berkshelf, and spins up a vagrant instance that pulls the data down. This is using a new -Vagrant plugin, created here at Whitepages, called [vagrant-chefzero](https://github.com/whitepages/vagrant-chefzero/). - - vagrant plugin install vagrant-chefzero - bundle install - bundle exec rake vagrant_startup - -License and Author(s) -===================== - -- Author:: Owyn Richen () -- Author:: Jack Foy () -- Author:: Paul Kohan () -- Author:: Brian Engelman () - -Copyright 2010-2013, [Whitepages Inc.](http://www.whitepages.com/) - -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. diff --git a/metadata.rb b/metadata.rb index 11222d3..412d6c1 100644 --- a/metadata.rb +++ b/metadata.rb @@ -1,16 +1,12 @@ name "pgbouncer" provides "pgbouncer" -maintainer "Whitepages Inc." -maintainer_email "orichen@whitepages.com" -license "Apache 2.0" +maintainer "Jay Yu" +maintainer_email "jayyu@synopsys.com" description "Installs/Configures pgbouncer" -long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) version "1.0.3" -recipe "pgbouncer", "the default recipe does nothing to hopefully indicate that this is an LWRP cookbook" -recipe "pgbouncer::example", "this gives an example of how one could consume the pgbouncer cookbook" %w{ubuntu}.each do |os| supports os end - depends "apt" + From 7505511a646771c2f14b95dd8ee552fa92ea5d93 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 3 Feb 2021 13:15:36 -0500 Subject: [PATCH 3/5] Update to fit Synopsys CloudOPS environment --- providers/connection.rb | 78 ++++++++++------------------------------- 1 file changed, 19 insertions(+), 59 deletions(-) diff --git a/providers/connection.rb b/providers/connection.rb index 1ded65a..bb059f3 100644 --- a/providers/connection.rb +++ b/providers/connection.rb @@ -2,20 +2,6 @@ # Cookbook Name:: pgbouncer # Provider:: connection # -# Copyright 2010-2013, Whitepages Inc. -# -# 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. -# require 'set' @@ -25,30 +11,27 @@ def initialize(*args) end action :start do - service "pgbouncer-#{new_resource.db_alias}-start" do - service_name "pgbouncer-#{new_resource.db_alias}" # this is to eliminate warnings around http://tickets.opscode.com/browse/CHEF-3694 - provider Chef::Provider::Service::Upstart + service "pgbouncer-start" do + service_name "pgbouncer" # this is to eliminate warnings around http://tickets.opscode.com/browse/CHEF-3694 + provider Chef::Provider::Service::Systemd action [:enable, :start, :reload] end - new_resource.updated_by_last_action(true) end action :restart do - service "pgbouncer-#{new_resource.db_alias}-restart" do - service_name "pgbouncer-#{new_resource.db_alias}" # this is to eliminate warnings around http://tickets.opscode.com/browse/CHEF-3694 - provider Chef::Provider::Service::Upstart + service "pgbouncer-restart" do + service_name "pgbouncer" # this is to eliminate warnings around http://tickets.opscode.com/browse/CHEF-3694 + provider Chef::Provider::Service::Systemd action [:enable, :restart] end - new_resource.updated_by_last_action(true) end action :stop do - service "pgbouncer-#{new_resource.db_alias}-stop" do - service_name "pgbouncer-#{new_resource.db_alias}" # this is to eliminate warnings around http://tickets.opscode.com/browse/CHEF-3694 - provider Chef::Provider::Service::Upstart + service "pgbouncer-stop" do + service_name "pgbouncer" # this is to eliminate warnings around http://tickets.opscode.com/browse/CHEF-3694 + provider Chef::Provider::Service::Systemd action :stop end - new_resource.updated_by_last_action(true) end action :setup do @@ -78,36 +61,18 @@ def initialize(*args) action [:install, :upgrade] end - service "pgbouncer-#{new_resource.db_alias}" do - provider Chef::Provider::Service::Upstart + service "pgbouncer" do + provider Chef::Provider::Service::Systemd supports :enable => true, :start => true, :restart => true, :reload => true action :nothing end - # create the log, pid, db_sockets, /etc/pgbouncer, and application socket directories - Set.new([ - new_resource.log_dir, - new_resource.pid_dir, - new_resource.socket_dir, - ::File.expand_path(::File.join(new_resource.socket_dir, new_resource.db_alias)), - '/etc/pgbouncer' - ]).each do |dir| - directory "#{new_resource.name}::#{dir}" do - path dir - action :create - recursive true - owner new_resource.user - group new_resource.group - mode 0775 - end - end - # build the userlist, pgbouncer.ini, upstart conf and logrotate.d templates { - "/etc/pgbouncer/userlist-#{new_resource.db_alias}.txt" => 'etc/pgbouncer/userlist.txt.erb', - "/etc/pgbouncer/pgbouncer-#{new_resource.db_alias}.ini" => 'etc/pgbouncer/pgbouncer.ini.erb', - "/etc/init/pgbouncer-#{new_resource.db_alias}.conf" => 'etc/init/pgbouncer.conf.erb', - "/etc/logrotate.d/pgbouncer-#{new_resource.db_alias}" => 'etc/logrotate.d/pgbouncer-logrotate.d.erb' + "/etc/pgbouncer/userlist.txt" => 'etc/pgbouncer/userlist.txt.erb', + "/etc/pgbouncer/pgbouncer.ini" => 'etc/pgbouncer/pgbouncer.ini.erb', + "/etc/init/pgbouncer.conf" => 'etc/init/pgbouncer.conf.erb', + "/etc/logrotate.d/pgbouncer" => 'etc/logrotate.d/pgbouncer-logrotate.d.erb' }.each do |key, source_template| ## We are setting destination_file to a duplicate of key because the hash ## key is frozen and immutable. @@ -135,9 +100,6 @@ def initialize(*args) listen_port: new_resource.listen_port, user: new_resource.user, group: new_resource.group, - log_dir: new_resource.log_dir, - socket_dir: new_resource.socket_dir, - pid_dir: new_resource.pid_dir, pool_mode: new_resource.pool_mode, max_client_conn: new_resource.max_client_conn, default_pool_size: new_resource.default_pool_size, @@ -163,20 +125,18 @@ def initialize(*args) end end - new_resource.updated_by_last_action(true) end action :teardown do - { "/etc/pgbouncer/userlist-#{new_resource.db_alias}.txt" => 'etc/pgbouncer/userlist.txt.erb', - "/etc/pgbouncer/pgbouncer-#{new_resource.db_alias}.ini" => 'etc/pgbouncer/pgbouncer.ini.erb', - "/etc/init/pgbouncer-#{new_resource.db_alias}.conf" => 'etc/pgbouncer/pgbouncer.conf', - "/etc/logrotate.d/pgbouncer-#{new_resource.db_alias}" => 'etc/logrotate.d/pgbouncer-logrotate.d' + { "/etc/pgbouncer/userlist.txt" => 'etc/pgbouncer/userlist.txt.erb', + "/etc/pgbouncer/pgbouncer.ini" => 'etc/pgbouncer/pgbouncer.ini.erb', + "/etc/init/pgbouncer.conf" => 'etc/pgbouncer/pgbouncer.conf', + "/etc/logrotate.d/pgbouncer" => 'etc/logrotate.d/pgbouncer-logrotate.d' }.each do |destination_file, source_template| file destination_file do action :delete end end - new_resource.updated_by_last_action(true) end From a5ae8976697ab56a8b8c7573466d841582ee80b7 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 3 Feb 2021 13:16:00 -0500 Subject: [PATCH 4/5] Update to fit Synopsys CloudOPS environment --- resources/connection.rb | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/resources/connection.rb b/resources/connection.rb index 94fb827..79f36f2 100644 --- a/resources/connection.rb +++ b/resources/connection.rb @@ -2,20 +2,6 @@ # Cookbook Name:: pgbouncer # Resource:: connection # -# Copyright 2010-2013, Whitepages Inc. -# -# 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. -# actions :setup, :teardown, :start, :restart, :stop default_action :setup @@ -36,11 +22,11 @@ attribute :listen_addr, :kind_of => String, :default => '*' attribute :listen_port, :kind_of => String -attribute :user, :kind_of => String, :default => 'pgbouncer' -attribute :group, :kind_of => String, :default => 'pgbouncer' -attribute :log_dir, :kind_of => String, :default => '/var/log/pgbouncer' -attribute :socket_dir, :kind_of => String, :default => '/var/run/pgbouncer' -attribute :pid_dir, :kind_of => String, :default => '/var/run/pgbouncer' +attribute :user, :kind_of => String, :default => 'postgres' +attribute :group, :kind_of => String, :default => 'postgres' +attribute :log_dir, :kind_of => String, :default => '/var/log/postgres' +attribute :socket_dir, :kind_of => String, :default => '/var/run/postgres' +attribute :pid_dir, :kind_of => String, :default => '/var/run/postgres' attribute :pool_mode, :kind_of => String, :default => 'transaction' attribute :max_client_conn, :kind_of => Integer, :default => 1000 From d04e1909ab723372fdaef390fcc5487581424f21 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 3 Feb 2021 13:16:29 -0500 Subject: [PATCH 5/5] Update to fit Synopsys CloudOPS environment --- templates/default/etc/pgbouncer/pgbouncer.ini.erb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/templates/default/etc/pgbouncer/pgbouncer.ini.erb b/templates/default/etc/pgbouncer/pgbouncer.ini.erb index c774f32..c73c718 100644 --- a/templates/default/etc/pgbouncer/pgbouncer.ini.erb +++ b/templates/default/etc/pgbouncer/pgbouncer.ini.erb @@ -24,8 +24,8 @@ ;;; Administrative settings ;;; -logfile = <%= @log_dir %>/pgbouncer-<%= @db_alias %>.log -pidfile = <%= @pid_dir %>/pgbouncer-<%= @db_alias %>.pid +logfile = /var/log/postgresql/pgbouncer.log +pidfile = /var/run/postgresql/pgbouncer.pid ;;; ;;; Where to wait for clients @@ -38,7 +38,8 @@ pidfile = <%= @pid_dir %>/pgbouncer-<%= @db_alias %>.pid ; unix socket is also used for -R. ; On debian it should be /var/run/postgresql -unix_socket_dir = <%= @socket_dir %>/<%= @db_alias %>/ + +unix_socket_dir = /var/run/postgresql ;;; ;;; Authentication settings @@ -46,7 +47,7 @@ unix_socket_dir = <%= @socket_dir %>/<%= @db_alias %>/ ; any, trust, plain, crypt, md5 auth_type = md5 -auth_file = /etc/pgbouncer/userlist-<%= @db_alias %>.txt +auth_file = /etc/pgbouncer/userlist.txt ;;; ;;; Users allowed into database 'pgbouncer'