Class: Vines::Agent::Shell
- Inherits:
-
Object
- Object
- Vines::Agent::Shell
- Includes:
- Log
- Defined in:
- lib/vines/agent/shell.rb
Overview
Provides a shell session to execute commands as a particular user. All commands are forked and executed in a child process to isolate them from the agent process. Keeping the same session open between commands allows stateful commands like ‘cd’ to work properly.
Instance Attribute Summary collapse
-
#permissions ⇒ Object
writeonly
Sets the attribute permissions.
Instance Method Summary collapse
-
#initialize(jid, permissions) ⇒ Shell
constructor
Create a new shell session to asynchronously execute commands for this JID.
-
#run(command, &callback) ⇒ Object
Queue the shell command to run as soon as the currently executing tasks complete.
Constructor Details
#initialize(jid, permissions) ⇒ Shell
Create a new shell session to asynchronously execute commands for this JID. The JID is validated in the permissions Hash before executing commands.
18 19 20 21 22 23 |
# File 'lib/vines/agent/shell.rb', line 18 def initialize(jid, ) @jid, = jid, @user = allowed_users.first if allowed_users.size == 1 @commands = EM::Queue.new process_command_queue end |
Instance Attribute Details
#permissions=(value) ⇒ Object (writeonly)
Sets the attribute permissions
13 14 15 |
# File 'lib/vines/agent/shell.rb', line 13 def (value) = value end |
Instance Method Details
#run(command, &callback) ⇒ Object
Queue the shell command to run as soon as the currently executing tasks complete. Yields the shell output to the callback block.
27 28 29 30 31 32 33 |
# File 'lib/vines/agent/shell.rb', line 27 def run(command, &callback) if reset?(command) callback.call(run_built_in(command)) else @commands.push({command: command.strip, callback: callback}) end end |