Class: Specjour::RsyncDaemon

Inherits:
Object
  • Object
show all
Includes:
SocketHelper
Defined in:
lib/specjour/rsync_daemon.rb

Constant Summary

CONFIG_VERSION =

Corresponds to the version of specjour that changed the configuration file.

"0.5.0".freeze
CONFIG_FILE_NAME =
"rsyncd.conf"
PID_FILE_NAME =
"rsyncd.pid"

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Methods included from SocketHelper

#current_uri, #hostname, #ip_from_hostname, #new_uri

Constructor Details

- (RsyncDaemon) initialize(project_path, project_name, port)

Returns a new instance of RsyncDaemon



14
15
16
17
18
# File 'lib/specjour/rsync_daemon.rb', line 14

def initialize(project_path, project_name, port)
  @project_path = project_path
  @project_name = project_name
  @port = port
end

Instance Attribute Details

- (Object) port (readonly)

Returns the value of attribute port



12
13
14
# File 'lib/specjour/rsync_daemon.rb', line 12

def port
  @port
end

- (Object) project_name (readonly)

Returns the value of attribute project_name



12
13
14
# File 'lib/specjour/rsync_daemon.rb', line 12

def project_name
  @project_name
end

- (Object) project_path (readonly)

Returns the value of attribute project_path



12
13
14
# File 'lib/specjour/rsync_daemon.rb', line 12

def project_path
  @project_path
end

Instance Method Details

- (Object) config_directory



20
21
22
# File 'lib/specjour/rsync_daemon.rb', line 20

def config_directory
  @config_directory ||= File.join(project_path, ".specjour")
end

- (Object) config_file



24
25
26
# File 'lib/specjour/rsync_daemon.rb', line 24

def config_file
  @config_file ||= File.join(config_directory, CONFIG_FILE_NAME)
end

- (Object) pid



28
29
30
31
32
# File 'lib/specjour/rsync_daemon.rb', line 28

def pid
  if File.exists?(pid_file)
    File.read(pid_file).strip.to_i
  end
end

- (Object) pid_file



34
35
36
# File 'lib/specjour/rsync_daemon.rb', line 34

def pid_file
  File.join(config_directory, PID_FILE_NAME)
end

- (Object) start



38
39
40
41
42
43
44
45
# File 'lib/specjour/rsync_daemon.rb', line 38

def start
  Kernel.at_exit { stop }
  write_config
  Dir.chdir(project_path) do
    Kernel.system *command
    sleep 0.1
  end
end

- (Object) stop



47
48
49
50
51
52
# File 'lib/specjour/rsync_daemon.rb', line 47

def stop
  if pid
    Process.kill("TERM", pid)
    FileUtils.rm(pid_file)
  end
end