Class: Specjour::RsyncDaemon

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

Constant Summary collapse

CONFIG_VERSION =

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

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SocketHelpers

#hostname, #ip_from_hostname

Constructor Details

#initialize(project_path, project_name) ⇒ RsyncDaemon

Returns a new instance of RsyncDaemon.



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

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

Instance Attribute Details

#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



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

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

#config_fileObject



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

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

#pidObject



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

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

#pid_fileObject



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

def pid_file
  File.join(config_directory, PID_FILE_NAME)
end

#startObject



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

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

#stopObject



45
46
47
48
49
50
# File 'lib/specjour/rsync_daemon.rb', line 45

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