Class: FcrepoWrapper::Instance
- Inherits:
-
Object
- Object
- FcrepoWrapper::Instance
- Defined in:
- lib/fcrepo_wrapper/instance.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#pid ⇒ Object
readonly
Returns the value of attribute pid.
Instance Method Summary collapse
-
#clean! ⇒ Object
Clean up any files fcrepo_wrapper may have downloaded.
- #configure ⇒ Object
-
#extract ⇒ String
extract a copy of fcrepo to instance_dir Does noting if fcrepo already exists at instance_dir.
- #extract_and_configure ⇒ Object
-
#host ⇒ Object
Get the host this fcrepo instance is bound to.
-
#initialize(options = {}) ⇒ Instance
constructor
A new instance of Instance.
- #instance_dir ⇒ Object
- #md5 ⇒ Object
- #options ⇒ Object
- #port ⇒ Object
- #process_arguments ⇒ Object
-
#remove_instance_dir! ⇒ Object
Clean up any files in the fcrepo instance dir.
-
#restart ⇒ Object
Stop fcrepo and wait for it to finish exiting.
-
#start ⇒ Object
Start fcrepo and wait for it to become available.
-
#started? ⇒ Boolean
Is fcrepo running?.
-
#status ⇒ Object
Check the status of a managed fcrepo service.
-
#stop ⇒ Object
Stop fcrepo and wait for it to finish exiting.
-
#url ⇒ Object
Get a (likely) URL to the fcrepo instance.
- #version ⇒ Object
- #wrap(&_block) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Instance
Returns a new instance of Instance.
31 32 33 |
# File 'lib/fcrepo_wrapper/instance.rb', line 31 def initialize( = {}) @config = Settings.new(Configuration.new()) end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
14 15 16 |
# File 'lib/fcrepo_wrapper/instance.rb', line 14 def config @config end |
#pid ⇒ Object (readonly)
Returns the value of attribute pid.
14 15 16 |
# File 'lib/fcrepo_wrapper/instance.rb', line 14 def pid @pid end |
Instance Method Details
#clean! ⇒ Object
Clean up any files fcrepo_wrapper may have downloaded
154 155 156 157 158 159 160 161 |
# File 'lib/fcrepo_wrapper/instance.rb', line 154 def clean! stop remove_instance_dir! FileUtils.remove_entry(config.download_path) if File.exists?(config.download_path) FileUtils.remove_entry(config.tmp_save_dir, true) if File.exists? config.tmp_save_dir md5.clean! FileUtils.remove_entry(config.version_file) if File.exists? config.version_file end |
#configure ⇒ Object
169 170 171 |
# File 'lib/fcrepo_wrapper/instance.rb', line 169 def configure raise_error_unless_extracted end |
#extract ⇒ String
extract a copy of fcrepo to instance_dir Does noting if fcrepo already exists at instance_dir
182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/fcrepo_wrapper/instance.rb', line 182 def extract return config.instance_dir if extracted? jar_file = download FileUtils.mkdir_p config.instance_dir FileUtils.cp jar_file, config.binary_path self.extracted_version = config.version config.instance_dir end |
#extract_and_configure ⇒ Object
173 174 175 176 177 |
# File 'lib/fcrepo_wrapper/instance.rb', line 173 def extract_and_configure instance_dir = extract configure instance_dir end |
#host ⇒ Object
Get the host this fcrepo instance is bound to
126 127 128 |
# File 'lib/fcrepo_wrapper/instance.rb', line 126 def host '127.0.0.1' end |
#instance_dir ⇒ Object
144 145 146 |
# File 'lib/fcrepo_wrapper/instance.rb', line 144 def instance_dir config.instance_dir end |
#md5 ⇒ Object
35 36 37 |
# File 'lib/fcrepo_wrapper/instance.rb', line 35 def md5 @md5 ||= MD5.new(config) end |
#options ⇒ Object
148 149 150 |
# File 'lib/fcrepo_wrapper/instance.rb', line 148 def config. end |
#port ⇒ Object
130 131 132 |
# File 'lib/fcrepo_wrapper/instance.rb', line 130 def port config.port end |
#process_arguments ⇒ Object
47 48 49 50 51 |
# File 'lib/fcrepo_wrapper/instance.rb', line 47 def process_arguments ["java"] + config. + config..merge(port: port) .map { |k, v| ["--#{k}", "#{v}"].reject(&:empty?) }.flatten end |
#remove_instance_dir! ⇒ Object
Clean up any files in the fcrepo instance dir
165 166 167 |
# File 'lib/fcrepo_wrapper/instance.rb', line 165 def remove_instance_dir! FileUtils.remove_entry(config.instance_dir, true) if File.exists? config.instance_dir end |
#restart ⇒ Object
Stop fcrepo and wait for it to finish exiting
86 87 88 89 90 91 |
# File 'lib/fcrepo_wrapper/instance.rb', line 86 def restart if config.managed? && started? stop start end end |
#start ⇒ Object
Start fcrepo and wait for it to become available
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/fcrepo_wrapper/instance.rb', line 55 def start extract_and_configure if config.managed? @pid = spawn(config.env, *process_arguments) # Wait for fcrepo to start while !status sleep 1 end end end |
#started? ⇒ Boolean
Is fcrepo running?
120 121 122 |
# File 'lib/fcrepo_wrapper/instance.rb', line 120 def started? !!status end |
#status ⇒ Object
Check the status of a managed fcrepo service
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/fcrepo_wrapper/instance.rb', line 95 def status return true unless config.managed? return false if pid.nil? begin Process.getpgid(pid) rescue Errno::ESRCH return false end begin TCPSocket.new(host, port).close Net::HTTP.start(host, port) do |http| http.request(Net::HTTP::Get.new('/')) end true rescue Errno::ECONNREFUSED, Errno::EINVAL false end end |
#stop ⇒ Object
Stop fcrepo and wait for it to finish exiting
69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/fcrepo_wrapper/instance.rb', line 69 def stop if config.managed? && started? Process.kill 'HUP', pid # Wait for fcrepo to stop while status sleep 1 end Process.waitpid(pid) end @pid = nil end |
#url ⇒ Object
Get a (likely) URL to the fcrepo instance
136 137 138 |
# File 'lib/fcrepo_wrapper/instance.rb', line 136 def url "http://#{host}:#{port}/" end |
#version ⇒ Object
140 141 142 |
# File 'lib/fcrepo_wrapper/instance.rb', line 140 def version config.version end |
#wrap(&_block) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/fcrepo_wrapper/instance.rb', line 39 def wrap(&_block) extract_and_configure start yield self ensure stop end |