File tree 2 files changed +15
-13
lines changed
2 files changed +15
-13
lines changed Original file line number Diff line number Diff line change @@ -30,20 +30,28 @@ class Chef
30
30
module Postgresql
31
31
# Helpers module
32
32
module Helpers
33
+ def pg_installed? ( pkg_name )
34
+ dpkg_status = Mixlib ::ShellOut . new ( "dpkg-query -W -f='${Status}\n ' #{ pkg_name } 2>/dev/null | grep -c -q 'ok installed'" )
35
+ dpkg_status . run_command
36
+ if dpkg_status . exitstatus == 0
37
+ false
38
+ else
39
+ true
40
+ end
41
+ end
42
+
33
43
def exec_in_pg_cluster ( cluster_version , cluster_name , sql )
34
44
return false unless pg_running? ( cluster_version , cluster_name )
35
45
postmaster_content = ::File . open ( "/var/lib/postgresql/#{ cluster_version } /#{ cluster_name } /postmaster.pid" ) . readlines
36
46
pg_port = postmaster_content [ 3 ] . to_i
37
47
psql_status = Mixlib ::ShellOut . new ( "echo -n \" #{ sql } ;\" | su -c 'psql -t -p #{ pg_port } ' postgres" )
38
48
psql_status . run_command
39
- Chef ::Log . info ( psql_status . stdout )
40
- Chef ::Log . info ( psql_status . stderr )
41
49
[ psql_status . stdout , psql_status . stderr ]
42
50
end
43
51
44
- def need_to_restart? ( cluster_version , cluster_name , advanced_options , node )
52
+ def need_to_restart? ( advanced_options , first_time )
45
53
if advanced_options [ :restart ] == :first
46
- return ( ! defined? node [ 'postgresql' ] [ cluster_version ] [ cluster_name ] [ 'success_at_least_once' ] )
54
+ return first_time
47
55
elsif advanced_options [ :restart ] == :always
48
56
return true
49
57
end
Original file line number Diff line number Diff line change 57
57
ENV [ 'LANG' ] = new_resource . cluster_create_options [ 'locale' ]
58
58
end
59
59
60
+ first_time = pg_installed? ( "postgresql-#{ configuration [ 'version' ] } " )
61
+
60
62
# Install packages
61
63
%W( postgresql-#{ configuration [ 'version' ] } postgresql-server-dev-all ) . each do |pkg |
62
64
package pkg
82
84
status_command "su -c '/usr/lib/postgresql/#{ cluster_version } /bin/pg_ctl \
83
85
-D /var/lib/postgresql/#{ cluster_version } /#{ cluster_name } status' postgres"
84
86
supports status : true , restart : true , reload : true
85
- notifies :create , 'ruby_block[set_success_mark]' , :delayed
86
- end
87
-
88
- ruby_block 'set_success_mark' do
89
- action :nothing
90
- block do
91
- node . normal [ 'postgresql' ] [ cluster_version ] [ cluster_name ] [ 'success_at_least_once' ] = true
92
- end
93
87
end
94
88
95
89
ruby_block 'restart_service' do
96
90
action :nothing
97
91
block do
98
- if need_to_restart? ( cluster_version , cluster_name , advanced_options , node )
92
+ if need_to_restart? ( advanced_options , first_time )
99
93
run_context . notifies_delayed ( Chef ::Resource ::Notification . new ( postgresql_service , :restart , self ) )
100
94
else
101
95
run_context . notifies_delayed ( Chef ::Resource ::Notification . new ( postgresql_service , :reload , self ) )
You can’t perform that action at this time.
0 commit comments