Class: ActivePostgres::Components::PgBouncer
- Defined in:
- lib/active_postgres/components/pgbouncer.rb
Instance Attribute Summary
Attributes inherited from Base
#config, #secrets, #ssh_executor
Instance Method Summary collapse
- #install ⇒ Object
- #install_on_standby(standby_host) ⇒ Object
- #restart ⇒ Object
- #uninstall ⇒ Object
- #update_userlist ⇒ Object
Methods inherited from Base
Constructor Details
This class inherits a constructor from ActivePostgres::Components::Base
Instance Method Details
#install ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/active_postgres/components/pgbouncer.rb', line 4 def install puts 'Installing PgBouncer for connection pooling...' config.all_hosts.each do |host| is_standby = config.standby_hosts.include?(host) install_on_host(host, is_standby: is_standby) end pgbouncer_app_hosts.each do |app_host| install_on_app_host(app_host) end end |
#install_on_standby(standby_host) ⇒ Object
64 65 66 67 |
# File 'lib/active_postgres/components/pgbouncer.rb', line 64 def install_on_standby(standby_host) puts "Installing PgBouncer on standby #{standby_host}..." install_on_host(standby_host, is_standby: true) end |
#restart ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/active_postgres/components/pgbouncer.rb', line 33 def restart puts 'Restarting PgBouncer...' (config.all_hosts + pgbouncer_app_hosts.map { |app_host| app_host.fetch('host') }).each do |host| ssh_executor.execute_on_host(host) do execute :sudo, 'systemctl', 'restart', 'pgbouncer' end end end |
#uninstall ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/active_postgres/components/pgbouncer.rb', line 17 def uninstall puts 'Uninstalling PgBouncer...' (config.all_hosts + pgbouncer_app_hosts.map { |app_host| app_host.fetch('host') }).each do |host| ssh_executor.execute_on_host(host) do execute :sudo, 'systemctl', 'disable', '--now', 'pgbouncer-follow-primary.timer', '||', 'true' execute :sudo, 'rm', '-f', '/usr/local/bin/pgbouncer-follow-primary', '/etc/systemd/system/pgbouncer-follow-primary.service', '/etc/systemd/system/pgbouncer-follow-primary.timer' execute :sudo, 'systemctl', 'daemon-reload' execute :sudo, 'systemctl', 'stop', 'pgbouncer' execute :sudo, 'apt-get', 'remove', '-y', 'pgbouncer' end end end |
#update_userlist ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/active_postgres/components/pgbouncer.rb', line 43 def update_userlist puts 'Updating PgBouncer userlist on all hosts...' config.all_hosts.each do |host| create_userlist(host) ssh_executor.execute_on_host(host) do execute :sudo, 'systemctl', 'reload', 'pgbouncer' end end pgbouncer_app_hosts.each do |app_host| host = app_host.fetch('host') create_userlist_from_primary(host) ssh_executor.execute_on_host(host) do execute :sudo, 'systemctl', 'reload', 'pgbouncer' end end end |