Class: 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'

Instance Method Summary collapse

Constructor Details

#initializeRsyncDaemon

Returns a new instance of RsyncDaemon.



9
10
11
12
# File 'lib/gorgon/rsync_daemon.rb', line 9

def initialize
  @project_directory = Dir.pwd
  @started = false
end

Instance Method Details

#startObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/gorgon/rsync_daemon.rb', line 14

def start
  return if @started

  if !port_available?
    puts port_busy_msg
    return false
  end
  
  Dir.mkdir(RSYNC_DIR_NAME)
  success = nil
  Dir.chdir(RSYNC_DIR_NAME) do
    File.write("rsyncd.conf", rsyncd_config_string(@project_directory))

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

  if success
    @started = true
    return true
  else
    return false
  end
end

#stopObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/gorgon/rsync_daemon.rb', line 38

def stop
  return unless @started

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

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