Class: Mccloud::Provisioner::Shell
- Inherits:
-
Object
- Object
- Mccloud::Provisioner::Shell
- Defined in:
- lib/mccloud/provisioner/shell.rb
Instance Attribute Summary collapse
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#inline ⇒ Object
Returns the value of attribute inline.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#path ⇒ Object
Returns the value of attribute path.
-
#sudo ⇒ Object
Returns the value of attribute sudo.
Instance Method Summary collapse
-
#initialize(env) ⇒ Shell
constructor
A new instance of Shell.
- #run(server) ⇒ Object
Constructor Details
#initialize(env) ⇒ Shell
Returns a new instance of Shell.
16 17 18 19 20 21 22 |
# File 'lib/mccloud/provisioner/shell.rb', line 16 def initialize(env) @env=env @sudo=false @name ="shell" @inline="who am i" @log_level="info" end |
Instance Attribute Details
#env ⇒ Object (readonly)
Returns the value of attribute env.
10 11 12 |
# File 'lib/mccloud/provisioner/shell.rb', line 10 def env @env end |
#inline ⇒ Object
Returns the value of attribute inline.
13 14 15 |
# File 'lib/mccloud/provisioner/shell.rb', line 13 def inline @inline end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/mccloud/provisioner/shell.rb', line 9 def name @name end |
#path ⇒ Object
Returns the value of attribute path.
12 13 14 |
# File 'lib/mccloud/provisioner/shell.rb', line 12 def path @path end |
#sudo ⇒ Object
Returns the value of attribute sudo.
14 15 16 |
# File 'lib/mccloud/provisioner/shell.rb', line 14 def sudo @sudo end |
Instance Method Details
#run(server) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/mccloud/provisioner/shell.rb', line 24 def run(server) server.transfer(StringIO.new(@inline),"/tmp/shell-provisioner.sh") unless @inline.nil? server.transfer(path,"/tmp/shell-provisioner.sh") unless @path.nil? server.execute("chmod +x /tmp/shell-provisioner.sh",{:mute => true}) env.ui.info "[#{server.name}] - [#{@name}] - running shell" env.ui.info "[#{server.name}] - [#{@name}] - login as #{server.user}" begin if !@sudo || server.user=="root" server.execute("/tmp/shell-provisioner.sh") else server.execute("sudo /tmp/shell-provisioner.sh") end rescue Exception ensure env.ui.info "[#{server.name}] - [#{@name}] - Cleaning up script" server.execute("rm /tmp/shell-provisioner.sh",{:mute => true}) end end |