Module: Bixby::Agent::ShellExec
- Included in:
- Bixby::Agent
- Defined in:
- lib/bixby-agent/agent/shell_exec.rb
Instance Method Summary collapse
-
#shell_exec(params) ⇒ CommandResponse
Shell exec a local command with the given params.
Instance Method Details
#shell_exec(params) ⇒ CommandResponse
Shell exec a local command with the given params
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/bixby-agent/agent/shell_exec.rb', line 26 def shell_exec(params) digest = params.delete("digest") || params.delete(:digest) spec = CommandSpec.new(params) log.debug { "shell_exec:\n" + spec.to_s + "\n" } spec.validate(digest) cmd = "#{spec.command_file} #{spec.args}" # Cleanup the ENV and execute old_env = {} %W{BUNDLE_BIN_PATH BUNDLE_GEMFILE}.each{ |r| old_env[r] = ENV.delete(r) if ENV.include?(r) } logger.debug("exec: #{cmd}") uid = lookup_id(:uid, spec.user) gid = lookup_id(:gid, spec.group) shell = Mixlib::ShellOut.new(cmd, :input => spec.stdin, :env => reset_env(spec.env, uid), :user => uid, :group => gid) shell.run_command old_env.each{ |k,v| ENV[k] = v } # reset the ENV return CommandResponse.new({ :status => shell.exitstatus, :stdout => shell.stdout, :stderr => shell.stderr }) end |