Class: Gorgon::RsyncDaemon

Inherits:
Object
  • Object
show all
Defined in:
lib/gorgon/rsync_daemon.rb

Constant Summary collapse

RSYNC_DIR_NAME =

for now, creates a readonly rsync daemon for the current directory on the mountpath “src”

"#{Dir.tmpdir}/gorgon_rsync_daemon"
RSYNC_PORT =
43434
PID_FILE =
'rsync.pid'

Class Method Summary collapse

Class Method Details

.start(directory_bucket) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/gorgon/rsync_daemon.rb', line 10

def self.start(directory_bucket)
  if directory_bucket.nil? || !File.directory?(directory_bucket)
    $stderr.puts "Please, expecify a valid directory."
    return false
  end

  if !port_available?
    puts port_busy_msg
    return false
  end

  Dir.mkdir(RSYNC_DIR_NAME)
  success = false
  Dir.chdir(RSYNC_DIR_NAME) do
    File.write("rsyncd.conf", rsyncd_config_string(directory_bucket))

    success = Kernel.system("rsync --daemon --config rsyncd.conf")
  end

  success
end

.stopObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/gorgon/rsync_daemon.rb', line 32

def self.stop
  if !File.directory?(RSYNC_DIR_NAME)
    puts "ERROR: Directory '#{RSYNC_DIR_NAME}' doesn't exists. Maybe rsync daemon is not running!"
    return false
  end

  success = nil
  Dir.chdir(RSYNC_DIR_NAME) do
    pid = File.read(PID_FILE)
    success = Kernel.system("kill #{pid}")
  end

  if success
    FileUtils::remove_entry_secure(RSYNC_DIR_NAME)
    return true
  else
    return false
  end
end