Class: Circus::Act
- Inherits:
-
Object
- Object
- Circus::Act
- Defined in:
- lib/circus/act.rb
Instance Attribute Summary collapse
-
#dir ⇒ Object
readonly
Returns the value of attribute dir.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#props ⇒ Object
readonly
Returns the value of attribute props.
Instance Method Summary collapse
- #act_file ⇒ Object
- #assemble(logger, output_root_dir, overlay_root) ⇒ Object
- #detect! ⇒ Object
-
#initialize(name, dir, props = {}) ⇒ Act
constructor
A new instance of Act.
- #package_for_dev(logger, run_root_dir) ⇒ Object
- #pause(logger, run_root) ⇒ Object
- #profile ⇒ Object
- #resume(logger, run_root) ⇒ Object
- #should_package? ⇒ Boolean
- #upload(output_root_dir, act_store) ⇒ Object
Constructor Details
#initialize(name, dir, props = {}) ⇒ Act
Returns a new instance of Act.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/circus/act.rb', line 8 def initialize(name, dir, props = {}) @name = name @dir = dir @props = props # Merge act specific properties if File.exists? act_file act_cfg = YAML.load(File.read(act_file)) @props.merge! act_cfg # Allow act name to be overriden @name = @props['name'] if @props['name'] end end |
Instance Attribute Details
#dir ⇒ Object (readonly)
Returns the value of attribute dir.
6 7 8 |
# File 'lib/circus/act.rb', line 6 def dir @dir end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/circus/act.rb', line 6 def name @name end |
#props ⇒ Object (readonly)
Returns the value of attribute props.
6 7 8 |
# File 'lib/circus/act.rb', line 6 def props @props end |
Instance Method Details
#act_file ⇒ Object
79 80 81 |
# File 'lib/circus/act.rb', line 79 def act_file File.join(@dir, 'act.yaml') end |
#assemble(logger, output_root_dir, overlay_root) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/circus/act.rb', line 51 def assemble(logger, output_root_dir, ) detect! unless @profile = File.join(, name) FileUtils.mkdir_p() return false unless profile.package_for_deploy(logger, ) begin # Package up the output file include_dirs = ["-C #{} ."] include_dirs << "-C #{@dir} ." if profile.package_base_dir? include_dirs.concat(profile.extra_dirs.map { |d| "-C #{File.dirname(d)} #{File.basename(d)}"}) output_name = File.join(output_root_dir, "#{name}.act") ExternalUtil.run_external(logger, 'Output packaging', "tar -czf #{output_name} --exclude .circus #{include_dirs.join(' ')} 2>&1") ensure profile.cleanup_after_deploy(logger, ) end end |
#detect! ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/circus/act.rb', line 34 def detect! # Run each profile against the directory to try to find one that matches profile_clazz = Circus::Profiles::PROFILES.find { |p| p.accepts?(@name, @dir, @props) } raise "No profile can run #{@dir}" unless profile_clazz @profile = profile_clazz.new(@name, @dir, @props) end |
#package_for_dev(logger, run_root_dir) ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/circus/act.rb', line 42 def package_for_dev(logger, run_root_dir) detect! unless @profile # Create our run directory, and tell the profile to package into it run_dir = File.join(run_root_dir, @name) FileUtils.mkdir_p run_dir profile.package_for_dev(logger, run_dir) end |
#pause(logger, run_root) ⇒ Object
83 84 85 86 87 88 |
# File 'lib/circus/act.rb', line 83 def pause(logger, run_root) working_dir = File.join(run_root, name) process_mgmt = Circus::Processes::Daemontools.new process_mgmt.pause_service(name, working_dir, logger) end |
#profile ⇒ Object
23 24 25 26 27 |
# File 'lib/circus/act.rb', line 23 def profile detect! unless @profile @profile end |
#resume(logger, run_root) ⇒ Object
90 91 92 93 94 95 |
# File 'lib/circus/act.rb', line 90 def resume(logger, run_root) working_dir = File.join(run_root, name) process_mgmt = Circus::Processes::Daemontools.new process_mgmt.resume_service(name, working_dir, logger) end |
#should_package? ⇒ Boolean
29 30 31 32 |
# File 'lib/circus/act.rb', line 29 def should_package? return false if @props['no-package'] true end |
#upload(output_root_dir, act_store) ⇒ Object
72 73 74 75 76 77 |
# File 'lib/circus/act.rb', line 72 def upload(output_root_dir, act_store) detect! unless @profile output_name = File.join(output_root_dir, "#{name}.act") act_store.upload_act(output_name) end |