Module: LSync
- Defined in:
- lib/lsync/error.rb,
lib/lsync.rb,
lib/lsync/shell.rb,
lib/lsync/method.rb,
lib/lsync/script.rb,
lib/lsync/server.rb,
lib/lsync/version.rb,
lib/lsync/directory.rb,
lib/lsync/controller.rb,
lib/lsync/shells/ssh.rb,
lib/lsync/tee_logger.rb,
lib/lsync/event_timer.rb,
lib/lsync/event_handler.rb,
lib/lsync/methods/rsync.rb
Overview
Copyright © 2007, 2011 Samuel G. D. Williams. <www.oriontransfer.co.nz>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Defined Under Namespace
Modules: EventHandler, Methods, Shells, TeeHelper Classes: AbsolutePathError, BackupMethodError, BasicController, CommandFailure, ConnectionError, CopyController, Directory, DirectoryController, Error, EventTimer, LockError, Method, MinimalLogFormat, Script, ScriptError, Server, ServerController, Shell, TeeLogger, Timeout
Constant Summary collapse
- CLIENT_CODE =
(Pathname.new(__FILE__).dirname + "client.rb").read
- VERSION =
"2.4.0"
Class Method Summary collapse
- .log_error(error, logger) ⇒ Object
- .log_task(task, logger) ⇒ Object
-
.run_script(options = {}, &block) ⇒ Object
Run a prepared backup script using a lockfile.
Class Method Details
.log_error(error, logger) ⇒ Object
46 47 48 49 50 51 |
# File 'lib/lsync/controller.rb', line 46 def self.log_error(error, logger) logger.error "Error #{error.class.name}: #{error}" error.backtrace.each do |where| logger.error "\t#{where}" end end |
.log_task(task, logger) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/lsync/controller.rb', line 25 def self.log_task(task, logger) pipes = [task.output, task.error] while pipes.size > 0 result = IO.select(pipes) result[0].each do |pipe| if pipe.closed? || pipe.eof? pipes.delete(pipe) next end if pipe == task.output logger.info pipe.readline.chomp elsif pipe == task.error logger.error pipe.readline.chomp end end end end |
.run_script(options = {}, &block) ⇒ Object
Run a prepared backup script using a lockfile.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/lsync.rb', line 41 def self.run_script( = {}, &block) script = LSync::Script.new(, &block) lockfile_path = $0 + ".lock" script.on(:failure) do |error| LSync::log_error(error, logger) end begin Lockfile.new(lockfile_path, :retries => 0) do script.run! end rescue Lockfile::MaxTriesLockError raise LockError.new("Lockfile #{lockfile_path} could not be acquired.") end end |