filbunke 0.3.2 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/bin/filbunked +27 -0
- data/doc/examples/filbunke_config.yml +21 -0
- data/doc/examples/http_evict_cache.rb +22 -0
- data/filbunke.gemspec +8 -2
- data/lib/filbunke/callbacks.rb +13 -0
- data/lib/filbunke/client.rb +19 -6
- data/lib/filbunke/daemon.rb +76 -0
- data/lib/filbunke/logger.rb +14 -0
- data/lib/filbunke/repository.rb +5 -2
- data/lib/filbunke.rb +4 -1
- metadata +10 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
1.0.0
|
data/bin/filbunked
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'filbunke'
|
5
|
+
require 'yaml'
|
6
|
+
require 'getoptlong'
|
7
|
+
|
8
|
+
raw_opts = GetoptLong.new(
|
9
|
+
[ '--help', '-h', GetoptLong::NO_ARGUMENT ],
|
10
|
+
[ '--config', '-c', GetoptLong::REQUIRED_ARGUMENT ]
|
11
|
+
)
|
12
|
+
|
13
|
+
opts = {}
|
14
|
+
raw_opts.each do |opt, arg|
|
15
|
+
opts[opt] = arg
|
16
|
+
end
|
17
|
+
|
18
|
+
if opts['--help'] || opts['--config'].blank?
|
19
|
+
puts "Usage: filbunked -c <config_file.yml>"
|
20
|
+
exit 1
|
21
|
+
else
|
22
|
+
config_file = File.read(opts['--config'])
|
23
|
+
config = YAML.load(config_file)
|
24
|
+
daemon = Filbunke::Daemon.new(config)
|
25
|
+
Process::UID.grant_privilege(Etc.getpwnam(config["user"]).uid)
|
26
|
+
daemon.run!
|
27
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
---
|
2
|
+
pid_file: '/var/run/filbunked.pid'
|
3
|
+
user: 'bjorns'
|
4
|
+
log_file: '/tmp/filbunke.log'
|
5
|
+
checkpoint_path: '/var/tmp/filbunke_checkpoints/'
|
6
|
+
run_every: 5
|
7
|
+
callback_path: '/Users/bjorns/Documents/Development/filbunke-cdn/client/doc/examples/'
|
8
|
+
repositories:
|
9
|
+
cache:
|
10
|
+
local_path: '/v5/cachetest'
|
11
|
+
filbunke_server_host: 'localhost'
|
12
|
+
filbunke_server_port: 8080
|
13
|
+
filbunke_server_repository: 'cache'
|
14
|
+
file_url_username: 'content'
|
15
|
+
file_url_password: 'JeSuisContent#1'
|
16
|
+
file_umask: 0644
|
17
|
+
directory_umask: 0755
|
18
|
+
callbacks:
|
19
|
+
http_evict_cache:
|
20
|
+
host: 'localhost'
|
21
|
+
port: 3010
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
|
3
|
+
class HttpEvictCache < Filbunke::Callbacks
|
4
|
+
|
5
|
+
def on_update(file)
|
6
|
+
begin
|
7
|
+
evict_http = Net::HTTP.new(@config["host"], @config["port"].to_i)
|
8
|
+
evict_http.start do |http|
|
9
|
+
evict_path = "/cache/evict/#{file.path.chomp('.yml')}"
|
10
|
+
request = Net::HTTP::Get.new(evict_path)
|
11
|
+
response = http.request(request)
|
12
|
+
if response.code.to_i != 200
|
13
|
+
@logger.log "Failed to evict cache entry: #{file.path}"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
rescue StandardError => e
|
17
|
+
@logger.log("Failed to evict cache entry: #{file.path}")
|
18
|
+
@logger.log(e.backtrace.join("\n"))
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
data/filbunke.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{filbunke}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "1.0.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Wouter de Bie"]
|
12
|
-
s.date = %q{2010-11-
|
12
|
+
s.date = %q{2010-11-10}
|
13
13
|
s.description = %q{Filbunke client and library}
|
14
14
|
s.email = %q{wouter@deltaprojects.se}
|
15
15
|
s.files = [
|
@@ -18,10 +18,16 @@ Gem::Specification.new do |s|
|
|
18
18
|
"Rakefile",
|
19
19
|
"VERSION",
|
20
20
|
"bin/.gitignore",
|
21
|
+
"bin/filbunked",
|
22
|
+
"doc/examples/filbunke_config.yml",
|
23
|
+
"doc/examples/http_evict_cache.rb",
|
21
24
|
"filbunke.gemspec",
|
22
25
|
"lib/filbunke.rb",
|
26
|
+
"lib/filbunke/callbacks.rb",
|
23
27
|
"lib/filbunke/client.rb",
|
28
|
+
"lib/filbunke/daemon.rb",
|
24
29
|
"lib/filbunke/file.rb",
|
30
|
+
"lib/filbunke/logger.rb",
|
25
31
|
"lib/filbunke/repository.rb",
|
26
32
|
"test/helper.rb",
|
27
33
|
"test/test_filbunke.rb"
|
data/lib/filbunke/client.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'active_support'
|
2
|
+
require 'active_support/all' rescue nil
|
2
3
|
require 'json'
|
3
4
|
require 'net/http'
|
4
5
|
require 'fileutils'
|
@@ -6,24 +7,31 @@ require 'fileutils'
|
|
6
7
|
module Filbunke
|
7
8
|
class Client
|
8
9
|
|
10
|
+
attr_reader :repository
|
11
|
+
|
9
12
|
UPDATES_ACTION = 'updates'
|
10
13
|
FILES_ACTION = 'files'
|
11
14
|
URL_KEY = 'url'
|
12
15
|
FROM_CHECKPOINT_KEY = 'from_checkpoint'
|
13
16
|
HASH_KEY = 'hash'
|
14
17
|
|
15
|
-
def initialize(repository)
|
18
|
+
def initialize(repository, logger, callbacks = [])
|
16
19
|
@repository = repository
|
20
|
+
@logger = logger
|
21
|
+
@callbacks = callbacks
|
17
22
|
end
|
18
23
|
|
19
|
-
def with_updated_files(last_checkpoint
|
24
|
+
def with_updated_files(last_checkpoint)
|
20
25
|
updates = get_updated_file_list(last_checkpoint)
|
21
26
|
updated_files = updates["files"] || []
|
22
27
|
updated_files.each do |raw_file|
|
23
28
|
file = File.new(raw_file)
|
24
29
|
if file.url.start_with?("http://")
|
25
|
-
local_file_path = File.join(local_path, file.path)
|
30
|
+
local_file_path = ::File.join(repository.local_path, file.path)
|
26
31
|
update_http_file!(file, local_file_path)
|
32
|
+
@callbacks.each do |callback|
|
33
|
+
callback.on_update(file)
|
34
|
+
end
|
27
35
|
yield file
|
28
36
|
else
|
29
37
|
raise "Unsupported protocol for file: #{file.inspect}"
|
@@ -32,6 +40,10 @@ module Filbunke
|
|
32
40
|
updates["checkpoint"] || last_checkpoint
|
33
41
|
end
|
34
42
|
|
43
|
+
def update_files!(last_checkpoint)
|
44
|
+
with_updated_files(last_checkpoint) {}
|
45
|
+
end
|
46
|
+
|
35
47
|
def register_updated_file!(path, url, hash = nil)
|
36
48
|
register_http = Net::HTTP.new(@repository.host, @repository.port)
|
37
49
|
register_http.start do |http|
|
@@ -91,15 +103,16 @@ module Filbunke
|
|
91
103
|
end
|
92
104
|
|
93
105
|
def write_file!(file_path, contents)
|
94
|
-
|
95
|
-
File.
|
106
|
+
@logger.log("Writing: #{file_path}")
|
107
|
+
::FileUtils.mkdir_p(::File.dirname(file_path))
|
108
|
+
::File.open(file_path, 'w') do |file|
|
96
109
|
file.write(contents);
|
97
110
|
file.close
|
98
111
|
end
|
99
112
|
end
|
100
113
|
|
101
114
|
def delete_file!(file_path)
|
102
|
-
File.delete(file_path)
|
115
|
+
::File.delete(file_path)
|
103
116
|
end
|
104
117
|
|
105
118
|
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
module Filbunke
|
2
|
+
class Daemon
|
3
|
+
|
4
|
+
def initialize(config)
|
5
|
+
@config = config
|
6
|
+
@clients = []
|
7
|
+
setup_clients!
|
8
|
+
write_pid!(config["pid_file"])
|
9
|
+
end
|
10
|
+
|
11
|
+
def setup_clients!
|
12
|
+
@logger = Logger.new(@config["log_file"])
|
13
|
+
@logger.log("Initializing filbunked")
|
14
|
+
@config["repositories"].each do |repository_name, repository_config|
|
15
|
+
@logger.log("Initializing repository: #{repository_name}")
|
16
|
+
@clients << begin
|
17
|
+
repository = Repository.new(repository_config["filbunke_server_repository"],
|
18
|
+
repository_config["filbunke_server_host"],
|
19
|
+
repository_config["filbunke_server_port"],
|
20
|
+
repository_config["local_path"],
|
21
|
+
repository_config["file_umask"].to_i,
|
22
|
+
repository_config["directory_umask"].to_i,
|
23
|
+
repository_config["file_url_username"],
|
24
|
+
repository_config["file_url_password"])
|
25
|
+
callbacks = []
|
26
|
+
repository_config["callbacks"].each do |callback_name, callback_config|
|
27
|
+
require ::File.join(@config["callback_path"], callback_name.to_s)
|
28
|
+
callback_class = callback_name.to_s.camelize.constantize
|
29
|
+
callbacks << callback_class.new(@logger, callback_config)
|
30
|
+
end
|
31
|
+
Client.new(repository, @logger, callbacks)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def run!
|
37
|
+
@logger.log("Starting filbunked")
|
38
|
+
while true
|
39
|
+
@clients.each do |client|
|
40
|
+
@logger.log("Updating repository: #{client.repository.name}")
|
41
|
+
new_checkpoint = client.update_files!(checkpoint_for_repository(client.repository))
|
42
|
+
update_checkpoint_for_repository(client.repository, new_checkpoint)
|
43
|
+
end
|
44
|
+
sleep @config["run_every"]
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def checkpoint_for_repository(repository)
|
51
|
+
@logger.log("Getting checkpoint for: #{repository.name}")
|
52
|
+
::File.open(checkpoint_file_name_for_repository(repository), 'r') {|f| f.readline.to_i } rescue 0
|
53
|
+
end
|
54
|
+
|
55
|
+
def update_checkpoint_for_repository(repository, checkpoint)
|
56
|
+
@logger.log("Updating checkpoint for: #{repository.name}")
|
57
|
+
f = ::File.new(checkpoint_file_name_for_repository(repository), 'w', repository.file_umask)
|
58
|
+
f.write(checkpoint)
|
59
|
+
f.close
|
60
|
+
end
|
61
|
+
|
62
|
+
def checkpoint_file_name_for_repository(repository)
|
63
|
+
FileUtils.mkdir_p(@config["checkpoint_path"], :mode => repository.directory_umask)
|
64
|
+
::File.join(@config["checkpoint_path"], repository.name + ".checkpoint")
|
65
|
+
end
|
66
|
+
|
67
|
+
def write_pid!(pid_file_path)
|
68
|
+
::File.open(pid_file_path, 'w') do |f|
|
69
|
+
f.write(Process.pid.to_i)
|
70
|
+
f.close
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
data/lib/filbunke/repository.rb
CHANGED
@@ -1,12 +1,15 @@
|
|
1
1
|
module Filbunke
|
2
2
|
class Repository
|
3
3
|
|
4
|
-
attr_accessor :host, :port, :
|
4
|
+
attr_accessor :name, :host, :port, :local_path, :file_umask, :directory_umask, :user, :pass
|
5
5
|
|
6
|
-
def initialize(name, host, port, user = nil, pass = nil)
|
6
|
+
def initialize(name, host, port, local_path, file_umask, directory_umask, user = nil, pass = nil)
|
7
7
|
@name = name
|
8
8
|
@host = host
|
9
9
|
@port = port
|
10
|
+
@local_path = local_path
|
11
|
+
@file_umask = file_umask
|
12
|
+
@directory_umask = directory_umask
|
10
13
|
@user = user
|
11
14
|
@pass = pass
|
12
15
|
end
|
data/lib/filbunke.rb
CHANGED
metadata
CHANGED
@@ -3,10 +3,10 @@ name: filbunke
|
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
|
+
- 1
|
6
7
|
- 0
|
7
|
-
-
|
8
|
-
|
9
|
-
version: 0.3.2
|
8
|
+
- 0
|
9
|
+
version: 1.0.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Wouter de Bie
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-11-
|
17
|
+
date: 2010-11-10 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -57,10 +57,16 @@ files:
|
|
57
57
|
- Rakefile
|
58
58
|
- VERSION
|
59
59
|
- bin/.gitignore
|
60
|
+
- bin/filbunked
|
61
|
+
- doc/examples/filbunke_config.yml
|
62
|
+
- doc/examples/http_evict_cache.rb
|
60
63
|
- filbunke.gemspec
|
61
64
|
- lib/filbunke.rb
|
65
|
+
- lib/filbunke/callbacks.rb
|
62
66
|
- lib/filbunke/client.rb
|
67
|
+
- lib/filbunke/daemon.rb
|
63
68
|
- lib/filbunke/file.rb
|
69
|
+
- lib/filbunke/logger.rb
|
64
70
|
- lib/filbunke/repository.rb
|
65
71
|
- test/helper.rb
|
66
72
|
- test/test_filbunke.rb
|