PageRenderTime 25ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/all.rb

https://bitbucket.org/tsacha/postgresql-clustering
Ruby | 474 lines | 397 code | 72 blank | 5 comment | 35 complexity | 6c35fd871fab03300167a96905910e94 MD5 | raw file
  1. #!/usr/bin/env ruby
  2. # -*- coding: utf-8 -*-
  3. load 'const.rb'
  4. require 'optparse'
  5. require 'fileutils'
  6. options = {:verbose => false, :init => true, :install => true, :compile => true, :remote => true, :master => true, :slave => true, :slavebis => true, :pgpool => true, :config => true, :launch => true, :reset => false}
  7. OptionParser.new do |opts|
  8. opts.banner = "Usage: all.rb [options]"
  9. opts.on("-v", "--verbose", "Run verbosely") do |v|
  10. options[:verbose] = v
  11. end
  12. opts.on("-i", "--[no-]install", "Install PostgreSQL") do |i|
  13. options[:install] = i
  14. end
  15. opts.on("-j", "--[no-]init", "Initialisation of PostgreSQL") do |j|
  16. options[:init] = j
  17. end
  18. opts.on("-t", "--[no-]compile", "Compilation of PostgreSQL") do |t|
  19. options[:compile] = t
  20. end
  21. opts.on("-r", "--[no-]remote", "Send remote scripts and install Ruby on remote servers") do |r|
  22. options[:remote] = r
  23. end
  24. opts.on("-c", "--[no-]config", "Configure servers") do |c|
  25. options[:config] = c
  26. end
  27. opts.on("-l", "--[no-]launch", "Launch servers") do |l|
  28. options[:launch] = l
  29. end
  30. opts.on("-m", "--[no-]master", "Prepare master server") do |m|
  31. options[:master] = m
  32. end
  33. opts.on("-s", "--[no-]slave", "Prepare slave server") do |s|
  34. options[:slave] = s
  35. end
  36. opts.on("-b", "--[no-]slavebis", "Prepare second slave server") do |b|
  37. options[:slavebis] = b
  38. end
  39. opts.on("-p", "--[no-]pgpool", "Prepare pgpool server") do |p|
  40. options[:pgpool] = p
  41. end
  42. opts.on("--reset", "Reset all remote servers") do |reset|
  43. options[:reset] = reset
  44. end
  45. end.parse!
  46. if options[:reset]
  47. puts "Réinitialisation des serveurs…"
  48. if options[:master]
  49. master = Thread.new() {
  50. if options[:remote]
  51. puts "Envoi du script de réinitialisation…"
  52. `scp -P #{PORT_SSH_MASTER} reset.rb #{HOST_MASTER}:/tmp`
  53. puts "Envoi des constantes…"
  54. `scp -P #{PORT_SSH_MASTER} const.rb #{HOST_MASTER}:/tmp`
  55. end
  56. puts "Réinitialisation du serveur maître…"
  57. system("ssh #{HOST_MASTER} -p #{PORT_SSH_MASTER} ruby /tmp/reset.rb")
  58. }
  59. end
  60. if options[:slave]
  61. slave = Thread.new() {
  62. if options[:remote]
  63. puts "Envoi du script de réinitialisation…"
  64. `scp -P #{PORT_SSH_SLAVE} reset.rb #{HOST_SLAVE}:/tmp`
  65. puts "Envoi des constantes…"
  66. `scp -P #{PORT_SSH_SLAVE} const.rb #{HOST_SLAVE}:/tmp`
  67. end
  68. puts "Réinitialisation du serveur esclave…"
  69. system("ssh #{HOST_SLAVE} -p #{PORT_SSH_SLAVE} ruby /tmp/reset.rb")
  70. }
  71. end
  72. if options[:slavebis]
  73. slavebis = Thread.new() {
  74. if options[:remote]
  75. puts "Envoi du script de réinitialisation…"
  76. `scp -P #{PORT_SSH_SLAVE2} reset.rb #{HOST_SLAVE2}:/tmp`
  77. puts "Envoi des constantes…"
  78. `scp -P #{PORT_SSH_SLAVE2} const.rb #{HOST_SLAVE2}:/tmp`
  79. end
  80. puts "Réinitialisation du serveur esclave…"
  81. system("ssh #{HOST_SLAVE2} -p #{PORT_SSH_SLAVE2} ruby /tmp/reset.rb")
  82. }
  83. end
  84. if options[:pgpool]
  85. pgpool = Thread.new() {
  86. if options[:remote]
  87. puts "Envoi du script de réinitialisation…"
  88. `scp -P #{PORT_SSH_PGPOOL} reset.rb #{HOST_PGPOOL}:/tmp`
  89. puts "Envoi des constantes…"
  90. `scp -P #{PORT_SSH_PGPOOL} const.rb #{HOST_PGPOOL}:/tmp`
  91. end
  92. puts "Réinitialisation du serveur PgPool…"
  93. system("ssh #{HOST_PGPOOL} -p #{PORT_SSH_PGPOOL} ruby /tmp/reset.rb")
  94. }
  95. end
  96. if options[:master]
  97. master.join
  98. end
  99. if options[:slave]
  100. slave.join
  101. end
  102. if options[:slavebis]
  103. slavebis.join
  104. end
  105. if options[:pgpool]
  106. pgpool.join
  107. end
  108. exit 0
  109. end
  110. puts
  111. puts "------"
  112. puts "Exécution du script d'installation de PosgreSQL"
  113. puts "------"
  114. puts
  115. if (options[:reset]) || (not File.exists?(INSTALL_FOLDER+'/ssh/id_rsa'))
  116. puts "Génération de la clé SSH commune…"
  117. system("ssh-keygen -f #{INSTALL_FOLDER}/ssh/id_rsa -N ''")
  118. end
  119. if options[:pgpool]
  120. pgpool = Thread.new() {
  121. # Installation de la machine pgpool
  122. if options[:remote]
  123. puts "Création du répertoire d'installation…"
  124. `ssh #{HOST_PGPOOL} -p #{PORT_SSH_PGPOOL} mkdir -p #{INSTALL_FOLDER}`
  125. puts "Envoi du script d'installation de PostgreSQL…"
  126. `scp -P #{PORT_SSH_PGPOOL} init_psql.rb #{HOST_PGPOOL}:#{INSTALL_FOLDER}`
  127. puts "Envoi des constantes d'installation…"
  128. `scp -P #{PORT_SSH_PGPOOL} const.rb #{HOST_PGPOOL}:#{INSTALL_FOLDER}`
  129. puts "Envoi du script de configuration du serveur pgPool…"
  130. `scp -P #{PORT_SSH_PGPOOL} pgpool.rb #{HOST_PGPOOL}:#{INSTALL_FOLDER}`
  131. puts "Installation de Ruby…"
  132. `ssh #{HOST_PGPOOL} -p #{PORT_SSH_PGPOOL} yum -y install ruby`
  133. end
  134. if options[:install]
  135. if options[:init]
  136. puts "Installation de PostgreSQL…"
  137. if options[:compile]
  138. system("ssh #{HOST_PGPOOL} -p #{PORT_SSH_PGPOOL} ruby #{INSTALL_FOLDER}/init_psql.rb")
  139. else
  140. system("ssh #{HOST_PGPOOL} -p #{PORT_SSH_PGPOOL} ruby #{INSTALL_FOLDER}/init_psql.rb --no-compile")
  141. end
  142. end
  143. puts "Envoi de la clé SSH commune au serveur pgPool"
  144. `scp -P #{PORT_SSH_PGPOOL} #{INSTALL_FOLDER}/ssh/id_rsa #{HOST_PGPOOL}:#{PSQL_FOLDER}/.ssh/`
  145. `scp -P #{PORT_SSH_PGPOOL} #{INSTALL_FOLDER}/ssh/id_rsa.pub #{HOST_PGPOOL}:#{PSQL_FOLDER}/.ssh/`
  146. `ssh #{HOST_PGPOOL} -p #{PORT_SSH_PGPOOL} 'cp #{PSQL_FOLDER}/.ssh/id_rsa.pub #{PSQL_FOLDER}/.ssh/authorized_keys; chown -R postgres:postgres #{PSQL_FOLDER}/.ssh'`
  147. end
  148. }
  149. end
  150. if options[:slave]
  151. slave = Thread.new() {
  152. # Installation de la machine esclave
  153. if options[:remote]
  154. puts "Création du répertoire d'installation…"
  155. `ssh #{HOST_SLAVE} -p #{PORT_SSH_SLAVE} mkdir -p #{INSTALL_FOLDER}`
  156. puts "Envoi du script d'installation de PostgreSQL…"
  157. `scp -P #{PORT_SSH_SLAVE} init_psql.rb #{HOST_SLAVE}:#{INSTALL_FOLDER}`
  158. puts "Envoi des constantes d'installation…"
  159. `scp -P #{PORT_SSH_SLAVE} const.rb #{HOST_SLAVE}:#{INSTALL_FOLDER}`
  160. puts "Envoi du script de configuration du serveur secondaire…"
  161. `scp -P #{PORT_SSH_SLAVE} slave.rb #{HOST_SLAVE}:#{INSTALL_FOLDER}`
  162. puts "Envoi du script de lancement du serveur esclave…"
  163. `scp -P #{PORT_SSH_SLAVE} slave_launch.rb #{HOST_SLAVE}:#{INSTALL_FOLDER}`
  164. puts "Installation de Ruby…"
  165. `ssh #{HOST_SLAVE} -p #{PORT_SSH_SLAVE} yum -y install ruby`
  166. end
  167. if options[:install]
  168. if options[:init]
  169. puts "Installation de PostgreSQL…"
  170. if options[:compile]
  171. system("ssh #{HOST_SLAVE} -p #{PORT_SSH_SLAVE} ruby #{INSTALL_FOLDER}/init_psql.rb")
  172. else
  173. system("ssh #{HOST_SLAVE} -p #{PORT_SSH_SLAVE} ruby #{INSTALL_FOLDER}/init_psql.rb --no-compile")
  174. end
  175. end
  176. puts "Envoi de la clé SSH commune au serveur esclave"
  177. `scp -P #{PORT_SSH_SLAVE} #{INSTALL_FOLDER}/ssh/id_rsa #{HOST_SLAVE}:#{PSQL_FOLDER}/.ssh/`
  178. `scp -P #{PORT_SSH_SLAVE} #{INSTALL_FOLDER}/ssh/id_rsa.pub #{HOST_SLAVE}:#{PSQL_FOLDER}/.ssh/`
  179. `ssh #{HOST_SLAVE} -p #{PORT_SSH_SLAVE} 'cp #{PSQL_FOLDER}/.ssh/id_rsa.pub #{PSQL_FOLDER}/.ssh/authorized_keys; chown -R postgres:postgres #{PSQL_FOLDER}/.ssh'`
  180. end
  181. }
  182. end
  183. if options[:slavebis]
  184. slavebis = Thread.new() {
  185. # Installation de la machine esclave
  186. if options[:remote]
  187. puts "Création du répertoire d'installation…"
  188. `ssh #{HOST_SLAVE2} -p #{PORT_SSH_SLAVE2} mkdir -p #{INSTALL_FOLDER}`
  189. puts "Envoi du script d'installation de PostgreSQL…"
  190. `scp -P #{PORT_SSH_SLAVE2} init_psql.rb #{HOST_SLAVE2}:#{INSTALL_FOLDER}`
  191. puts "Envoi des constantes d'installation…"
  192. `scp -P #{PORT_SSH_SLAVE2} const.rb #{HOST_SLAVE2}:#{INSTALL_FOLDER}`
  193. puts "Envoi du script de configuration du serveur secondaire…"
  194. `scp -P #{PORT_SSH_SLAVE2} slave.rb #{HOST_SLAVE2}:#{INSTALL_FOLDER}`
  195. puts "Envoi du script de lancement du serveur esclave…"
  196. `scp -P #{PORT_SSH_SLAVE2} slave_launch.rb #{HOST_SLAVE2}:#{INSTALL_FOLDER}`
  197. puts "Installation de Ruby…"
  198. `ssh #{HOST_SLAVE2} -p #{PORT_SSH_SLAVE2} yum -y install ruby`
  199. end
  200. if options[:install]
  201. if options[:init]
  202. puts "Installation de PostgreSQL…"
  203. if options[:compile]
  204. system("ssh #{HOST_SLAVE2} -p #{PORT_SSH_SLAVE2} ruby #{INSTALL_FOLDER}/init_psql.rb")
  205. else
  206. system("ssh #{HOST_SLAVE2} -p #{PORT_SSH_SLAVE2} ruby #{INSTALL_FOLDER}/init_psql.rb --no-compile")
  207. end
  208. end
  209. puts "Envoi de la clé SSH commune au serveur esclave"
  210. `scp -P #{PORT_SSH_SLAVE2} #{INSTALL_FOLDER}/ssh/id_rsa #{HOST_SLAVE2}:#{PSQL_FOLDER}/.ssh/`
  211. `scp -P #{PORT_SSH_SLAVE2} #{INSTALL_FOLDER}/ssh/id_rsa.pub #{HOST_SLAVE2}:#{PSQL_FOLDER}/.ssh/`
  212. `ssh #{HOST_SLAVE2} -p #{PORT_SSH_SLAVE2} 'cp #{PSQL_FOLDER}/.ssh/id_rsa.pub #{PSQL_FOLDER}/.ssh/authorized_keys; chown -R postgres:postgres #{PSQL_FOLDER}/.ssh'`
  213. end
  214. }
  215. end
  216. if options[:master]
  217. master = Thread.new() {
  218. # Installation de la machine maître
  219. if options[:remote]
  220. puts "Création du répertoire d'installation…"
  221. `ssh #{HOST_MASTER} -p #{PORT_SSH_MASTER} mkdir -p #{INSTALL_FOLDER}`
  222. puts "Envoi du script d'installation de PostgreSQL…"
  223. `scp -P #{PORT_SSH_MASTER} init_psql.rb #{HOST_MASTER}:#{INSTALL_FOLDER}`
  224. puts "Envoi des constantes d'installation…"
  225. `scp -P #{PORT_SSH_MASTER} const.rb #{HOST_MASTER}:#{INSTALL_FOLDER}`
  226. puts "Envoi du script de configuration du serveur maître…"
  227. `scp -P #{PORT_SSH_MASTER} master.rb #{HOST_MASTER}:#{INSTALL_FOLDER}`
  228. puts "Envoi du script de lancement du serveur maître…"
  229. `scp -P #{PORT_SSH_MASTER} master_launch.rb #{HOST_MASTER}:#{INSTALL_FOLDER}`
  230. puts "Installation de Ruby…"
  231. `ssh #{HOST_MASTER} -p #{PORT_SSH_MASTER} yum -y install ruby`
  232. end
  233. if options[:install]
  234. if options[:init]
  235. puts "Installation de PostgreSQL…"
  236. if options[:compile]
  237. system("ssh #{HOST_MASTER} -p #{PORT_SSH_MASTER} ruby #{INSTALL_FOLDER}/init_psql.rb")
  238. else
  239. system("ssh #{HOST_MASTER} -p #{PORT_SSH_MASTER} ruby #{INSTALL_FOLDER}/init_psql.rb --no-compile")
  240. end
  241. end
  242. puts "Envoi de la clé SSH commune au serveur maître"
  243. `scp -P #{PORT_SSH_MASTER} #{INSTALL_FOLDER}/ssh/id_rsa #{HOST_MASTER}:#{PSQL_FOLDER}/.ssh/`
  244. `scp -P #{PORT_SSH_MASTER} #{INSTALL_FOLDER}/ssh/id_rsa.pub #{HOST_MASTER}:#{PSQL_FOLDER}/.ssh/`
  245. `ssh #{HOST_MASTER} -p #{PORT_SSH_MASTER} 'cp #{PSQL_FOLDER}/.ssh/id_rsa.pub #{PSQL_FOLDER}/.ssh/authorized_keys; chown -R postgres:postgres #{PSQL_FOLDER}/.ssh'`
  246. end
  247. if options[:config]
  248. puts "Réécriture des fichiers de configuration PostgreSQL…"
  249. FileUtils.cp(INSTALL_FOLDER+'/master/postgresql.conf.template',INSTALL_FOLDER+'/master/postgresql.conf')
  250. FileUtils.cp(INSTALL_FOLDER+'/master/pg_hba.conf.template',INSTALL_FOLDER+'/master/pg_hba.conf')
  251. file_names = [INSTALL_FOLDER+'/master/postgresql.conf', INSTALL_FOLDER+'/master/pg_hba.conf']
  252. file_names.each do |file_name|
  253. replace = File.read(file_name)
  254. replace = replace.gsub(/HOST_MASTER/, HOST_MASTER)
  255. replace = replace.gsub(/PORT_PSQL_MASTER/, PORT_PSQL_MASTER)
  256. replace = replace.gsub(/PORT_SSH_SLAVE2/, PORT_SSH_SLAVE2)
  257. replace = replace.gsub(/PORT_SSH_SLAVE/, PORT_SSH_SLAVE)
  258. replace = replace.gsub(/PSQL_USER/, PSQL_USER)
  259. replace = replace.gsub(/HOST_SLAVE2_IP/, HOST_SLAVE2_IP)
  260. replace = replace.gsub(/HOST_SLAVE_IP/, HOST_SLAVE_IP)
  261. replace = replace.gsub(/HOST_PGPOOL_IP/, HOST_PGPOOL_IP)
  262. replace = replace.gsub(/HOST_SLAVE2/, HOST_SLAVE2)
  263. replace = replace.gsub(/HOST_SLAVE/, HOST_SLAVE)
  264. replace = replace.gsub(/PSQL_FOLDER/, PSQL_FOLDER)
  265. replace = replace.gsub(/SYNC_MASTER/, SYNC_MASTER)
  266. File.open(file_name, "w") { |file| file.puts replace }
  267. `scp -P #{PORT_SSH_MASTER} #{file_name} #{HOST_MASTER}:#{PSQL_FOLDER}/conf/#{File.basename(file_name)}`
  268. end
  269. end
  270. }
  271. if options[:slave]
  272. slave.join
  273. end
  274. if options[:slavebis]
  275. slavebis.join
  276. end
  277. masterConfig = Thread.new {
  278. puts "Configuration du serveur maître…"
  279. system("ssh #{HOST_MASTER} -p #{PORT_SSH_MASTER} ruby #{INSTALL_FOLDER}/master.rb")
  280. puts "Récupération de la base de données du serveur maître…"
  281. }
  282. end
  283. if options[:master]
  284. masterConfig.join
  285. end
  286. slaveConfig = Thread.new {
  287. if options[:slave]
  288. if options[:config]
  289. puts "Réécriture des fichiers de configuration PostgreSQL…"
  290. FileUtils.cp(INSTALL_FOLDER+'/slave/postgresql.conf.template',INSTALL_FOLDER+'/slave/postgresql.conf')
  291. FileUtils.cp(INSTALL_FOLDER+'/slave/pg_hba.conf.template',INSTALL_FOLDER+'/slave/pg_hba.conf')
  292. FileUtils.cp(INSTALL_FOLDER+'/slave/recovery.conf.template',INSTALL_FOLDER+'/slave/recovery.conf')
  293. file_names = [INSTALL_FOLDER+'/slave/postgresql.conf', INSTALL_FOLDER+'/slave/pg_hba.conf', INSTALL_FOLDER+'/slave/recovery.conf']
  294. file_names.each do |file_name|
  295. replace = File.read(file_name)
  296. replace = replace.gsub(/HOST_MASTER_IP/, HOST_MASTER_IP)
  297. replace = replace.gsub(/HOST_PGPOOL_IP/, HOST_PGPOOL_IP)
  298. replace = replace.gsub(/HOST_MASTER/, HOST_MASTER)
  299. replace = replace.gsub(/PORT_PSQL_MASTER/, PORT_PSQL_MASTER)
  300. replace = replace.gsub(/PORT_PSQL_SLAVE2/, PORT_PSQL_SLAVE2)
  301. replace = replace.gsub(/PORT_PSQL_SLAVE/, PORT_PSQL_SLAVE)
  302. replace = replace.gsub(/PORT_SSH_SLAVE2/, PORT_SSH_SLAVE2)
  303. replace = replace.gsub(/PORT_SSH_SLAVE/, PORT_SSH_SLAVE)
  304. replace = replace.gsub(/PSQL_USER/, PSQL_USER)
  305. replace = replace.gsub(/PSQL_FOLDER/, PSQL_FOLDER)
  306. replace = replace.gsub(/HOT_STANDBY_SLAVE/, HOT_STANDBY_SLAVE)
  307. replace = replace.gsub(/SYNC_MASTER/, SYNC_MASTER)
  308. File.open(file_name, "w") { |file| file.puts replace }
  309. `scp -P #{PORT_SSH_SLAVE} #{file_name} #{HOST_SLAVE}:#{PSQL_FOLDER}/conf/#{File.basename(file_name)}`
  310. end
  311. puts "Configuration du serveur esclave…"
  312. system("ssh #{HOST_SLAVE} -p #{PORT_SSH_SLAVE} ruby #{INSTALL_FOLDER}/slave.rb")
  313. end
  314. end
  315. }
  316. slavebisConfig = Thread.new {
  317. if options[:slavebis]
  318. if options[:config]
  319. puts "Réécriture des fichiers de configuration PostgreSQL…"
  320. FileUtils.cp(INSTALL_FOLDER+'/slave/postgresql.conf.template',INSTALL_FOLDER+'/slave/postgresql.conf')
  321. FileUtils.cp(INSTALL_FOLDER+'/slave/pg_hba.conf.template',INSTALL_FOLDER+'/slave/pg_hba.conf')
  322. FileUtils.cp(INSTALL_FOLDER+'/slave/recovery.conf.template',INSTALL_FOLDER+'/slave/recovery.conf')
  323. file_names = [INSTALL_FOLDER+'/slave/postgresql.conf', INSTALL_FOLDER+'/slave/pg_hba.conf', INSTALL_FOLDER+'/slave/recovery.conf']
  324. file_names.each do |file_name|
  325. replace = File.read(file_name)
  326. replace = replace.gsub(/HOST_MASTER_IP/, HOST_MASTER_IP)
  327. replace = replace.gsub(/HOST_PGPOOL_IP/, HOST_PGPOOL_IP)
  328. replace = replace.gsub(/HOST_MASTER/, HOST_MASTER)
  329. replace = replace.gsub(/PORT_PSQL_MASTER/, PORT_PSQL_MASTER)
  330. replace = replace.gsub(/PORT_PSQL_SLAVE2/, PORT_PSQL_SLAVE2)
  331. replace = replace.gsub(/PORT_PSQL_SLAVE/, PORT_PSQL_SLAVE)
  332. replace = replace.gsub(/PORT_SSH_SLAVE2/, PORT_SSH_SLAVE2)
  333. replace = replace.gsub(/PORT_SSH_SLAVE/, PORT_SSH_SLAVE)
  334. replace = replace.gsub(/PSQL_USER/, PSQL_USER)
  335. replace = replace.gsub(/PSQL_FOLDER/, PSQL_FOLDER)
  336. replace = replace.gsub(/HOT_STANDBY_SLAVE/, HOT_STANDBY_SLAVE)
  337. replace = replace.gsub(/SYNC_MASTER/, SYNC_MASTER)
  338. File.open(file_name, "w") { |file| file.puts replace }
  339. `scp -P #{PORT_SSH_SLAVE2} #{file_name} #{HOST_SLAVE2}:#{PSQL_FOLDER}/conf/#{File.basename(file_name)}`
  340. end
  341. puts "Configuration du serveur esclave…"
  342. system("ssh #{HOST_SLAVE2} -p #{PORT_SSH_SLAVE2} ruby #{INSTALL_FOLDER}/slave.rb")
  343. end
  344. end
  345. }
  346. if options[:slave]
  347. slaveConfig.join
  348. end
  349. if options[:slavebis]
  350. slavebisConfig.join
  351. end
  352. if options[:pgpool]
  353. pgpoolConfig = Thread.new {
  354. if options[:config]
  355. puts "Réécriture des fichiers de configuration pgPool…"
  356. FileUtils.cp(INSTALL_FOLDER+'/pgpool/pgpool.conf.template',INSTALL_FOLDER+'/pgpool/pgpool.conf')
  357. FileUtils.cp(INSTALL_FOLDER+'/pgpool/pg_hba.conf.template',INSTALL_FOLDER+'/pgpool/pg_hba.conf')
  358. FileUtils.cp(INSTALL_FOLDER+'/pgpool/pcp.conf.template',INSTALL_FOLDER+'/pgpool/pcp.conf')
  359. FileUtils.cp(INSTALL_FOLDER+'/pgpool/failover.rb.template',INSTALL_FOLDER+'/pgpool/failover.rb')
  360. file_names = [INSTALL_FOLDER+'/pgpool/pgpool.conf', INSTALL_FOLDER+'/pgpool/pg_hba.conf', INSTALL_FOLDER+'/pgpool/pcp.conf', INSTALL_FOLDER+'/pgpool/failover.rb']
  361. file_names.each do |file_name|
  362. replace = File.read(file_name)
  363. replace = replace.gsub(/HOST_MASTER_IP/, HOST_MASTER_IP)
  364. replace = replace.gsub(/PORT_PSQL_MASTER/, PORT_PSQL_MASTER)
  365. replace = replace.gsub(/PORT_PSQL_SLAVE2/, PORT_PSQL_SLAVE2)
  366. replace = replace.gsub(/PORT_PSQL_SLAVE/, PORT_PSQL_SLAVE)
  367. replace = replace.gsub(/HOST_SLAVE2_IP/, HOST_SLAVE2_IP)
  368. replace = replace.gsub(/HOST_SLAVE_IP/, HOST_SLAVE_IP)
  369. replace = replace.gsub(/PSQL_FOLDER/, PSQL_FOLDER)
  370. replace = replace.gsub(/PGPOOL_FOLDER/, PGPOOL_FOLDER)
  371. replace = replace.gsub(/PGPOOL_PORT/, PGPOOL_PORT)
  372. replace = replace.gsub(/PGPOOL_PCP_PORT/, PGPOOL_PCP_PORT)
  373. File.open(file_name, "w") { |file| file.puts replace }
  374. `scp -P #{PORT_SSH_PGPOOL} #{file_name} #{HOST_PGPOOL}:#{PGPOOL_FOLDER}/conf/#{File.basename(file_name)}`
  375. end
  376. puts "Configuration du serveur pgPool…"
  377. system("ssh #{HOST_PGPOOL} -p #{PORT_SSH_PGPOOL} ruby #{INSTALL_FOLDER}/pgpool.rb")
  378. end
  379. }
  380. end
  381. if options[:pgpool]
  382. pgpoolConfig.join
  383. end