rest-ftp-daemon 0.100 → 0.100.2
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.
- checksums.yaml +4 -4
- data/README.md +50 -33
- data/lib/rest-ftp-daemon/api/job_presenter.rb +5 -1
- data/lib/rest-ftp-daemon/config.rb +0 -1
- data/lib/rest-ftp-daemon/constants.rb +3 -4
- data/lib/rest-ftp-daemon/job.rb +23 -5
- data/lib/rest-ftp-daemon/job_queue.rb +10 -8
- data/lib/rest-ftp-daemon/logger.rb +1 -1
- data/lib/rest-ftp-daemon/logger_pool.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a45abd6abf0d38a6dca977c42e81c1cf538dbd77
|
4
|
+
data.tar.gz: a0d3f0fd02e570f9f0f3d56ae403607e0d854a43
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f3d570450921acd5a1c8d0c61c89ad6ce6b0a97be868e74f3cacf654b3a7695e055345aa3111ca74f068572786b9d52fdbcaa1c2315efee26f8c924211890707
|
7
|
+
data.tar.gz: 733164d4039e1660d50850b889c17704718a65097337d9a9b368ea1b3fc29879e67d4ef27e597a102b8775a1c58ec4dc8461bb81d8be2c790b393bce31d02ca3
|
data/README.md
CHANGED
@@ -13,6 +13,8 @@ Features
|
|
13
13
|
|
14
14
|
As of today, its main features are :
|
15
15
|
|
16
|
+
* Offer a basic dashboard directly within the daemon HTTP interface
|
17
|
+
* Periodically send an update-notification with transfer status and progress
|
16
18
|
* Allow environment-specific configuration in a YAML file
|
17
19
|
* Delegate a transfer job by ``POST```'ing a simple JSON structure
|
18
20
|
* Spawn a dedicated thread to handle this job in its own context
|
@@ -24,6 +26,7 @@ As of today, its main features are :
|
|
24
26
|
* Provide RESTful notifications to the requesting client
|
25
27
|
* Allow authentication in FTP target in a standard URI-format
|
26
28
|
* Allow configuration-based path templates to abstract local mounts or remote FTPs (endpoint tokens)
|
29
|
+
* Allow to specify random remote/local source/target
|
27
30
|
* Remote supported protocols: FTP and FTPs
|
28
31
|
* Allow main file transfer protocols: sFTP, FTPs / FTPes
|
29
32
|
* Automatically clean-up jobs after a configurable amount of time (failed, finished)
|
@@ -34,13 +37,9 @@ As of today, its main features are :
|
|
34
37
|
|
35
38
|
Expected features in a short-time range :
|
36
39
|
|
37
|
-
* Allow change of priorities or other attributes after a job has been started
|
38
|
-
* Offer a basic dashboard directly within the daemon HTTP interface
|
39
|
-
* Periodically send an update-notification with transfer status and progress
|
40
40
|
* Allow fallback file source when first file path is unavailable (failover)
|
41
41
|
* Provide swagger-style API documentation
|
42
42
|
* Authenticate API clients
|
43
|
-
* Allow to specify random remote/local source/target
|
44
43
|
* Allow more transfer protocols (sFTP, HTTP POST etc)
|
45
44
|
|
46
45
|
Known bugs :
|
@@ -58,8 +57,8 @@ You may use ```rbenv``` and ```ruby-build``` to get the right Ruby version. If t
|
|
58
57
|
```
|
59
58
|
# apt-get install ruby-build rbenv
|
60
59
|
# ruby-build --definitions | grep '2.1'
|
61
|
-
|
62
60
|
```
|
61
|
+
|
63
62
|
Otherwise, you way have to update ruby-build to include Ruby 2.1.0 definitions.
|
64
63
|
On Debian, 2.1.0 is not included in Wheezy and appears in Jessie's version of the package.
|
65
64
|
|
@@ -90,18 +89,6 @@ Update RubyGems and install the gem from rubygems.org
|
|
90
89
|
# rest-ftp-daemon start
|
91
90
|
```
|
92
91
|
|
93
|
-
Finally start the daemon on the standart port, or on a specific port using ```-p```
|
94
|
-
|
95
|
-
```
|
96
|
-
# rest-ftp-daemon -p 4000 start
|
97
|
-
```
|
98
|
-
|
99
|
-
Check that the daemon is running and providing its status info.
|
100
|
-
If the daemon seems to exit as soon as it's launched, this may be due to logfiles that cannot be written on (check permissions or owner).
|
101
|
-
|
102
|
-
```
|
103
|
-
http://localhost:3200/
|
104
|
-
```
|
105
92
|
|
106
93
|
Configuration
|
107
94
|
------------------------------------------------------------------------------------
|
@@ -123,6 +110,38 @@ As a starting point, ``rest-ftp-daemon.yml.sample`` is an exemple config file th
|
|
123
110
|
Default administrator credentials are admin/admin. Please change the password in this configuration file before starting any kind of production.
|
124
111
|
|
125
112
|
|
113
|
+
Execution
|
114
|
+
------------------------------------------------------------------------------------
|
115
|
+
|
116
|
+
You can simply start the daemon on the standart port, or on a specific port using ```-p```
|
117
|
+
|
118
|
+
```
|
119
|
+
# rest-ftp-daemon -p 4000 start
|
120
|
+
```
|
121
|
+
|
122
|
+
Check that the daemon is running and exposes a JSON status structure on ```http://localhost:3200/status```.
|
123
|
+
|
124
|
+
The dashbaord will provide a gobal view on ```http://localhost:3200/```
|
125
|
+
|
126
|
+
If the daemon appears to exit quickly when launched, it may be caused by logfiles that can't be written (check files permissions or owner).
|
127
|
+
|
128
|
+
Launcher options :
|
129
|
+
|
130
|
+
| Param | Short | Default | Description |
|
131
|
+
|------- |-------------- |------------- |----------------------------------------------------------- |
|
132
|
+
| -p | --port | (automatic) | Port to listen for API requests |
|
133
|
+
| -e | | production | Environment name |
|
134
|
+
| | --dev | | Equivalent to -e development |
|
135
|
+
| -w | --workers | 1 | Number of workers spawned at launch |
|
136
|
+
| -d | --daemonize | false | Wether to send the daemon to background |
|
137
|
+
| -f | --foreground | false | Wether to keep the daemon running in the shell |
|
138
|
+
| -P | --pid | (automatic) | Path of the file containing the PID |
|
139
|
+
| -u | --user | (none) | User to run the daemon as |
|
140
|
+
| -g | --group | (none) | Group of the user to run the daemon as |
|
141
|
+
| -h | --help | | Show info about the current version and available options |
|
142
|
+
| -v | --version | | Show the current version |
|
143
|
+
|
144
|
+
|
126
145
|
Logging
|
127
146
|
------------------------------------------------------------------------------------
|
128
147
|
|
@@ -133,12 +152,12 @@ Otherwise separate logging paths can be provided for the Thin webserver, API rel
|
|
133
152
|
Job cleanup
|
134
153
|
------------------------------------------------------------------------------------
|
135
154
|
|
136
|
-
Job can be cleanup up after a certain
|
155
|
+
Job can be cleanup up after a certain delay, when they are on one of these status:
|
137
156
|
|
138
|
-
- failed, after conchita.clean_failed seconds
|
139
|
-
- finished, after conchita.clean_finished seconds
|
157
|
+
- "failed", cleaned up after conchita.clean_failed seconds
|
158
|
+
- "finished", cleaned up after conchita.clean_finished seconds
|
140
159
|
|
141
|
-
Cleanup is done on a regular basis, every
|
160
|
+
Cleanup is done on a regular basis, every X seconds (X = conchita.timer)
|
142
161
|
|
143
162
|
|
144
163
|
Usage examples
|
@@ -184,20 +203,18 @@ GET http://localhost:3100/jobs/1
|
|
184
203
|
```
|
185
204
|
|
186
205
|
|
187
|
-
|
188
|
-
Doc TODO
|
206
|
+
TODO for this document
|
189
207
|
------------------------------------------------------------------------------------
|
190
208
|
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
Document
|
196
|
-
|
197
|
-
Document
|
198
|
-
|
199
|
-
Document counters
|
200
|
-
|
209
|
+
* Update Apiary documentation
|
210
|
+
* Update Apiary documentation
|
211
|
+
* Update Apiary documentation
|
212
|
+
* Update Apiary documentation !
|
213
|
+
* Document /status
|
214
|
+
* Document /routes
|
215
|
+
* Document multiple-files upload
|
216
|
+
* Document mkdir and overwrite options
|
217
|
+
* Document counters
|
201
218
|
|
202
219
|
|
203
220
|
About
|
@@ -17,10 +17,14 @@ module RestFtpDaemon
|
|
17
17
|
|
18
18
|
expose :error
|
19
19
|
expose :status
|
20
|
-
|
21
20
|
expose :queued_at
|
22
21
|
expose :updated_at
|
22
|
+
expose :started_at
|
23
|
+
expose :finished_at
|
24
|
+
|
25
|
+
# Computed fields
|
23
26
|
expose :age
|
27
|
+
expose :exectime
|
24
28
|
|
25
29
|
# Params
|
26
30
|
# expose :wid, unless: lambda { |object, options| object.wid.nil? }
|
@@ -1,21 +1,20 @@
|
|
1
1
|
# Terrific constants
|
2
2
|
APP_NAME = "rest-ftp-daemon"
|
3
3
|
APP_CONF = "/etc/#{APP_NAME}.yml"
|
4
|
-
APP_VER = "0.100"
|
4
|
+
APP_VER = "0.100.2"
|
5
5
|
|
6
6
|
# Some global constants
|
7
7
|
IDENT_JOB_LEN = 4
|
8
8
|
IDENT_NOTIF_LEN = 4
|
9
9
|
IDENT_RANDOM_LEN = 8
|
10
|
+
DEFAULT_LOGS_PIPE_LEN = 15
|
11
|
+
DEFAULT_LOGS_ID_LEN = 8
|
10
12
|
|
11
13
|
# Some defaults
|
12
14
|
DEFAULT_CONNECT_TIMEOUT_SEC = 30
|
13
15
|
DEFAULT_UPDATE_EVERY_KB = 2048
|
14
16
|
DEFAULT_WORKERS = 1
|
15
17
|
|
16
|
-
DEFAULT_LOGS_PIPE_WIDTH = 15
|
17
|
-
DEFAULT_LOGS_ID_WIDTH = 8
|
18
|
-
|
19
18
|
# Initialize markers
|
20
19
|
APP_STARTED = Time.now
|
21
20
|
APP_LIBS = File.dirname(__FILE__)
|
data/lib/rest-ftp-daemon/job.rb
CHANGED
@@ -17,6 +17,9 @@ module RestFtpDaemon
|
|
17
17
|
attr_reader :queued_at
|
18
18
|
attr_reader :updated_at
|
19
19
|
|
20
|
+
attr_reader :started_at
|
21
|
+
attr_reader :finished_at
|
22
|
+
|
20
23
|
attr_reader :params
|
21
24
|
|
22
25
|
FIELDS.each do |field|
|
@@ -34,6 +37,12 @@ module RestFtpDaemon
|
|
34
37
|
instance_variable_set("@#{field.to_s}", params[field])
|
35
38
|
end
|
36
39
|
@params = {}
|
40
|
+
@updated_at = nil
|
41
|
+
@started_at = nil
|
42
|
+
@finished_at = nil
|
43
|
+
@error = nil
|
44
|
+
@status = nil
|
45
|
+
@wid = nil
|
37
46
|
|
38
47
|
# Logger
|
39
48
|
# @logger = RestFtpDaemon::Logger.new(:workers, "JOB #{id}")
|
@@ -173,10 +182,15 @@ module RestFtpDaemon
|
|
173
182
|
protected
|
174
183
|
|
175
184
|
def age
|
176
|
-
return
|
185
|
+
return nil if @queued_at.nil?
|
177
186
|
(Time.now - @queued_at).round(2)
|
178
187
|
end
|
179
188
|
|
189
|
+
def exectime
|
190
|
+
return nil if (@started_at.nil? || @finished_at.nil?)
|
191
|
+
(@finished_at - @started_at).round(2)
|
192
|
+
end
|
193
|
+
|
180
194
|
def wander time
|
181
195
|
info "Job.wander #{time}"
|
182
196
|
@wander_for = time
|
@@ -267,6 +281,9 @@ module RestFtpDaemon
|
|
267
281
|
end
|
268
282
|
|
269
283
|
def transfer
|
284
|
+
# Start transfert flag
|
285
|
+
@started_at = Time.now
|
286
|
+
|
270
287
|
# Method assertions and init
|
271
288
|
@status = :checking_source
|
272
289
|
raise RestFtpDaemon::JobAssertionFailed unless @source_path && @target_url
|
@@ -311,13 +328,14 @@ module RestFtpDaemon
|
|
311
328
|
set :source_processed, done
|
312
329
|
end
|
313
330
|
|
314
|
-
# Add total transferred to counter
|
315
|
-
$queue.counter_add :transferred, @transfer_total
|
316
|
-
|
317
331
|
# Close FTP connexion
|
318
332
|
@ftp.close
|
319
333
|
info "Job.transfer disconnecting"
|
320
334
|
@status = :disconnecting
|
335
|
+
|
336
|
+
# Update counters and flags
|
337
|
+
$queue.counter_add :transferred, @transfer_total
|
338
|
+
@finished_at = Time.now
|
321
339
|
end
|
322
340
|
|
323
341
|
private
|
@@ -524,7 +542,7 @@ module RestFtpDaemon
|
|
524
542
|
stack << (Helpers.format_bytes @transfer_sent, "B")
|
525
543
|
stack << (Helpers.format_bytes @transfer_total, "B")
|
526
544
|
stack << (Helpers.format_bytes bitrate0, "bps")
|
527
|
-
info "Job.ftp_transfer" + stack.map{|txt| ("%#{
|
545
|
+
info "Job.ftp_transfer" + stack.map{|txt| ("%#{DEFAULT_LOGS_PIPE_LEN.to_i}s" % txt)}.join("\t")
|
528
546
|
|
529
547
|
# Update time pointer
|
530
548
|
t0 = Time.now
|
@@ -67,12 +67,14 @@ module RestFtpDaemon
|
|
67
67
|
end
|
68
68
|
|
69
69
|
def counter_get name
|
70
|
-
@
|
70
|
+
@mutex_counters.synchronize do
|
71
|
+
@counters[name]
|
72
|
+
end
|
71
73
|
end
|
72
74
|
|
73
75
|
def counters
|
74
76
|
@mutex_counters.synchronize do
|
75
|
-
@counters
|
77
|
+
@counters
|
76
78
|
end
|
77
79
|
end
|
78
80
|
|
@@ -90,8 +92,6 @@ module RestFtpDaemon
|
|
90
92
|
end
|
91
93
|
|
92
94
|
def all
|
93
|
-
# queued2 = @queued.clone
|
94
|
-
# return queued2.merge(@popped)
|
95
95
|
@queued + @popped
|
96
96
|
end
|
97
97
|
def all_size
|
@@ -115,7 +115,6 @@ module RestFtpDaemon
|
|
115
115
|
@mutex.synchronize do
|
116
116
|
# Push job into the queue
|
117
117
|
@queued.push job
|
118
|
-
#info "JobQueue.push: #{job.id}"
|
119
118
|
|
120
119
|
# Tell the job it's been queued
|
121
120
|
job.set_queued if job.respond_to? :set_queued
|
@@ -132,7 +131,6 @@ module RestFtpDaemon
|
|
132
131
|
alias << push
|
133
132
|
alias enq push
|
134
133
|
|
135
|
-
|
136
134
|
def pop(non_block=false)
|
137
135
|
# info "JobQueue.pop"
|
138
136
|
@mutex.synchronize do
|
@@ -165,11 +163,15 @@ module RestFtpDaemon
|
|
165
163
|
end
|
166
164
|
|
167
165
|
def ordered_queue
|
168
|
-
@
|
166
|
+
@mutex_counters.synchronize do
|
167
|
+
@queued.sort_by { |item| [item.priority.to_i, - item.id.to_i] }
|
168
|
+
end
|
169
169
|
end
|
170
170
|
|
171
171
|
def ordered_popped
|
172
|
-
@
|
172
|
+
@mutex_counters.synchronize do
|
173
|
+
@popped.sort_by { |item| [item.updated_at] }
|
174
|
+
end
|
173
175
|
end
|
174
176
|
|
175
177
|
protected
|
@@ -3,7 +3,7 @@ class Logger
|
|
3
3
|
attr_accessor :pipe
|
4
4
|
|
5
5
|
def info_with_id message, options = {}
|
6
|
-
field_id = "%#{-
|
6
|
+
field_id = "%#{-DEFAULT_LOGS_ID_LEN.to_i}s" % options[:id].to_s
|
7
7
|
add Logger::INFO, "#{field_id} \t#{' '*(options[:level].to_i+1)}#{message}"
|
8
8
|
end
|
9
9
|
|
@@ -25,7 +25,7 @@ module RestFtpDaemon
|
|
25
25
|
logger.formatter = proc do |severity, datetime, progname, message|
|
26
26
|
# stamp = Time.now.strftime("%Y-%m-%d %H:%M:%S")
|
27
27
|
stamp = datetime.strftime("%Y-%m-%d %H:%M:%S")
|
28
|
-
field_pipe = "%-#{
|
28
|
+
field_pipe = "%-#{DEFAULT_LOGS_PIPE_LEN.to_i}s" % progname
|
29
29
|
"#{stamp} #{field_pipe} #{message}\n"
|
30
30
|
end
|
31
31
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rest-ftp-daemon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 0.100.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bruno MEDICI
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-12-
|
11
|
+
date: 2014-12-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|