filecluster 0.2.6 → 0.2.7
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/README.md +1 -0
- data/bin/fc-daemon +14 -2
- data/lib/daemon/task_thread.rb +1 -0
- data/lib/fc/db.rb +1 -0
- data/lib/fc/item.rb +2 -1
- data/lib/fc/storage.rb +14 -14
- data/lib/fc/version.rb +1 -1
- data/lib/manage/storages.rb +5 -2
- metadata +4 -4
data/README.md
CHANGED
@@ -46,6 +46,7 @@ Selecting available storage to copy item by policy.copy_storages (from left to t
|
|
46
46
|
|daemon_global_tasks_per_thread|10|tasks count for one task thread|
|
47
47
|
|daemon_global_tasks_threads_limit|10|tasks threads count limit for one storage|
|
48
48
|
|daemon_copy_tasks_limit|10|copy tasks count limit for one host|
|
49
|
+
|daemon_restart_period|86400|time between fc-daemon self restart|
|
49
50
|
|
50
51
|
## Usage
|
51
52
|
|
data/bin/fc-daemon
CHANGED
@@ -49,6 +49,9 @@ end
|
|
49
49
|
trap("TERM") {quit_on_quit}
|
50
50
|
trap("INT") {quit_on_quit}
|
51
51
|
|
52
|
+
|
53
|
+
|
54
|
+
start_time = Time.new.to_i
|
52
55
|
while true do
|
53
56
|
if $exit_signal
|
54
57
|
$log.debug('wait tasks_threads')
|
@@ -56,9 +59,13 @@ while true do
|
|
56
59
|
if $global_daemon_thread
|
57
60
|
$log.debug('wait global_daemon_thread')
|
58
61
|
$global_daemon_thread.join
|
59
|
-
end
|
62
|
+
end
|
60
63
|
$log.info('Exit')
|
61
|
-
|
64
|
+
if $exit_signal == :restart
|
65
|
+
exec('ruby', __FILE__)
|
66
|
+
else
|
67
|
+
exit
|
68
|
+
end
|
62
69
|
else
|
63
70
|
run_global_daemon
|
64
71
|
update_storages
|
@@ -68,4 +75,9 @@ while true do
|
|
68
75
|
end
|
69
76
|
$log.debug('sleep')
|
70
77
|
sleep FC::Var.get('daemon_cycle_time', 30).to_i
|
78
|
+
alive_time = Time.new.to_i - start_time
|
79
|
+
if !$exit_signal && alive_time > FC::Var.get('daemon_restart_period', 86400).to_i
|
80
|
+
$log.info("Self restart, #{alive_time} seconds up")
|
81
|
+
$exit_signal = :restart
|
82
|
+
end
|
71
83
|
end
|
data/lib/daemon/task_thread.rb
CHANGED
@@ -21,6 +21,7 @@ class TaskThread < BaseThread
|
|
21
21
|
item_storage = task[:item_storage]
|
22
22
|
storage = $storages.detect{|s| s.name == item_storage.storage_name}
|
23
23
|
item = FC::Item.find(item_storage.item_id)
|
24
|
+
$log.debug("Delete #{storage.path}#{item.name}")
|
24
25
|
storage.delete_file(item.name)
|
25
26
|
item_storage.delete
|
26
27
|
rescue Exception => e
|
data/lib/fc/db.rb
CHANGED
@@ -204,6 +204,7 @@ module FC
|
|
204
204
|
FC::DB.connect.query("INSERT INTO #{@prefix}vars SET name='daemon_global_tasks_per_thread', val='10', descr='tasks count for one task thread'")
|
205
205
|
FC::DB.connect.query("INSERT INTO #{@prefix}vars SET name='daemon_global_tasks_threads_limit', val='10', descr='tasks threads count limit for one storage'")
|
206
206
|
FC::DB.connect.query("INSERT INTO #{@prefix}vars SET name='daemon_copy_tasks_limit', val='10', descr='copy tasks count limit for one host'")
|
207
|
+
FC::DB.connect.query("INSERT INTO #{@prefix}vars SET name='daemon_restart_period', val='86400', descr='time between fc-daemon self restart'")
|
207
208
|
end
|
208
209
|
end
|
209
210
|
end
|
data/lib/fc/item.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
require 'shellwords'
|
2
3
|
|
3
4
|
module FC
|
4
5
|
class Item < DbBase
|
@@ -15,7 +16,7 @@ module FC
|
|
15
16
|
:name => item_name.to_s.gsub('//', '/').sub(/\/$/, '').sub(/^\//, '').strip,
|
16
17
|
:policy_id => policy.id,
|
17
18
|
:dir => File.directory?(local_path),
|
18
|
-
:size => `du -sb #{local_path}`.to_i
|
19
|
+
:size => `du -sb #{local_path.shellescape}`.to_i
|
19
20
|
})
|
20
21
|
item_params.delete(:replace)
|
21
22
|
item_params.delete(:inplace)
|
data/lib/fc/storage.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
require 'shellwords'
|
2
3
|
|
3
4
|
module FC
|
4
5
|
class Storage < DbBase
|
@@ -40,15 +41,14 @@ module FC
|
|
40
41
|
def copy_path(local_path, file_name)
|
41
42
|
dst_path = "#{self.path}#{file_name}"
|
42
43
|
|
43
|
-
cmd =
|
44
|
-
|
45
|
-
"ssh -oBatchMode=yes -oStrictHostKeyChecking=no #{self.host} 'mkdir -p #{File.dirname(dst_path)}'"
|
44
|
+
cmd = "rm -rf #{dst_path.shellescape}; mkdir -p #{File.dirname(dst_path).shellescape}"
|
45
|
+
cmd = self.class.curr_host == host ? cmd : "ssh -oBatchMode=yes -oStrictHostKeyChecking=no #{self.host} '#{cmd}'"
|
46
46
|
r = `#{cmd} 2>&1`
|
47
47
|
raise r if $?.exitstatus != 0
|
48
48
|
|
49
49
|
cmd = self.class.curr_host == host ?
|
50
|
-
"cp -r #{local_path} #{dst_path}" :
|
51
|
-
"scp -rB #{local_path} #{self.host}:#{dst_path}"
|
50
|
+
"cp -r #{local_path.shellescape} #{dst_path}" :
|
51
|
+
"scp -rB #{local_path.shellescape} #{self.host}:#{dst_path.shellescape}"
|
52
52
|
r = `#{cmd} 2>&1`
|
53
53
|
raise r if $?.exitstatus != 0
|
54
54
|
end
|
@@ -57,12 +57,12 @@ module FC
|
|
57
57
|
def copy_to_local(file_name, local_path)
|
58
58
|
src_path = "#{self.path}#{file_name}"
|
59
59
|
|
60
|
-
r = `mkdir -p #{File.dirname(local_path)} 2>&1`
|
60
|
+
r = `rm -rf #{local_path.shellescape}; mkdir -p #{File.dirname(local_path).shellescape} 2>&1`
|
61
61
|
raise r if $?.exitstatus != 0
|
62
62
|
|
63
63
|
cmd = self.class.curr_host == host ?
|
64
|
-
"cp -r #{src_path} #{local_path}" :
|
65
|
-
"scp -rB #{self.host}:#{src_path} #{local_path}"
|
64
|
+
"cp -r #{src_path.shellescape} #{local_path.shellescape}" :
|
65
|
+
"scp -rB #{self.host}:#{src_path.shellescape} #{local_path.shellescape}"
|
66
66
|
r = `#{cmd} 2>&1`
|
67
67
|
raise r if $?.exitstatus != 0
|
68
68
|
end
|
@@ -71,14 +71,14 @@ module FC
|
|
71
71
|
def delete_file(file_name)
|
72
72
|
dst_path = "#{self.path}#{file_name}"
|
73
73
|
cmd = self.class.curr_host == host ?
|
74
|
-
"rm -rf #{dst_path}" :
|
75
|
-
"ssh -oBatchMode=yes -oStrictHostKeyChecking=no #{self.host} 'rm -rf #{dst_path}'"
|
74
|
+
"rm -rf #{dst_path.shellescape}" :
|
75
|
+
"ssh -oBatchMode=yes -oStrictHostKeyChecking=no #{self.host} 'rm -rf #{dst_path.shellescape}'"
|
76
76
|
r = `#{cmd} 2>&1`
|
77
77
|
raise r if $?.exitstatus != 0
|
78
78
|
|
79
79
|
cmd = self.class.curr_host == host ?
|
80
|
-
"ls -la #{dst_path}" :
|
81
|
-
"ssh -oBatchMode=yes -oStrictHostKeyChecking=no #{self.host} 'ls -la #{dst_path}'"
|
80
|
+
"ls -la #{dst_path.shellescape}" :
|
81
|
+
"ssh -oBatchMode=yes -oStrictHostKeyChecking=no #{self.host} 'ls -la #{dst_path.shellescape}'"
|
82
82
|
r = `#{cmd} 2>/dev/null`
|
83
83
|
raise "Path #{dst_path} not deleted" unless r.empty?
|
84
84
|
end
|
@@ -88,8 +88,8 @@ module FC
|
|
88
88
|
dst_path = "#{self.path}#{file_name}"
|
89
89
|
|
90
90
|
cmd = self.class.curr_host == host ?
|
91
|
-
"du -sb #{dst_path}" :
|
92
|
-
"ssh -oBatchMode=yes -oStrictHostKeyChecking=no #{self.host} 'du -sb #{dst_path}'"
|
91
|
+
"du -sb #{dst_path.shellescape}" :
|
92
|
+
"ssh -oBatchMode=yes -oStrictHostKeyChecking=no #{self.host} 'du -sb #{dst_path.shellescape}'"
|
93
93
|
r = ignore_errors ? `#{cmd} 2>/dev/null` : `#{cmd} 2>&1`
|
94
94
|
raise r if $?.exitstatus != 0
|
95
95
|
r.to_i
|
data/lib/fc/version.rb
CHANGED
data/lib/manage/storages.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'shellwords'
|
3
|
+
|
1
4
|
def storages_list
|
2
5
|
storages = FC::Storage.where("1 ORDER BY host")
|
3
6
|
if storages.size == 0
|
@@ -230,7 +233,7 @@ def make_storages_sync(storage, make_delete, silent = false)
|
|
230
233
|
puts "Deleted #{count} items_storages" unless silent
|
231
234
|
|
232
235
|
# delete empty folders
|
233
|
-
count = `find #{storage.path} -empty -type d`.split("\n").count
|
234
|
-
`find #{storage.path} -empty -type d -delete` if make_delete
|
236
|
+
count = `find #{storage.path.shellescape} -empty -type d`.split("\n").count
|
237
|
+
`find #{storage.path.shellescape} -empty -type d -delete` if make_delete
|
235
238
|
puts "Deleted #{count} empty folders" unless silent
|
236
239
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: filecluster
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-10-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rb-readline
|
@@ -192,7 +192,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
192
192
|
version: '0'
|
193
193
|
segments:
|
194
194
|
- 0
|
195
|
-
hash:
|
195
|
+
hash: 2992741008983549077
|
196
196
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
197
197
|
none: false
|
198
198
|
requirements:
|
@@ -201,7 +201,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
201
201
|
version: '0'
|
202
202
|
segments:
|
203
203
|
- 0
|
204
|
-
hash:
|
204
|
+
hash: 2992741008983549077
|
205
205
|
requirements: []
|
206
206
|
rubyforge_project:
|
207
207
|
rubygems_version: 1.8.24
|