我对ruby非常陌生,我正在尝试排查puppet给我的错误。到目前为止谷歌并没有帮助我更接近理解这个问题。其他information here这个ruby函数做了什么?
当傀儡启动Redis的初始化脚本,它返回以下错误:
Debug: Executing '/etc/init.d/redis_6390 start'
Error: Could not start Service[redis_6390]: Execution of '/etc/init.d/redis_6390 start' returned 1: Error: Could not execute posix command: Exec format error - /etc/init.d/redis_6390
Wrapped exception:
Execution of '/etc/init.d/redis_6390 start' returned 1: Error: Could not execute posix command: Exec format error - /etc/init.d/redis_6390
Error: /Stage[main]/Ac_redis_6390/Service[redis_6390]/ensure: change from stopped to running failed: Could not start Service[redis_6390]: Execution of '/etc/init.d/redis_6390 start' returned 1: Error: Could not execute posix command: Exec format error - /etc/init.d/redis_6390
Debug: Class[Ac_redis_6390]: The container Stage[main] will propagate my refresh event
我已经找到了确切的行“无法执行POSIX命令:”木偶的源代码内。
https://github.com/puppetlabs/puppet/blob/master/lib/puppet/util/execution.rb
# This is private method.
# @comment see call to private_class_method after method definition
# @api private
#
def self.execute_posix(command, options, stdin, stdout, stderr)
child_pid = Puppet::Util.safe_posix_fork(stdin, stdout, stderr) do
# We can't just call Array(command), and rely on it returning
# things like ['foo'], when passed ['foo'], because
# Array(command) will call command.to_a internally, which when
# given a string can end up doing Very Bad Things(TM), such as
# turning "/tmp/foo;\r\n /bin/echo" into ["/tmp/foo;\r\n", " /bin/echo"]
command = [command].flatten
Process.setsid
begin
Puppet::Util::SUIDManager.change_privileges(options[:uid], options[:gid], true)
# if the caller has requested that we override locale environment variables,
if (options[:override_locale]) then
# loop over them and clear them
Puppet::Util::POSIX::LOCALE_ENV_VARS.each { |name| ENV.delete(name) }
# set LANG and LC_ALL to 'C' so that the command will have consistent, predictable output
# it's OK to manipulate these directly rather than, e.g., via "withenv", because we are in
# a forked process.
ENV['LANG'] = 'C'
ENV['LC_ALL'] = 'C'
end
# unset all of the user-related environment variables so that different methods of starting puppet
# (automatic start during boot, via 'service', via /etc/init.d, etc.) won't have unexpected side
# effects relating to user/home dir environment vars.
# it's OK to manipulate these directly rather than, e.g., via "withenv", because we are in
# a forked process.
Puppet::Util::POSIX::USER_ENV_VARS.each { |name| ENV.delete(name) }
options[:custom_environment] ||= {}
Puppet::Util.withenv(options[:custom_environment]) do
Kernel.exec(*command)
end
rescue => detail
Puppet.log_exception(detail, "Could not execute posix command: #{detail}")
exit!(1)
end
end
child_pid
end
private_class_method :execute_posix
做这些行吗?我试图了解什么是抛出这个异常。
options[:custom_environment] ||= {}
Puppet::Util.withenv(options[:custom_environment]) do
Kernel.exec(*command)
end