oye 0.1.7 → 0.1.12
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/Gemfile.lock +2 -2
- data/README.md +18 -0
- data/lib/oye.rb +92 -39
- data/lib/oye/version.rb +1 -1
- data/oye.gemspec +2 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a0f6ff207c4fac96695688a50e1b59a630d00d0da82f2b467d8e887a4a4f147c
|
4
|
+
data.tar.gz: '043181a7f859c284c01e8f37c9ca55f447e21a256e7e0b3f6c6d6bc1f4736e28'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7bba790ca065eb5b4ea379a28490ac02e80a63e3998582c0037733a31ad3b0496ef073e695f66d5157e452448526a72da44be0ec5f9ff6def5e1d91a4fa6d7f0
|
7
|
+
data.tar.gz: 4a4914bd17c72fb35875230f3e651b4db0109b07a9a21a781660ec7769012577794170792d225e12d24cc142fe19d52d30705a40e3b6dd4e4621d6c65b4667c6
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -10,4 +10,22 @@ A continuous monitoring tool that does a few things:
|
|
10
10
|
[ ] run rails tests inside Oye.monitor
|
11
11
|
[ ] check for irregularities in @repos, e.g two repeated cloned repos
|
12
12
|
[ ] give warning if port is not open by using `port_open?` method
|
13
|
+
- fix possible port conflicts. for example `oye -p 3000` will add that port to the list of ports (or sockets) already specified in the app's config file (unicorn.rb). but you print an error if there are port conflicts
|
13
14
|
[ ] why is the trap with `FileUtils.rm_f(oye_pidfile)` not removing the PID file
|
15
|
+
[ ] make a website for 'oye' where you provide better documentation. e.g.
|
16
|
+
- how to set up oye.yml
|
17
|
+
[ ] create a git brach called 'oye' and pull from that one instead of 'origin'.
|
18
|
+
[ ] suport remote branches via 'ssh'. e.g. you can use `Net::SSH` as i use in '~/.ruby/req'
|
19
|
+
[ ] support for webrick app server
|
20
|
+
[ ] support for apps that dont use an app server (e.g. oye.dance and sergioro.mx run in nginx alone)
|
21
|
+
[ ] support 'jekyll serve' for people that dont want to use a web server for jekyll
|
22
|
+
[ ] split the file. use Oye::Actions as a namespace for update, restart, start, stop methods
|
23
|
+
[ ] read environment for each app from oye.yml. e.g. user cn specify 'production' for one app and 'development' for another. The '-e' option is the default environment to be used if none is specified in oye.yml
|
24
|
+
[ ] change %x() to system() to prevent undesired prints to console (e.g. if you stop 'oye' while it is running '%x(bundler)' it will dump bundler errors to the console.)
|
25
|
+
[ ] give specific help for each command like jekyl does `jekyll [cmd] -h`
|
26
|
+
- e.g. with `oye port -h`
|
27
|
+
[ ] there might be a hard-to-find-bug if `oye` is executing a `git pull` while the origin repo is receiving data from a `git push`.
|
28
|
+
[ ] in 'oye.yml' you could pass an aditional parameter to specify what type of app it is. in this way you dont need to use `is_rails?`. e.g.
|
29
|
+
/git/pete.land.git:
|
30
|
+
- /var/www/html/pete.land:
|
31
|
+
type: jekyll
|
data/lib/oye.rb
CHANGED
@@ -2,9 +2,9 @@ $LOAD_PATH.unshift __dir__
|
|
2
2
|
|
3
3
|
require "oye/version"
|
4
4
|
require 'fileutils'
|
5
|
-
require 'yaml'
|
6
5
|
require 'socket'
|
7
6
|
require 'timeout'
|
7
|
+
require 'yaml'
|
8
8
|
|
9
9
|
module Oye
|
10
10
|
class Error < StandardError; end
|
@@ -17,9 +17,13 @@ module Oye
|
|
17
17
|
def start(args)
|
18
18
|
help if(args.include?('-h') or args.include?('--help'))
|
19
19
|
version if(args.include?('-v') or args.include?('--version'))
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
restart_oye if(args.include?('-r') or args.include?('--restart'))
|
21
|
+
config_oye if(args.include?('-c') or args.include?('--config'))
|
22
|
+
|
23
|
+
if(args.include?('-s') or args.include?('--stop'))
|
24
|
+
stop_oye
|
25
|
+
exit
|
26
|
+
end
|
23
27
|
|
24
28
|
FileUtils.mkdir_p(oyedir)
|
25
29
|
|
@@ -66,9 +70,9 @@ module Oye
|
|
66
70
|
end
|
67
71
|
end
|
68
72
|
|
69
|
-
@
|
70
|
-
|
71
|
-
@
|
73
|
+
@default_unicorn_options = "-E #{@environment} -D"
|
74
|
+
@default_unicorn_options << " -l #{@port}" if @port
|
75
|
+
@default_jekyll_options = "-B"
|
72
76
|
|
73
77
|
monitor
|
74
78
|
end
|
@@ -95,45 +99,38 @@ module Oye
|
|
95
99
|
exit
|
96
100
|
end
|
97
101
|
|
102
|
+
# main method
|
98
103
|
def monitor
|
99
104
|
%w(TERM INT).each do |signal|
|
100
105
|
trap(signal) do
|
101
106
|
stop_oye
|
102
|
-
FileUtils.rm_f(oye_pidfile)
|
103
107
|
exit
|
104
108
|
end
|
105
109
|
end
|
106
110
|
|
111
|
+
# get change-times of origin repos
|
107
112
|
@repos.keys.filter_map do |origin|
|
108
113
|
next unless File.exists?(origin)
|
109
|
-
|
110
114
|
@repos[origin]['stat'] = File.stat(origin).ctime
|
111
115
|
end
|
112
116
|
|
113
117
|
pid = fork do
|
114
118
|
begin
|
115
|
-
#
|
116
|
-
# TODO i dont like this loop
|
119
|
+
# initial build and start of apps
|
117
120
|
@repos.values.flatten.each do |app|
|
118
121
|
app['clones'].each do |clone|
|
119
|
-
|
120
122
|
if !File.exists?(clone)
|
121
123
|
log(clone, status: :warn, message: "Could not find repo")
|
122
124
|
next
|
123
|
-
elsif !File.exists?(app_pid_dir(clone))
|
124
|
-
log(clone, status: :warn, message: "Could not find pids directory")
|
125
|
-
next
|
126
|
-
elsif File.exists?(app_pid_file(clone))
|
127
|
-
# if pid fle exists, the app should be running and there's no need to be initialize it
|
128
|
-
next
|
129
125
|
end
|
130
126
|
|
131
|
-
|
127
|
+
build_app(clone)
|
132
128
|
|
133
|
-
|
129
|
+
start_app(clone)
|
134
130
|
end
|
135
131
|
end
|
136
132
|
|
133
|
+
# loop that watches for changes in origin repos
|
137
134
|
loop do
|
138
135
|
repos_dup = @repos
|
139
136
|
repos_dup.keys.each do |origin|
|
@@ -150,17 +147,15 @@ module Oye
|
|
150
147
|
|
151
148
|
unless @repos[origin]['stat'] == File.stat(origin).ctime
|
152
149
|
@repos[origin]['stat'] = File.stat(origin).ctime
|
153
|
-
|
154
|
-
|
155
|
-
|
150
|
+
update_app(clone)
|
151
|
+
build_app(clone)
|
152
|
+
restart_app(clone)
|
156
153
|
end
|
157
154
|
end
|
158
155
|
end
|
159
156
|
sleep @interval
|
160
157
|
end
|
161
158
|
end
|
162
|
-
rescue => e
|
163
|
-
abort "Fatal system error while initializing oye: #{e.message}, #{caller}"
|
164
159
|
end
|
165
160
|
|
166
161
|
File.open(oye_pidfile, 'w') { |f| f.puts pid }
|
@@ -181,31 +176,61 @@ module Oye
|
|
181
176
|
end
|
182
177
|
end
|
183
178
|
|
184
|
-
def
|
179
|
+
def build_app(dir)
|
185
180
|
Dir.chdir(dir) do
|
186
181
|
%x(bundle)
|
187
182
|
|
188
|
-
|
183
|
+
if rails_app?(dir)
|
184
|
+
%x(RAILS_ENV=#{@environment} rails db:migrate)
|
189
185
|
|
190
|
-
|
191
|
-
|
186
|
+
if @environment == 'production'
|
187
|
+
%x(RAILS_ENV=production rails assets:{clean,precompile})
|
188
|
+
end
|
189
|
+
elsif jekyll_app?(dir)
|
190
|
+
%x{jekyll build}
|
192
191
|
end
|
193
192
|
end
|
194
193
|
|
195
|
-
|
196
|
-
|
197
|
-
|
194
|
+
log(dir, status: :info, message: "Built app")
|
195
|
+
rescue => e
|
196
|
+
log(dir, status: :warn, message: "#{__method__.to_s} (#{e.message})")
|
197
|
+
end
|
198
198
|
|
199
|
-
|
199
|
+
def stop_app(dir)
|
200
|
+
if rails_app?(dir)
|
201
|
+
if File.exists?(app_pid_file(dir))
|
202
|
+
Process.kill 'TERM', app_pid(dir)
|
203
|
+
end
|
204
|
+
elsif jekyll_app?(dir)
|
205
|
+
if @environment == 'development'
|
206
|
+
%x(pkill -f jekyll)
|
207
|
+
end
|
208
|
+
end
|
200
209
|
rescue => e
|
201
210
|
log(dir, status: :warn, message: "#{__method__.to_s} (#{e.message})")
|
202
211
|
end
|
203
212
|
|
204
|
-
def
|
205
|
-
|
213
|
+
def start_app(dir)
|
214
|
+
Dir.chdir(dir) do
|
215
|
+
if rails_app?(dir)
|
216
|
+
unicorn_options = @default_unicorn_options << " -c #{unicorn_file(dir)}"
|
217
|
+
|
218
|
+
system("unicorn_rails #{unicorn_options}", [:out, :err] => File::NULL)
|
219
|
+
elsif jekyll_app?(dir)
|
220
|
+
if @environment == 'development'
|
221
|
+
jekyll_options = @default_jekyll_options << " -s #{dir} -d #{dir}/_site"
|
222
|
+
|
223
|
+
system("jekyll serve #{jekyll_options}", [:out, :err] => File::NULL)
|
224
|
+
end
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
log(dir, status: :info, message: "Started app")
|
229
|
+
rescue => e
|
230
|
+
log(dir, status: :warn, message: "#{__method__.to_s} (#{e.message})")
|
206
231
|
end
|
207
232
|
|
208
|
-
def
|
233
|
+
def update_app(dir)
|
209
234
|
system("git -C #{dir} pull", [:out, :err] => File::NULL)
|
210
235
|
|
211
236
|
log(dir, status: :info, message: "Pulled from origin")
|
@@ -221,13 +246,15 @@ module Oye
|
|
221
246
|
exit
|
222
247
|
end
|
223
248
|
|
224
|
-
|
249
|
+
# print oye config files
|
250
|
+
def config_oye
|
225
251
|
puts "Config file: #{oye_config}"
|
226
252
|
puts "Log file: #{oye_logfile}"
|
227
253
|
puts "PID file: #{oye_pidfile}"
|
228
254
|
exit
|
229
255
|
end
|
230
256
|
|
257
|
+
# print watched repos
|
231
258
|
def info
|
232
259
|
not_found = []
|
233
260
|
@repos.keys.each do |repo|
|
@@ -265,14 +292,39 @@ module Oye
|
|
265
292
|
|
266
293
|
def stop_oye
|
267
294
|
Process.kill 'TERM', oye_pid
|
295
|
+
FileUtils.rm_f(oye_pidfile)
|
296
|
+
log(oye_pidfile, status: :info, message: "Stopped oye")
|
297
|
+
rescue Errno::ENOENT
|
268
298
|
end
|
269
299
|
|
270
300
|
# TODO implement
|
271
|
-
def
|
301
|
+
def restart_oye
|
302
|
+
end
|
303
|
+
|
304
|
+
def restart_app(clone)
|
305
|
+
stop_app(clone)
|
306
|
+
start_app(clone)
|
272
307
|
end
|
273
308
|
|
274
309
|
private
|
275
310
|
|
311
|
+
# determine type of application
|
312
|
+
# #rails_
|
313
|
+
%w(rails jekyll).each do |app_type|
|
314
|
+
define_method("#{app_type}_app?") do |dir|
|
315
|
+
if File.exist?(gemfile(dir)) && File.read(gemfile(dir)).match?(/^\s*#{app_type}\b/)
|
316
|
+
true
|
317
|
+
else
|
318
|
+
false
|
319
|
+
end
|
320
|
+
end
|
321
|
+
end
|
322
|
+
|
323
|
+
def gemfile(dir)
|
324
|
+
File.join(dir, "Gemfile.lock")
|
325
|
+
end
|
326
|
+
|
327
|
+
# return +true+ if the port is open else +false+
|
276
328
|
def port_open?(port)
|
277
329
|
begin
|
278
330
|
Timeout::timeout(1) do
|
@@ -298,10 +350,12 @@ module Oye
|
|
298
350
|
"#{oyedir}/oye.yml"
|
299
351
|
end
|
300
352
|
|
353
|
+
# log +oye+ actions
|
301
354
|
def oye_logfile
|
302
355
|
"#{oyedir}/oye.log"
|
303
356
|
end
|
304
357
|
|
358
|
+
# :stopdoc:
|
305
359
|
def oye_pidfile
|
306
360
|
"#{oyedir}/oye.pid"
|
307
361
|
end
|
@@ -310,7 +364,6 @@ module Oye
|
|
310
364
|
File.read(oye_pidfile).to_i
|
311
365
|
end
|
312
366
|
|
313
|
-
|
314
367
|
def unicorn_file(dir)
|
315
368
|
File.join(dir, "config/unicorn.rb")
|
316
369
|
end
|
data/lib/oye/version.rb
CHANGED
data/oye.gemspec
CHANGED
@@ -8,6 +8,7 @@ Gem::Specification.new do |spec|
|
|
8
8
|
|
9
9
|
spec.summary = %q{Continuous monitoring tool}
|
10
10
|
spec.description = %q{Continuous monitoring tool}
|
11
|
+
spec.homepage = "https://oye.dance"
|
11
12
|
spec.license = "MIT"
|
12
13
|
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
13
14
|
|
@@ -27,5 +28,5 @@ Gem::Specification.new do |spec|
|
|
27
28
|
spec.add_development_dependency "ronn", "~> 0.7"
|
28
29
|
spec.add_development_dependency "ruby-prof", ">= 0"
|
29
30
|
|
30
|
-
#spec.add_runtime_dependency "
|
31
|
+
#spec.add_runtime_dependency "bundler", "~> 2.1.2"
|
31
32
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oye
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sergioro
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-05-
|
11
|
+
date: 2020-05-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: benchmark-ips
|
@@ -129,7 +129,7 @@ files:
|
|
129
129
|
- lib/oye.rb
|
130
130
|
- lib/oye/version.rb
|
131
131
|
- oye.gemspec
|
132
|
-
homepage:
|
132
|
+
homepage: https://oye.dance
|
133
133
|
licenses:
|
134
134
|
- MIT
|
135
135
|
metadata: {}
|