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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: db235ec5368219133e4a2c3b13de51ca4fc021a584ba625828c1584da3b8c2c1
4
- data.tar.gz: f0336786603d0f76352ed08230b514da02ab816fc0da825f4f5c5e308f9a8e04
3
+ metadata.gz: 4d831e91e5865351713d5cb2afcc47999d17295f38ff912be8a68cc4fa096702
4
+ data.tar.gz: bbee3ceed27964133da5521bcc60c03c1632ae734ae70d384b4badc6afaa0fee
5
5
  SHA512:
6
- metadata.gz: e7c8c761835d0cd0398cb6c629be42843ea7266f8b641f9ecb4bbaa0de12d35bda0fa4e39bce0cdf451d694ed31981a0a16fc7d0c4e1005ed03cd934756b1750
7
- data.tar.gz: 8883d0b11278ea7e5b8f898e887d910554b4da4c3fa46c8ee7506e64454c801cc00be98545cb4db757d43173cb48bf3a656eb30dd9a7b2dedf08515458a86aa5
6
+ metadata.gz: a13bed4b5ba684e80a118cc96ae80840965844a1878fcf2400b5e675c883b6ba78d889e46838f4413b36aea5c5c81c811126a51e03adf33097e2e36b002dc98c
7
+ data.tar.gz: 54240a68d4cfabd48066b7b7a9c9e88ff1cca967150197068e22346fe83551ec3d38eba390b4d4d294e929c80a6f095cbc9e96370b1568323f9333ac94c0ce90
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- oye (0.1.9)
4
+ oye (0.1.10)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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
- stop if(args.include?('-s') or args.include?('--stop'))
21
- restart if(args.include?('-r') or args.include?('--restart'))
22
- config if(args.include?('-c') or args.include?('--config'))
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
- @unicorn_default_options = "-E #{@environment} -D"
70
-
71
- @unicorn_default_options << " -l #{@port}" if @port
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
- serve_app(clone)
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
- serve_app(clone)
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 serve_app(dir)
195
+ def stop_app(dir)
198
196
  if rails_app?(dir)
199
- unicorn_options = @unicorn_default_options << " -c #{unicorn_file(dir)}"
200
-
201
- %x{unicorn_rails #{unicorn_options}}
202
-
203
- log(dir, status: :info, message: "Started app")
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 stop_app(dir)
210
- Process.kill 'TERM', app_pid(dir)
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
- def config
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 restart
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
- # rails_app?, jekyll_app?
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
@@ -1,3 +1,3 @@
1
1
  module Oye
2
- VERSION = "0.1.9"
2
+ VERSION = "0.1.10"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oye
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - sergioro