oye 0.1.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ba0137a6da4e4541a1691339760c047d60c4b223aafbdccc7195ceb85ebef815
4
+ data.tar.gz: b489de80c32505ff4009e30924ba1e1ba45698b456371a57dc6c917600e7e7ff
5
+ SHA512:
6
+ metadata.gz: bdf339dfbbae4ab3e961002c952532ce6aad899ce6f1d453ecf23afbaaa94aed67430cc2fcfca7845a2dba608df6b66e59d95530bf15d6fc0b00c894f707ef52
7
+ data.tar.gz: e22782ff4bfcf7f59ea864c52ac72e5469c265e90a0fe4fb21d2fee86b4cb3f85d6c3fef5ed9e44c1a726f6ee0944340d444a39f0495d1b1d128da640b093fb4
data/.gitignore ADDED
@@ -0,0 +1,57 @@
1
+ # files without extensions except directories
2
+ *
3
+ !/**/
4
+ !?*.*
5
+
6
+ # directories
7
+ .bundle/
8
+ _yardoc/
9
+ coverage/
10
+ doc/
11
+ pkg/
12
+ spec/reports/
13
+ tmp/
14
+ vendor/
15
+
16
+ # files
17
+ *.dump
18
+ *.log
19
+ *.mod
20
+ *.o
21
+ *~
22
+ .*.swp
23
+ .DS_Store
24
+ .byebug
25
+ .idea
26
+ .project
27
+ .rake*
28
+ .rake*
29
+ .ruby-*
30
+ .rvmrc
31
+ .rubocop*
32
+ .secret
33
+ .yardoc
34
+ TODO.md
35
+ core.*
36
+ cscope.out
37
+ secrets.yml
38
+ tags
39
+
40
+ # don't ignore
41
+ !.gitignore
42
+ !.keep
43
+ !Capfile
44
+ !Cheffile
45
+ !Gemfile
46
+ ![MR]akefile
47
+ !bin/**/[^.]*
48
+ !exe/**/[^.]*
49
+
50
+ /.bundle/
51
+ /.yardoc
52
+ /_yardoc/
53
+ /coverage/
54
+ /doc/
55
+ /pkg/
56
+ /spec/reports/
57
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.7.0
6
+ before_install: gem install bundler -v 2.1.2
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in oye.gemspec
4
+ gemspec
5
+
data/Gemfile.lock ADDED
@@ -0,0 +1,44 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ oye (0.1.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ansi (1.5.0)
10
+ benchmark-ips (2.7.2)
11
+ builder (3.2.4)
12
+ byebug (11.0.1)
13
+ hpricot (0.8.6)
14
+ minitest (5.14.1)
15
+ minitest-reporters (1.3.8)
16
+ ansi
17
+ builder
18
+ minitest (>= 5.0)
19
+ ruby-progressbar
20
+ mustache (1.1.1)
21
+ rake (13.0.1)
22
+ rdiscount (2.2.0.1)
23
+ ronn (0.7.3)
24
+ hpricot (>= 0.8.2)
25
+ mustache (>= 0.7.0)
26
+ rdiscount (>= 1.5.8)
27
+ ruby-prof (1.4.1)
28
+ ruby-progressbar (1.10.1)
29
+
30
+ PLATFORMS
31
+ ruby
32
+
33
+ DEPENDENCIES
34
+ benchmark-ips
35
+ byebug (~> 11.0.1)
36
+ minitest (~> 5.0)
37
+ minitest-reporters (~> 1.3.8)
38
+ oye!
39
+ rake (~> 13.0.1)
40
+ ronn (~> 0.7)
41
+ ruby-prof
42
+
43
+ BUNDLED WITH
44
+ 2.1.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 sergioro
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,9 @@
1
+ # Oye
2
+
3
+ A continuous monitoring tool that does a few things:
4
+
5
+ 1. listens for changes in bare git repos
6
+ 2. updates cloned repos when the corresponding bare repo changes
7
+ 3. restarts the rails app with the new code
8
+
9
+ [ ] use multithreaading. each thread should watch a unique repo.
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+ require 'rake/clean'
4
+
5
+ CLEAN.include ['**/.*.sw?', '**/*.gem', 'test/test.log']
6
+
7
+ task default: %i[test package]
8
+ task package: :clean
9
+
10
+ Rake::TestTask.new do |t|
11
+ t.libs << 'lib' << 'test'
12
+ t.test_files = FileList['test/**/*_test.rb']
13
+ t.warning = false
14
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "oye"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/oye ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift File.expand_path('../lib', __dir__)
4
+
5
+ require "oye"
6
+
7
+ Oye.start(ARGV)
@@ -0,0 +1,3 @@
1
+ module Oye
2
+ VERSION = "0.1.1"
3
+ end
data/lib/oye.rb ADDED
@@ -0,0 +1,188 @@
1
+ $LOAD_PATH.unshift __dir__
2
+
3
+ require "oye/version"
4
+ require 'fileutils'
5
+
6
+ module Oye
7
+ class Error < StandardError; end
8
+
9
+ @interval = 5
10
+
11
+ class << self
12
+ def start(args)
13
+ help if(args.include?('-h') or args.include?('--help'))
14
+ version if(args.include?('-v') or args.include?('--version'))
15
+ stop if(args.include?('-s') or args.include?('--stop'))
16
+ restart if(args.include?('-r') or args.include?('--restart'))
17
+ config if(args.include?('-c') or args.include?('--config'))
18
+
19
+ FileUtils.mkdir_p(oyedir)
20
+
21
+ read_config
22
+
23
+ list if(args.include?('-l') or args.include?('--list'))
24
+
25
+ if(args.include?('-i') or args.include?('--info'))
26
+ args.map! {|a| a == '--info' ? '-i' : a}
27
+ _, @pattern = args.slice!(args.index('-i'),2)
28
+ @pattern = @pattern.nil? ? /.*/ : Regexp.new(@pattern)
29
+ info
30
+ end
31
+
32
+ if(args.include?('-t') or args.include?('--time'))
33
+ args.map! {|a| a == '--time' ? '-t' : a}
34
+ _, @interval = args.slice!(args.index('-i'),2)
35
+ @interval = @interval.to_i
36
+ end
37
+
38
+ monitor
39
+ end
40
+
41
+ def read_config
42
+ @repos = {}
43
+
44
+ YAML.load(File.open(oye_config)).each do |origin, clone|
45
+ @repos[origin] = {'clone' => clone}
46
+ end
47
+ end
48
+
49
+ def help
50
+ puts <<~eos
51
+ -c, --config print config and log files
52
+ -h, --help print this message
53
+ -i, --info [PATTERN] print info of repos matching PATTERN (default .*)
54
+ -l, --list print monitored repos
55
+ -r, --restart restart oye
56
+ -s, --stop stop oye
57
+ -t, --time [SECS] time interval for repo monitoring (default 5)
58
+ -v, --version print oye version
59
+ eos
60
+ exit
61
+ end
62
+
63
+ def restart_clone
64
+ system("cd #{File.dirname(@repos[repo]['clone']}")
65
+ system("git pull")
66
+ system("kill $(cat pids/*)")
67
+ system("unicorn_rails -l 178.128.15.65:3001 -c config/unicorn.rb -E production -D")
68
+ end
69
+
70
+ def monitor
71
+ trap('TERM') { exit }
72
+ trap('INT') { exit }
73
+
74
+ not_found = []
75
+ repos_dup = @repos
76
+
77
+ repos_dup.keys.filter_map do |repo|
78
+ unless File.exists?(repo)
79
+ not_found << @repos.delete(repo)
80
+ next
81
+ end
82
+
83
+ @repos[repo]['stat'] = File.stat(repo).ctime
84
+ end
85
+
86
+ unless not_found.empty?
87
+ puts "\nWARNING Could not find repos:", not_found
88
+ end
89
+
90
+ log_format = "[%Y-%m-%d %H:%M:%S]"
91
+
92
+ pid = fork do
93
+ begin
94
+ loop do
95
+ repos_dup = @repos
96
+ repos_dup.each do |repo|
97
+ unless @repos[repo]['stat'] == File.stat(name).ctime
98
+ @repos[repo]['stats'] = File.stat(name).ctime
99
+
100
+ File.open(oye_logfile, 'a') do |f|
101
+ f.puts "#{@repos[repo]['stats'].strftime(log_format)} #{repo}"
102
+ end
103
+
104
+ restart_clone
105
+ end
106
+ end
107
+ sleep @interval
108
+ end
109
+ rescue => e
110
+ abort "There was a fatal system error while starting oye: #{e.message}, #{caller}"
111
+ end
112
+ end
113
+
114
+ File.open(oye_pidfile, 'w') { |f| f.puts pid }
115
+
116
+ ::Process.detach pid
117
+ end
118
+
119
+ def list
120
+ puts @repos.keys
121
+ exit
122
+ end
123
+
124
+ def config
125
+ puts "Config file: #{oye_config}"
126
+ puts "Log file: #{oye_logfile}"
127
+ exit
128
+ end
129
+
130
+ def info
131
+ not_found = []
132
+ @repos.keys.each do |repo|
133
+ next unless repo.match?(@pattern)
134
+
135
+ unless File.exists?(repo)
136
+ not_found << repo
137
+ next
138
+ end
139
+
140
+ ftime=File.stat(repo).ctime
141
+
142
+ # use same format than "ls -l"
143
+ time_format =
144
+ if ftime.year == Time.now.year
145
+ "%b %d %H:%M"
146
+ else
147
+ "%b %d %Y"
148
+ end
149
+
150
+ puts "#{ftime.strftime(time_format)} #{repo}"
151
+ end
152
+
153
+ unless not_found.empty?
154
+ puts "\nCould not find repos:", not_found
155
+ end
156
+
157
+ exit
158
+ end
159
+
160
+ def version
161
+ puts "oye #{VERSION}"
162
+ exit
163
+ end
164
+
165
+ def stop
166
+ end
167
+
168
+ def restart
169
+ end
170
+
171
+ def oyedir
172
+ "#{ENV['HOME']}/.oye"
173
+ end
174
+
175
+ # file with the name of repos that +oye+ should watch
176
+ def oye_config
177
+ "#{oyedir}/oye.yml"
178
+ end
179
+
180
+ def oye_logfile
181
+ "#{oyedir}/oye.log"
182
+ end
183
+
184
+ def oye_pidfile
185
+ "#{oyedir}/oye.pid"
186
+ end
187
+ end
188
+ end
data/oye.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ require_relative 'lib/oye/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "oye"
5
+ spec.version = Oye::VERSION
6
+ spec.authors = ["sergioro"]
7
+ spec.email = ["yo@sergioro.mx"]
8
+
9
+ spec.summary = %q{Continuous monitoring tool}
10
+ spec.description = %q{Continuous monitoring tool}
11
+ spec.license = "MIT"
12
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
13
+
14
+ # Specify which files should be added to the gem when it is released.
15
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
16
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
17
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+ spec.add_development_dependency "benchmark-ips", ">= 0"
23
+ spec.add_development_dependency "byebug", "~> 11.0.1"
24
+ spec.add_development_dependency "minitest", "~> 5.0"
25
+ spec.add_development_dependency "minitest-reporters", "~> 1.3.8"
26
+ spec.add_development_dependency "rake", "~> 13.0.1"
27
+ spec.add_development_dependency "ronn", "~> 0.7"
28
+ spec.add_development_dependency "ruby-prof", ">= 0"
29
+
30
+ #spec.add_runtime_dependency "SOME_GEM", "~> VERSION"
31
+ end
metadata ADDED
@@ -0,0 +1,155 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: oye
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - sergioro
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-05-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: benchmark-ips
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: byebug
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 11.0.1
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 11.0.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest-reporters
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.3.8
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.3.8
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 13.0.1
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 13.0.1
83
+ - !ruby/object:Gem::Dependency
84
+ name: ronn
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.7'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.7'
97
+ - !ruby/object:Gem::Dependency
98
+ name: ruby-prof
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Continuous monitoring tool
112
+ email:
113
+ - yo@sergioro.mx
114
+ executables:
115
+ - oye
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - ".gitignore"
120
+ - ".travis.yml"
121
+ - Gemfile
122
+ - Gemfile.lock
123
+ - LICENSE.txt
124
+ - README.md
125
+ - Rakefile
126
+ - bin/console
127
+ - bin/setup
128
+ - exe/oye
129
+ - lib/oye.rb
130
+ - lib/oye/version.rb
131
+ - oye.gemspec
132
+ homepage:
133
+ licenses:
134
+ - MIT
135
+ metadata: {}
136
+ post_install_message:
137
+ rdoc_options: []
138
+ require_paths:
139
+ - lib
140
+ required_ruby_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: 2.3.0
145
+ required_rubygems_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ requirements: []
151
+ rubygems_version: 3.1.2
152
+ signing_key:
153
+ specification_version: 4
154
+ summary: Continuous monitoring tool
155
+ test_files: []