fiverr_copy 1.0.2 → 1.0.3

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 CHANGED
@@ -18,7 +18,70 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
- TODO: Write usage instructions here
21
+ FiverrCopy automates the process of distributing files to multiple servers in a sync column method.
22
+ You'll need to write a "recipe" and boot up the server with that recipe.
23
+
24
+ What it actually does is to create a linked list of servers in which ever client is connected to the next client
25
+ starting with the server.
26
+ the server then distributes the file to the first client in queue, and this client passes every chunk of data it gets to the next client and so on.
27
+
28
+ the main benefit is obviously getting a more efficient way to distribute files to multiple machines than the normal scp, nfs mount, etc.
29
+
30
+ ## Recipes
31
+
32
+ To create a FiverrCopy recipe, just create a ruby file that looks something like this
33
+
34
+ ```ruby
35
+ FiverrCopy::Server.recipe = FiverrCopy::Recipe.new("My Awesome Script", "a void description") do |recipe|
36
+ recipe.filter = "*.jpg"
37
+ recipe.clients = ["server1", "server2"]
38
+ recipe.username = "serveruser"
39
+ recipe.port = 1555
40
+ recipe.chunk_size = 1024
41
+ recipe.manual = true
42
+ end
43
+ ```
44
+ * filter: this is the file selector that the FiverrCopy::Server will grab and tar before distribution, you can either specify a wildcard, a specific file or join both by spaces.
45
+ * clients: a list of ips or hosts to distribute the file to. protip: use host names that all the servers in the process are familiar with (server and clients).
46
+ * username: FiverrCopy uses Net::SSH to fire up some events, it counts on you that your current user can login to any of the machines using a username only and an ssh key.
47
+ * port: which port to run on.
48
+ * chunk_size: buffer size when sending file chunks.
49
+ * manuak: FiverrCopy will try to fire up clients when it runs, if you want to run them by yourself - toggle this option and the FiverrCopy::Server will assume the clients are ready.
50
+
51
+ ## Binary
52
+
53
+ FiverrCopy contains only one binary which is `fiverr_copy`:
54
+
55
+ ```bash
56
+ Usage: fiverr_copy [options]
57
+ -c, --client Run as client
58
+ -s, --server Run as server
59
+ -p, --port PORT Select a port. (default: 1234)
60
+ -r, --recipe FILE Specify a recipe file
61
+ -n, --nexthop IP/HOST Specify the next hop for distribution
62
+ -f, --filename FILENAME Specify filename
63
+ -w, --chunk CHUNK_SIZE specify chunk size
64
+ -h, --help Display this screen
65
+ ```
66
+
67
+ ## Examples
68
+
69
+ running a server:
70
+
71
+ `fiverr_copy --server --recipe /etc/distribute_mysql_dump.rb`
72
+
73
+ the server will only need the `--server` and the `--recipe` options.
74
+
75
+ running a client manually:
76
+
77
+ `fiverr_copy --client --port 1555 --filename mysql_dump_compressed_1333364100.tgz --chunk 1024`
78
+
79
+ this will run a FiverrCopy::Client instance on port 1555, reading 1024 bytes at a time from stream to the mysql_dump_compressed_* file destination.
80
+
81
+ ## TODOs
82
+
83
+ 1. Testing, how.
84
+
22
85
 
23
86
  ## Contributing
24
87
 
@@ -17,6 +17,22 @@ class FiverrCopy::Server
17
17
  compressed_file_name = "fiverr_copy_compressed_#{Time.now.to_i}.tgz"
18
18
 
19
19
  if !(self.recipe.manual_client_activation?)
20
+
21
+ last_hop = self.recipe.initialized_clients.shift
22
+
23
+ puts "Last Hop: #{last_hop.inspect}"
24
+ threads << Thread.new(last_hop) do |current_client|
25
+ current_client.setup!
26
+ Net::SSH.start(current_client.client_ip, current_client.username) do |ssh|
27
+ gem_exists = ssh.exec("which fiverr_copy") == "" ? false : true
28
+ if !(gem_exists)
29
+ puts "Please install the fiverr_copy gem on all clients."
30
+ exit 0
31
+ end
32
+ ssh.exec("fiverr_copy --client --port #{self.recipe.port} --filename #{compressed_file_name} --chunk #{self.recipe.chunk_size} \&")
33
+ end
34
+ end
35
+
20
36
  self.recipe.initialized_clients.each do |client|
21
37
  threads << Thread.new(client) do |current_client|
22
38
  current_client.setup!
@@ -27,11 +43,7 @@ class FiverrCopy::Server
27
43
  puts "Please install the fiverr_copy gem on all clients."
28
44
  exit 0
29
45
  end
30
- next_client = "--nexthop #{current_client.next_client}" if current_client.next_client
31
- puts "#{current_client.client_ip}: fiverr_copy --client --port #{self.recipe.port} --filename #{compressed_file_name} --chunk #{self.recipe.chunk_size} #{next_client} \&"
32
- silence_stream(STDOUT) do
33
- ssh.exec("fiverr_copy --client --port #{self.recipe.port} --filename #{compressed_file_name} --chunk #{self.recipe.chunk_size} #{next_client} \&")
34
- end
46
+ ssh.exec("fiverr_copy --client --port #{self.recipe.port} --filename #{compressed_file_name} --chunk #{self.recipe.chunk_size} --nexthop #{current_client.next_client} \&")
35
47
  end
36
48
  end
37
49
  end
@@ -75,7 +87,7 @@ class FiverrCopy::Server
75
87
  while !(client_session.closed?) && (buffer = transmitted_file.read(self.recipe.chunk_size)) do
76
88
  client_session.write buffer
77
89
  sent += self.recipe.chunk_size
78
- print "\r#{"%.2f" % (sent.to_f / file_size.to_f * 100)}% "
90
+ print "\r#{"%.2f" % (sent.to_f / file_size.to_f * 100)}% " if Time.now.to_i % 3 == 0
79
91
  end
80
92
  puts "Done!"
81
93
  end
@@ -1,3 +1,3 @@
1
1
  module FiverrCopy
2
- VERSION = "1.0.2"
2
+ VERSION = "1.0.3"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fiverr_copy
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 2
10
- version: 1.0.2
9
+ - 3
10
+ version: 1.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Elad Meidar