Class: Specjour::RsyncDaemon

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

Constant Summary collapse

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, #local_ip, #new_uri

Constructor Details

#initialize(project_path, project_name, port) ⇒ RsyncDaemon

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

#portObject (readonly)

Returns the value of attribute port.



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

def port
  @port
end

#project_nameObject (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

#project_pathObject (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

#config_directoryObject



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

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

#config_fileObject



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

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

#pidObject



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

#pid_fileObject



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

def pid_file
  File.join(config_directory, PID_FILE_NAME)
end

#startObject



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

#stopObject



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

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