magicmonkey 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -19,13 +19,12 @@ Magicmonkey allows you to build in easy way the follow web server architecture:
19
19
  | Listen on port 3000 | | Listen on port 3001 | | Listen on port 3002 |
20
20
  | Site foo.com | | Site bar.com | | Site wella.com |
21
21
  +-------------------------------+ +-------------------------------+ +-------------------------------+
22
-
23
-
22
+
23
+
24
24
  Every your web applications have a virtual host like this:
25
25
 
26
26
  <VirtualHost *:80>
27
27
  ServerName foo.com
28
- PassengerEnabled off
29
28
  ProxyPass / http://127.0.0.1:3000/
30
29
  ProxyPassReverse / http://127.0.0.1:3000/
31
30
  </VirtualHost>
@@ -36,13 +35,13 @@ To do this you need to have install RVM to manage multiply Ruby versions.
36
35
  == Install
37
36
 
38
37
  gem install magicmonkey
39
-
38
+
40
39
  == Usage
41
40
 
42
41
  First of all you need to say to Magicmonkey that you want manage an application in this way. To to this use the magicmonkey command 'ADD':
43
42
 
44
43
  magicmonkey add APP_NAME [options]
45
-
44
+
46
45
  When added, you can start, stop, restart the application
47
46
 
48
47
  magicmonkey {start|stop|restart} APP_NAME1, APP_NAME2, ...
@@ -60,7 +59,7 @@ Magicmonkey save the configuration in <tt>~/.magicmonkey.yml</tt>
60
59
  You can use this email address for any questions or help: mailto:enrico@megiston.it.
61
60
 
62
61
  == Note on Patches/Pull Requests
63
-
62
+
64
63
  * Fork the project.
65
64
  * Make your feature addition or bug fix.
66
65
  * Add tests for it. This is important so I don't break it in a
@@ -0,0 +1,15 @@
1
+ module Thin
2
+
3
+ def self.start(args = {})
4
+ return "thin start -e production -p #{args[:port]} #{args[:app_server_options]} -d"
5
+ end
6
+
7
+ def self.stop(args = {})
8
+ return "thin stop -p #{args[:port]}"
9
+ end
10
+
11
+ def self.restart(args = {})
12
+ [self.stop(args), 'sleep 3', self.start(args)]
13
+ end
14
+
15
+ end
@@ -159,7 +159,7 @@ module MagicMonkey
159
159
  exit
160
160
  end
161
161
  end
162
- Conf[app_name] = o
162
+ Conf[app_name] = o.select{|k,v| [:ruby, :port, :app_server, :app_server_options, :app_path, :vhost_path].include?(k)}
163
163
  Conf.save
164
164
 
165
165
  puts "#{green}Application '#{app_name}' added.#{reset}"
@@ -188,17 +188,23 @@ module MagicMonkey
188
188
  end
189
189
  app_name = args.first
190
190
  if Conf[app_name]
191
+ self.start_stop_restart(:stop, [app_name])
192
+ begin
193
+ Cocaine::CommandLine.new("sudo a2dissite '#{app_name}'").run
194
+ rescue Cocaine::ExitStatusError => e
195
+ rputs 'Failed to disable site.'
196
+ end
191
197
  vh_file = "#{Conf[app_name][:vhost_path]}/#{app_name}"
192
198
  if o[:remove_vhost] && File.exist?(vh_file)
193
199
  begin
194
- Cocaine::CommandLine.new("sudo a2dissite '#{app_name}' && sudo rm -f '#{vh_file}'").run
200
+ Cocaine::CommandLine.new("sudo rm -f '#{vh_file}'").run
195
201
  rescue Cocaine::ExitStatusError => e
196
202
  rputs 'Failed to remove virtual host file.'
197
- exit
198
203
  end
199
204
  end
200
205
  Conf.delete(app_name)
201
206
  Conf.save
207
+ puts "Application '#{app_name}' removed."
202
208
  else
203
209
  rputs "Application '#{app_name}' does not exist."
204
210
  end
@@ -330,235 +336,3 @@ module MagicMonkey
330
336
  end
331
337
 
332
338
  end
333
-
334
- __END__
335
-
336
- def self.start2(argv)
337
- v, help = common_options(argv)
338
- if help
339
- puts 'Start a web application added with ADD command. If no params are given start all web applications.'
340
- exit
341
- end
342
- applications = argv
343
- applications = Conf.applications.keys if argv.empty?
344
- applications.each do |app_name|
345
- if Conf[app_name]
346
- commands = []
347
- if Conf[app_name][:ruby] != 'auto'
348
- commands << "source '#{Dir.home}/.rvm/scripts/rvm'"
349
- commands << "rvm #{v ? 'use ' : ''}'#{Conf[app_name][:ruby]}'"
350
- end
351
- commands << "cd '#{Conf[app_name][:app_path]}'"
352
- case Conf[app_name][:app_server]
353
- when 'passenger'
354
- commands << "passenger start -e production -p #{Conf[app_name][:port]} #{Conf[app_name][:app_server_options]} -d"
355
- when 'thin'
356
- commands << "thin start -e production -p #{Conf[app_name][:port]} #{Conf[app_name][:app_server_options]} -d"
357
- end
358
- print "Starting '#{app_name}' application..."
359
- STDOUT.flush
360
- output = `bash -c "#{commands.join(' && ')}"`
361
- puts ' done.'
362
- print output if v
363
- end
364
- end
365
- end
366
-
367
- def self.stop2(argv)
368
- v, help = common_options(argv)
369
- if help
370
- puts 'Stop a web application added with ADD command. If no params are given stop all web applications.'
371
- exit
372
- end
373
- applications = argv
374
- applications = Conf.applications.keys if argv.empty?
375
- applications.each do |app_name|
376
- if Conf[app_name]
377
- commands = []
378
- if Conf[app_name][:ruby] != 'auto'
379
- commands << "source '#{Etc.getpwuid.dir}/.rvm/scripts/rvm'"
380
- commands << "rvm #{v ? 'use ' : ''}'#{Conf[app_name][:ruby]}'"
381
- end
382
- commands << "cd '#{Conf[app_name][:app_path]}'"
383
- case Conf[app_name][:app_server]
384
- when 'passenger'
385
- commands << "passenger stop -p #{Conf[app_name][:port]}"
386
- when 'thin'
387
- commands << "thin stop -p #{Conf[app_name][:port]}"
388
- end
389
- print "Stopping '#{app_name}' application..."
390
- STDOUT.flush
391
- output = `bash -c "#{commands.join(' && ')}"`
392
- puts ' done.'
393
- print output if v
394
- end
395
- end
396
- end
397
-
398
- def self.restart2(argv)
399
- applications = argv
400
- applications = Conf.applications.keys if argv.empty?
401
- applications.each do |app_name|
402
- self.stop([app_name])
403
- self.start([app_name])
404
- end
405
- end
406
-
407
- def self.add2(argv)
408
- options = {}
409
- tmp = argv.join('$$').split(/\$\$--\$\$/)
410
- argv = tmp[0].split('$$')
411
- options[:app_server_options] = tmp[1] ? tmp[1].split('$$').join(' ') : ''
412
- servers = ['passenger', 'thin']
413
- ports = (3000..4000).to_a.collect{|p| p.to_s}
414
- options[:app_server] = servers.first
415
- options[:app_path] = '/var/sites/APP_NAME/current'
416
- options[:port] = nil
417
- options[:ruby] = 'auto'
418
- options[:vhost_path] = '/etc/apache2/sites-available'
419
- vhost_template = "#{Dir.home}/.magicmonkey.yml"
420
- force = false
421
- create_vhost = true
422
- enable_site = true
423
- reload_apache = false
424
- server_name = nil
425
-
426
- parser = OptionParser.new do |opts|
427
- opts.banner = 'Usage: magicmonkey add APP_NAME [options] [-- application_server_options]'
428
- opts.separator ''
429
- opts.separator 'Options:'
430
-
431
- opts.on('-s', '--app-server APP_SERVER', servers, "Use the given application server: #{servers.join(', ')} (default: #{options[:app_server]}).") do |s|
432
- options[:app_server] = s
433
- end
434
- opts.on('--app-path APP_PATH', "Use the given application path (default: '#{options[:app_path]}').") do |path|
435
- options[:app_path] = path
436
- end
437
- opts.on('--vhost-path VHOST_PATH', "Use the given virtual host path (default: '#{options[:vhost_path]}').") do |path|
438
- options[:vhost_path] = path
439
- end
440
- opts.on('--vhost-template TEMPLATE', "Use the given virtual host template file (default: #{vhost_template}).") do |template|
441
- vhost_template = template
442
- end
443
- opts.on('-p', '--port NUMBER', ports, "Use the given port number (min: #{ports.first}, max: #{ports.last}).") do |p|
444
- options[:port] = p.to_i
445
- end
446
- opts.on('-r', '--ruby RUBY_VERSION', "Use the given Ruby version (default: auto).") do |r|
447
- options[:ruby] = r
448
- end
449
- opts.on('-f', '--[no-]force', "Force mode: replace exist files (default: #{force}).") do |f|
450
- force = f
451
- end
452
- opts.on('--[no-]create-vhost', "Create virtual host file from template (default: #{create_vhost}).") do |c|
453
- create_vhost = c
454
- end
455
- opts.on('--[no-]enable-site', "Enable Apache virtual host (default: #{enable_site}).") do |e|
456
- enable_site = e
457
- end
458
- opts.on('--[no-]reload-apache', "Reload apache to load virtual host (default: #{reload_apache}).") do |r|
459
- reload_apache = r
460
- end
461
- opts.on('--server-name SERVER_NAME', "Set ServerName on virtual host (default: APP_NAME).") do |name|
462
- server_name = name
463
- end
464
- opts.on_tail('-h', '--help', 'Show this help message.') do
465
- puts opts
466
- exit
467
- end
468
- end
469
- begin
470
- argv = parser.parse!(argv)
471
- rescue
472
- puts parser.help
473
- exit
474
- end
475
- if argv.size != 1
476
- puts parser.help
477
- exit
478
- end
479
- app_name = argv[0]
480
- #setting up default values
481
- options[:app_path].gsub!('APP_NAME', app_name)
482
- port = get_port(options[:port])
483
- if port
484
- options[:port] = port
485
- else
486
- puts 'This port is busy'
487
- exit
488
- end
489
- #start
490
- if Conf[app_name].nil?
491
- Conf[app_name] = options
492
- puts "Configuration for application '#{app_name}' is:"
493
- pp Conf[app_name]
494
- print 'Add this application? [Y/n]'
495
- input = STDIN.gets
496
- if input.upcase == "Y\n" || input == "\n"
497
- if create_vhost
498
- vh = YAML.load_file(vhost_template)[:vhost_template]
499
- vh.gsub!('$APP_NAME', app_name)
500
- vh.gsub!('$SERVER_NAME', server_name || app_name)
501
- #vh.gsub!('$DOCUMENT_ROOT', Conf[app_name][:app_path])
502
- vh.gsub!('$PORT', Conf[app_name][:port].to_s)
503
- vh_file = "#{Conf[app_name][:vhost_path]}/#{app_name}"
504
- if !File.exist?(vh_file) || force
505
- #File.open(vh_file, 'w') { |f| f.write(vh) }
506
- print `sudo bash -c "echo '#{vh}' > #{vh_file}"`
507
- else
508
- puts "Virtual host file '#{vh_file}' already exist. Use option '-f' to replace it."
509
- exit
510
- end
511
- print `sudo a2ensite '#{app_name}'` if enable_site
512
- print `sudo /etc/init.d/apache2 reload` if enable_site && reload_apache
513
- end
514
- Conf.save
515
- puts 'Application added.'
516
- else
517
- puts 'Application rejected.'
518
- end
519
- else
520
- puts "Application '#{app_name}' already added. You can remove it with 'remove' command."
521
- end
522
- end
523
-
524
- def self.remove(argv)
525
- argv.each do |app_name|
526
- if Conf[app_name]
527
- vh_file = "#{Conf[app_name][:vhost_path]}/#{app_name}"
528
- if File.exist?(vh_file)
529
- print `sudo a2dissite '#{app_name}'`
530
- print `sudo rm -f #{vh_file}`
531
- end
532
- Conf.delete(app_name)
533
- Conf.save
534
- else
535
- puts "Application '#{app_name}' does not exist. You can add it with 'add' command."
536
- end
537
- end
538
- end
539
-
540
- private
541
-
542
- def self.rputs(message)
543
- puts "#{red}#{message}#{reset}"
544
- end
545
-
546
- def self.get_port(port = nil)
547
- ports = Conf.ports
548
- return 3000 if ports.nil? || ports.empty?
549
- return false if ports.include?(port)
550
- return ((3000..5000).to_a - ports).first if port.nil?
551
- return port
552
- end
553
-
554
- def self.common_options(argv)
555
- verbose = argv.include?('-v') || argv.include?('--version')
556
- help = argv.include?('-h') || argv.include?('--help')
557
- argv.delete('-v')
558
- argv.delete('--version')
559
- argv.delete('-h')
560
- argv.delete('--help')
561
- return verbose, help
562
- end
563
-
564
- end
@@ -1,3 +1,3 @@
1
1
  module Magicmonkey
2
- VERSION = '1.0.3'
2
+ VERSION = '1.0.4'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: magicmonkey
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-10-25 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: cocaine
16
- requirement: &70316082426460 !ruby/object:Gem::Requirement
16
+ requirement: &70166973463740 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70316082426460
24
+ version_requirements: *70166973463740
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: term-ansicolor
27
- requirement: &70316082426040 !ruby/object:Gem::Requirement
27
+ requirement: &70166973463280 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70316082426040
35
+ version_requirements: *70166973463280
36
36
  description: ! 'Manage your Rails applications: different Ruby versions and different
37
37
  application servers.'
38
38
  email:
@@ -49,6 +49,7 @@ files:
49
49
  - Rakefile
50
50
  - bin/magicmonkey
51
51
  - lib/magicmonkey/app_servers/passenger.rb
52
+ - lib/magicmonkey/app_servers/thin.rb
52
53
  - lib/magicmonkey/configuration.rb
53
54
  - lib/magicmonkey/magicmonkey.rb
54
55
  - lib/magicmonkey/version.rb