Sha256: 3af4adbf775916dee5d66e590d9555469e434d76191bcfcbb73ea716a4d61740

Contents?: true

Size: 1.1 KB

Versions: 4

Compression:

Stored size: 1.1 KB

Contents

module Specjour
  class RsyncDaemon
    require 'fileutils'

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

    def config_file
      File.join("/tmp", "rsyncd.conf")
    end

    def start
      write_config
      system("rsync", "--daemon", "--config=#{config_file}", "--port=8989")
      at_exit { puts 'shutting down rsync'; stop }
    end

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

    protected

    def write_config
      File.open(config_file, 'w') do |f|
        f.write config
      end
    end

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

    def pid_file
      File.join("/tmp", "#{project_name}_rsync_daemon.pid")
    end

    def config
      <<-CONFIG
# global configuration
use chroot = no
timeout = 60
read only = yes
pid file = #{pid_file}

[#{project_name}]
  path = #{project_path}
  exclude = .git* doc tmp/* public log script
      CONFIG
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
specjour-0.1.4 lib/specjour/rsync_daemon.rb
specjour-0.1.3 lib/specjour/rsync_daemon.rb
specjour-0.1.2 lib/specjour/rsync_daemon.rb
specjour-0.1.1 lib/specjour/rsync_daemon.rb