oye 0.1.9 → 0.1.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +1 -0
- data/lib/oye.rb +55 -26
- data/lib/oye/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4d831e91e5865351713d5cb2afcc47999d17295f38ff912be8a68cc4fa096702
|
4
|
+
data.tar.gz: bbee3ceed27964133da5521bcc60c03c1632ae734ae70d384b4badc6afaa0fee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a13bed4b5ba684e80a118cc96ae80840965844a1878fcf2400b5e675c883b6ba78d889e46838f4413b36aea5c5c81c811126a51e03adf33097e2e36b002dc98c
|
7
|
+
data.tar.gz: 54240a68d4cfabd48066b7b7a9c9e88ff1cca967150197068e22346fe83551ec3d38eba390b4d4d294e929c80a6f095cbc9e96370b1568323f9333ac94c0ce90
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -16,3 +16,4 @@ A continuous monitoring tool that does a few things:
|
|
16
16
|
[ ] create a git brach called 'oye' and pull from that one instead of 'origin'.
|
17
17
|
[ ] suport remote branches via 'ssh'. e.g. you can use `Net::SSH` as i use in '~/.ruby/req'
|
18
18
|
[ ] support 'jekyll serve' for people that dont want to use a web server for jekyll
|
19
|
+
[ ] split the file. use Oye::Actions as a namespace for update, restart, start, stop methods
|
data/lib/oye.rb
CHANGED
@@ -17,9 +17,9 @@ 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
|
+
stop_oye if(args.include?('-s') or args.include?('--stop'))
|
21
|
+
restart_oye if(args.include?('-r') or args.include?('--restart'))
|
22
|
+
config_oye if(args.include?('-c') or args.include?('--config'))
|
23
23
|
|
24
24
|
FileUtils.mkdir_p(oyedir)
|
25
25
|
|
@@ -66,9 +66,9 @@ module Oye
|
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
69
|
-
@
|
70
|
-
|
71
|
-
@
|
69
|
+
@default_unicorn_options = "-E #{@environment} -D"
|
70
|
+
@default_unicorn_options << " -l #{@port}" if @port
|
71
|
+
@default_jekyll_options = "-B"
|
72
72
|
|
73
73
|
monitor
|
74
74
|
end
|
@@ -95,24 +95,24 @@ module Oye
|
|
95
95
|
exit
|
96
96
|
end
|
97
97
|
|
98
|
+
# main method
|
98
99
|
def monitor
|
99
100
|
%w(TERM INT).each do |signal|
|
100
101
|
trap(signal) do
|
101
102
|
stop_oye
|
102
|
-
FileUtils.rm_f(oye_pidfile)
|
103
|
-
log(oye_pidfile, status: :info, message: "Stopped oye")
|
104
103
|
exit
|
105
104
|
end
|
106
105
|
end
|
107
106
|
|
107
|
+
# get change-times of origin repos
|
108
108
|
@repos.keys.filter_map do |origin|
|
109
109
|
next unless File.exists?(origin)
|
110
|
-
|
111
110
|
@repos[origin]['stat'] = File.stat(origin).ctime
|
112
111
|
end
|
113
112
|
|
114
113
|
pid = fork do
|
115
114
|
begin
|
115
|
+
# initial build and start of apps
|
116
116
|
@repos.values.flatten.each do |app|
|
117
117
|
app['clones'].each do |clone|
|
118
118
|
if !File.exists?(clone)
|
@@ -122,10 +122,11 @@ module Oye
|
|
122
122
|
|
123
123
|
build_app(clone)
|
124
124
|
|
125
|
-
|
125
|
+
start_app(clone)
|
126
126
|
end
|
127
127
|
end
|
128
128
|
|
129
|
+
# loop that watches for changes in origin repos
|
129
130
|
loop do
|
130
131
|
repos_dup = @repos
|
131
132
|
repos_dup.keys.each do |origin|
|
@@ -142,18 +143,15 @@ module Oye
|
|
142
143
|
|
143
144
|
unless @repos[origin]['stat'] == File.stat(origin).ctime
|
144
145
|
@repos[origin]['stat'] = File.stat(origin).ctime
|
145
|
-
stop_app(clone) if File.exists?(app_pid_file(clone))
|
146
146
|
update_app(clone)
|
147
147
|
build_app(clone)
|
148
|
-
|
148
|
+
restart_app(clone)
|
149
149
|
end
|
150
150
|
end
|
151
151
|
end
|
152
152
|
sleep @interval
|
153
153
|
end
|
154
154
|
end
|
155
|
-
rescue => e
|
156
|
-
abort "Fatal system error while initializing oye: #{e.message}, #{caller}"
|
157
155
|
end
|
158
156
|
|
159
157
|
File.open(oye_pidfile, 'w') { |f| f.puts pid }
|
@@ -194,20 +192,38 @@ module Oye
|
|
194
192
|
log(dir, status: :warn, message: "#{__method__.to_s} (#{e.message})")
|
195
193
|
end
|
196
194
|
|
197
|
-
def
|
195
|
+
def stop_app(dir)
|
198
196
|
if rails_app?(dir)
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
197
|
+
if File.exists?(app_pid_file(dir))
|
198
|
+
Process.kill 'TERM', app_pid(dir)
|
199
|
+
end
|
200
|
+
elsif jekyll_app?(dir)
|
201
|
+
if @environment == 'development'
|
202
|
+
%x(pkill -f jekyll)
|
203
|
+
end
|
204
204
|
end
|
205
205
|
rescue => e
|
206
206
|
log(dir, status: :warn, message: "#{__method__.to_s} (#{e.message})")
|
207
207
|
end
|
208
208
|
|
209
|
-
def
|
210
|
-
|
209
|
+
def start_app(dir)
|
210
|
+
Dir.chdir(dir) do
|
211
|
+
if rails_app?(dir)
|
212
|
+
unicorn_options = @default_unicorn_options << " -c #{unicorn_file(dir)}"
|
213
|
+
|
214
|
+
system("unicorn_rails #{unicorn_options}", [:out, :err] => File::NULL)
|
215
|
+
elsif jekyll_app?(dir)
|
216
|
+
if @environment == 'development'
|
217
|
+
jekyll_options = @default_jekyll_options << " -s #{dir} -d #{dir}/_site"
|
218
|
+
|
219
|
+
system("jekyll serve #{jekyll_options}", [:out, :err] => File::NULL)
|
220
|
+
end
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
log(dir, status: :info, message: "Started app")
|
225
|
+
rescue => e
|
226
|
+
log(dir, status: :warn, message: "#{__method__.to_s} (#{e.message})")
|
211
227
|
end
|
212
228
|
|
213
229
|
def update_app(dir)
|
@@ -226,13 +242,15 @@ module Oye
|
|
226
242
|
exit
|
227
243
|
end
|
228
244
|
|
229
|
-
|
245
|
+
# print oye config files
|
246
|
+
def config_oye
|
230
247
|
puts "Config file: #{oye_config}"
|
231
248
|
puts "Log file: #{oye_logfile}"
|
232
249
|
puts "PID file: #{oye_pidfile}"
|
233
250
|
exit
|
234
251
|
end
|
235
252
|
|
253
|
+
# print watched repos
|
236
254
|
def info
|
237
255
|
not_found = []
|
238
256
|
@repos.keys.each do |repo|
|
@@ -270,15 +288,24 @@ module Oye
|
|
270
288
|
|
271
289
|
def stop_oye
|
272
290
|
Process.kill 'TERM', oye_pid
|
291
|
+
FileUtils.rm_f(oye_pidfile)
|
292
|
+
log(oye_pidfile, status: :info, message: "Stopped oye")
|
293
|
+
rescue Errno::ENOENT
|
273
294
|
end
|
274
295
|
|
275
296
|
# TODO implement
|
276
|
-
def
|
297
|
+
def restart_oye
|
298
|
+
end
|
299
|
+
|
300
|
+
def restart_app(clone)
|
301
|
+
stop_app(clone)
|
302
|
+
start_app(clone)
|
277
303
|
end
|
278
304
|
|
279
305
|
private
|
280
306
|
|
281
|
-
#
|
307
|
+
# determine type of application
|
308
|
+
# #rails_
|
282
309
|
%w(rails jekyll).each do |app_type|
|
283
310
|
define_method("#{app_type}_app?") do |dir|
|
284
311
|
if File.exist?(gemfile(dir)) && File.read(gemfile(dir)).match?(/^\s*#{app_type}\b/)
|
@@ -293,6 +320,7 @@ module Oye
|
|
293
320
|
File.join(dir, "Gemfile.lock")
|
294
321
|
end
|
295
322
|
|
323
|
+
# return +true+ if the port is open else +false+
|
296
324
|
def port_open?(port)
|
297
325
|
begin
|
298
326
|
Timeout::timeout(1) do
|
@@ -318,10 +346,12 @@ module Oye
|
|
318
346
|
"#{oyedir}/oye.yml"
|
319
347
|
end
|
320
348
|
|
349
|
+
# log +oye+ actions
|
321
350
|
def oye_logfile
|
322
351
|
"#{oyedir}/oye.log"
|
323
352
|
end
|
324
353
|
|
354
|
+
# :stopdoc:
|
325
355
|
def oye_pidfile
|
326
356
|
"#{oyedir}/oye.pid"
|
327
357
|
end
|
@@ -330,7 +360,6 @@ module Oye
|
|
330
360
|
File.read(oye_pidfile).to_i
|
331
361
|
end
|
332
362
|
|
333
|
-
|
334
363
|
def unicorn_file(dir)
|
335
364
|
File.join(dir, "config/unicorn.rb")
|
336
365
|
end
|
data/lib/oye/version.rb
CHANGED