Class: RightScale::PowershellHost
- Defined in:
- lib/chef/windows/powershell_host.rb
Overview
This class is responsible for managing a Powershell process instance It allows running Powershell scripts in the associated instance and will log the script output.
Instance Method Summary collapse
- #format_log_message(message) ⇒ Object
-
#initialize(options = {}) ⇒ PowershellHost
constructor
Start the Powershell process synchronously Set the instance variable :active to true once Powershell was successfully started.
-
#run(script_path) ⇒ Object
Run Powershell script in associated Powershell process Log stdout and stderr to Chef logger.
-
#terminate ⇒ Object
Terminate associated Powershell process :run cannot be called after :terminate This method is idempotent.
Constructor Details
#initialize(options = {}) ⇒ PowershellHost
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/chef/windows/powershell_host.rb', line 36 def initialize( = {}) Log.debug(("Initializing")) @node = [:node] @provider_name = [:provider_name] @pipe_name = "#{@provider_name}_#{Time.now.strftime("%Y-%m-%d-%H%M%S")}" @response_mutex = Mutex.new @response_event = ConditionVariable.new Log.debug(("Starting pipe server")) @pipe_server = RightScale::Windows::PowershellPipeServer.new(:pipe_name => @pipe_name) do |kind, payload| case kind when :is_ready then query when :respond then respond(payload) end end unless @pipe_server.start @pipe_server = nil return end Log.debug(("Starting chef node server")) RightScale::Windows::ChefNodeServer.instance.start(:node => @node) Log.debug(("Starting host")) start_powershell_process Log.debug(("Initialized")) end |
Instance Method Details
#format_log_message(message) ⇒ Object
69 70 71 |
# File 'lib/chef/windows/powershell_host.rb', line 69 def () "[PowershellHost #{@pipe_name}] - #{message}" end |
#run(script_path) ⇒ Object
Run Powershell script in associated Powershell process Log stdout and stderr to Chef logger
Argument
- script_path(String)
-
Full path to Powershell script to be run
Return
- res(Number)
-
The exit code of the script that was run. nil if no exit status was available.
Raise
- RightScale::Exceptions:ApplicationError
-
If Powershell process is not running (i.e. :active is false)
84 85 86 87 88 89 |
# File 'lib/chef/windows/powershell_host.rb', line 84 def run(script_path) Log.debug(("Running #{script_path}")) res = run_command("&\"#{script_path}\"") Log.debug(("Finished #{script_path}")) res end |
#terminate ⇒ Object
Terminate associated Powershell process :run cannot be called after :terminate This method is idempotent
Return
- true
-
Always return true
97 98 99 100 101 102 103 |
# File 'lib/chef/windows/powershell_host.rb', line 97 def terminate Log.debug(("Terminate requested")) res = run_command("break") Log.debug(("Terminate signal sent")) true end |