@@ -143,19 +143,30 @@ module PuppetMetricsCollector
143
143
#
144
144
# @return [Exec::Result] The result of the SQL statement.
145
145
def exec_psql ( query , database : nil , timeout : @timeout )
146
+ runuser_path = if File . executable? ( '/usr/sbin/runuser' )
147
+ '/usr/sbin/runuser'
148
+ elsif File . executable? ( '/sbin/runuser' )
149
+ '/sbin/runuser'
150
+ else
151
+ nil
152
+ end
146
153
psql_command = [ @psql , '--file=-' ,
147
154
'--no-align' , '--no-psqlrc' ,
148
155
'--pset=pager=off' , '--set=ON_ERROR_STOP=on' ,
149
156
'--single-transaction' , '--tuples-only' , '--quiet' ]
150
157
psql_command += [ "--dbname=#{ database } " ] unless database . nil?
151
158
152
- command_line = [ '/usr/sbin/runuser' , '-u' , 'pe-postgres' ,
159
+ command_line = [ runuser_path , '-u' , 'pe-postgres' ,
153
160
'--' , *psql_command ]
154
161
155
162
env = { 'PGOPTIONS' => "-c statement_timeout=#{ timeout } s" ,
156
163
'PGTZ' => 'GMT' }
157
164
158
- Exec . exec_cmd ( *command_line , stdin_data : query , env : env , timeout : timeout + 1 )
165
+ if runuser_path
166
+ Exec . exec_cmd ( *command_line , stdin_data : query , env : env , timeout : timeout + 1 )
167
+ else
168
+ $stderr. puts ( 'WARN: no runuser executable found' )
169
+ end
159
170
end
160
171
161
172
# Add an error message to a result hash
0 commit comments