Module: CliTool::Remote::ClassMethods

Defined in:
lib/cli_tool/remote.rb

Instance Method Summary collapse

Instance Method Details

#custom!(*a, &b) ⇒ Object



314
315
316
317
# File 'lib/cli_tool/remote.rb', line 314

def custom!(*a, &b)
  Proc.new { |obj| obj.instance_exec(*a, &b) }
  false
end

#restart!Object



302
303
304
# File 'lib/cli_tool/remote.rb', line 302

def restart!
  queue(Script.new.exec('shutdown -r now', :sudo))
end

#run!(command, *a, &b) ⇒ Object



310
311
312
# File 'lib/cli_tool/remote.rb', line 310

def run!(command, *a, &b)
  run(command, *a, &b)
end

#run_suite!(*a, &b) ⇒ Object



306
307
308
# File 'lib/cli_tool/remote.rb', line 306

def run_suite!(*a, &b)
  run(:run_suite!, *a, &b)
end

#script(options = {}, &block) ⇒ Object



265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
# File 'lib/cli_tool/remote.rb', line 265

def script(options = {}, &block)
  script = Proc.new do
    run = true

    # Allow restricting the runs based on the tags provided
    if self.tags
      script_tags = (options[:tags] || []).concat([options[:tag]]).compact.flatten
      run = false if (self.tags & script_tags).empty?
    end

    # Run only when the tag is provided if tag_only option is provided
    run = false if run && options[:tag_only] == true && self.tags.empty?

    if run # Do we want to run this script?
      build_script = Script.new
      build_script.__send__(:instance_exec, self, &block)
      if options[:reboot] == true
        build_script.exec('shutdown -r now', :sudo)
        puts "\nServer will reboot upon completion of this block!\n", [:blue, :italic]
      elsif options[:shutdown] == true
        build_script.exec('shutdown -h now', :sudo)
        puts "\nServer will shutdown upon completion of this block!\n", [:blue, :italic]
      end

      build_script
    else
      false # Don't run anything
    end
  end

  queue(script)
end

#script_plugin(object) ⇒ Object



261
262
263
# File 'lib/cli_tool/remote.rb', line 261

def script_plugin(object)
  Script.__send__(:include, object)
end

#shutdown!Object



298
299
300
# File 'lib/cli_tool/remote.rb', line 298

def shutdown!
  queue(Script.new.exec('shutdown -h now', :sudo))
end