aptly-watcher 0.3.1 → 0.4
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 +9 -7
- data/lib/aptly/watcher.rb +25 -7
- data/lib/aptly/watcher/aptly_shim.rb +4 -2
- data/lib/aptly/watcher/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 559666bf483b86bfe158a4a8b658efe788bc1668
|
4
|
+
data.tar.gz: a3260100fbe61e3b5c6b4613cc4940aa96a20c60
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f01dc300b5ebd7cd0c3b3b912497d1e58d6e96332a8a2d0919f2cf655f014ce590a5f38089413383f4814b705b030f7d53db873b4bb91a3a72f0690cf8a08e9f
|
7
|
+
data.tar.gz: 4447ce3cbe77c308f6807ccbd9a9ea45422111ff8d86a4e2a19cbd1e919f7ac186ee0d9179c7d884a9a1aa6d8cce602fe318267f8c350ff9a31ff0f209d19f3d
|
data/README.md
CHANGED
@@ -26,15 +26,17 @@ First you need to create a config file as such (we parse tildes to `ENV['HOME']`
|
|
26
26
|
|
27
27
|
```yaml
|
28
28
|
---
|
29
|
-
:distrib: myapp
|
30
|
-
:repos:
|
29
|
+
:distrib: myapp # the distribution (or the name of your app)
|
30
|
+
:repos: # the repos to create and publish
|
31
31
|
- stable
|
32
32
|
- testing
|
33
|
-
:log: ~/watcher.log
|
34
|
-
:
|
35
|
-
:
|
36
|
-
:
|
37
|
-
:
|
33
|
+
:log: ~/watcher.log # use '-' for STDOUT, false to disable
|
34
|
+
:redis_log: aptly:watcher:log # the redis list to log into, set as false to disable
|
35
|
+
:conf: ~/aptly.conf # the location of the aptly conf file
|
36
|
+
:pidfile: ~/aptly-watcher.pid # the location of the aptly-watcher pidfile
|
37
|
+
:incoming_dir: ~/incoming # the base incoming directory
|
38
|
+
:user: aptly # the user to own the aptly directory after adding/publishing
|
39
|
+
:group: aptly # the group to own the aptly directory after adding/publishing
|
38
40
|
```
|
39
41
|
|
40
42
|
Then you can run the watcher with the config file:
|
data/lib/aptly/watcher.rb
CHANGED
@@ -11,12 +11,22 @@ module Aptly
|
|
11
11
|
class << self
|
12
12
|
|
13
13
|
def redis
|
14
|
+
return nil if @config[:redis_log] == false
|
14
15
|
@redis ||= Redis.new
|
15
16
|
end
|
16
17
|
|
17
18
|
def logger
|
18
19
|
return @logger if @logger
|
19
|
-
|
20
|
+
|
21
|
+
target = case @config[:log]
|
22
|
+
when '-'
|
23
|
+
STDOUT
|
24
|
+
when false
|
25
|
+
'/dev/null'
|
26
|
+
else
|
27
|
+
@config[:log]
|
28
|
+
end
|
29
|
+
|
20
30
|
@logger ||= Logger.new target, 0, 1024000
|
21
31
|
end
|
22
32
|
|
@@ -31,13 +41,21 @@ module Aptly
|
|
31
41
|
end
|
32
42
|
end
|
33
43
|
|
34
|
-
# log into redis so we can pick it up in the DMS
|
35
44
|
def log(level, message)
|
45
|
+
message.chomp.lines.each_with_index do |line, index| # multi line logging
|
46
|
+
line.chomp!
|
47
|
+
line = " #{line}" unless index.zero?
|
48
|
+
redis_log(level, line) if @config[:redis_log] != false
|
49
|
+
logger.send(level.to_sym, line) if @config[:log] != false
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def redis_log(level, message)
|
54
|
+
return false if redis.nil?
|
36
55
|
timestamp = Time.now.strftime('%Y-%m-%d %H:%M:%S')
|
37
56
|
msg = "#{level[0].upcase}, [#{timestamp}] #{level.upcase} -- #{message}"
|
38
|
-
redis.lpush(
|
39
|
-
redis.ltrim(
|
40
|
-
logger.send(level.to_sym, message)
|
57
|
+
redis.lpush(@config[:redis_log], msg)
|
58
|
+
redis.ltrim(@config[:redis_log], 0, 99)
|
41
59
|
end
|
42
60
|
|
43
61
|
# run the watcher with the given config
|
@@ -54,8 +72,8 @@ module Aptly
|
|
54
72
|
notifier.watch(repo_dir, :close_write) do |event|
|
55
73
|
begin
|
56
74
|
dispatcher.process(repo_dir, event, repo)
|
57
|
-
log :info, "Successfully added #{event.name} to #{repo}"
|
58
|
-
system "chown #{config[:user]}:#{config[:
|
75
|
+
log :info, "Successfully added #{event.name} to #{config[:distrib]}/#{repo}"
|
76
|
+
system "chown #{config[:user]}:#{config[:group]} #{config[:aptly]['rootDir']} -R"
|
59
77
|
rescue StandardError => e
|
60
78
|
e.message.lines.each {|line| log :error, line.chomp }
|
61
79
|
end
|
@@ -10,19 +10,21 @@ module Aptly
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def create
|
13
|
-
repo_list = `aptly repo list --raw`
|
13
|
+
repo_list = `aptly repo list #{config} --raw`
|
14
14
|
|
15
15
|
# create a repo for each component
|
16
16
|
@components.each do |repo|
|
17
17
|
next if repo_list.include? repo # avoid raising an error
|
18
18
|
output = `aptly repo create #{distrib} #{config} #{component(repo)} #{repo} 2>&1`
|
19
19
|
raise StandardError, "Failed to create repo #{repo}\n#{output}" unless $?.success?
|
20
|
+
Aptly::Watcher.log :info, "Created repo #{@name}/#{repo}"
|
20
21
|
end
|
21
22
|
|
22
23
|
# publish the repos for the first time (empty)
|
23
|
-
unless `aptly publish list --raw`.include? @name # avoid raising an error
|
24
|
+
unless `aptly publish list #{config} --raw`.include? @name # avoid raising an error
|
24
25
|
output = `aptly publish repo #{config} #{distrib} #{component(:all)} #{@components.join(' ')} 2>&1`
|
25
26
|
raise StandardError, "Failed to publish #{@name} for the first time\n#{output}" unless $?.success?
|
27
|
+
Aptly::Watcher.log :info, "Published repos #{@components.join('/')} for #{@name}"
|
26
28
|
end
|
27
29
|
end
|
28
30
|
|