capobvious 0.2.8 → 0.2.9

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.
@@ -75,7 +75,7 @@ Capistrano::Configuration.instance.load do
75
75
 
76
76
  after 'deploy:update_code', 'bundle:install'
77
77
  after "deploy:update", "deploy:cleanup"
78
-
78
+
79
79
  if !exists?(:assets) || fetch(:assets) == true
80
80
  after 'deploy:update_code', 'assets:precompile'
81
81
  before 'deploy:finalize_update', 'assets:symlink'
@@ -147,10 +147,10 @@ Capistrano::Configuration.instance.load do
147
147
 
148
148
  namespace :auto do
149
149
  task :run do
150
- # bundle.install
151
- # if exists?(:assets) && fetch(:assets) == true
152
- # assets.precompile
153
- # end
150
+ # bundle.install
151
+ # if exists?(:assets) && fetch(:assets) == true
152
+ # assets.precompile
153
+ # end
154
154
  create.files
155
155
  if exists?(:sphinx) && fetch(:sphinx) == true
156
156
  sphinx.symlink
@@ -210,15 +210,38 @@ Capistrano::Configuration.instance.load do
210
210
  end
211
211
  end
212
212
 
213
+ def which(name)
214
+ str = capture("which #{name}").chop
215
+ return false if str == ''
216
+ str
217
+ rescue
218
+ false
219
+ end
220
+ def local_which(name)
221
+ str = `which #{name}`.chop
222
+ return false if str == ''
223
+ str
224
+ rescue
225
+ false
226
+ end
227
+ def ssh_port
228
+ exists?(:port) ? fetch(:port) : 22
229
+ end
230
+
231
+
213
232
  namespace :import do
214
233
  task :sys do
215
- backup.sys
216
- system "rm -rfv public/system/"
217
- system "cd public && #{arch_extract} ../#{local_folder_path}/#{sys_file_name}"
234
+ #system "rm -rfv public/system/"
235
+ if which('rsync') && local_which('rsync')
236
+ logger.important('Importing with rsync', 'import:sys')
237
+ system "rsync -avz --rsh='ssh -p#{ssh_port}' #{user}@#{serv}:#{shared_path}/system public/"
238
+ else
239
+ backup.sys
240
+ system "cd public && #{arch_extract} ../#{local_folder_path}/#{sys_file_name}"
241
+ end
218
242
  end
219
- # task :db do
220
- # db.pg_import
221
- # end
243
+ end
244
+ namespace :export do
222
245
  end
223
246
 
224
247
  #def prompt_with_default(var, default)
@@ -317,15 +340,15 @@ Capistrano::Configuration.instance.load do
317
340
 
318
341
  namespace :nginx do
319
342
  [:stop, :start, :restart, :reload].each do |action|
320
- desc "#{action.to_s} nginx"
321
- task action, :roles => :web do
322
- run "#{sudo} /etc/init.d/nginx #{action.to_s}"
343
+ desc "#{action.to_s} nginx"
344
+ task action, :roles => :web do
345
+ run "#{sudo} /etc/init.d/nginx #{action.to_s}"
346
+ end
323
347
  end
324
- end
325
348
 
326
349
  desc "Add app nginx conf to server"
327
350
  task :conf do
328
- default_nginx_template = <<-EOF
351
+ default_nginx_template = <<-EOF
329
352
  server {
330
353
  listen 80;
331
354
  server_name #{server_name};
@@ -340,7 +363,7 @@ Capistrano::Configuration.instance.load do
340
363
  # add_header ETag "";
341
364
  # break;
342
365
  # }
343
- #{exists?(:nginx_add)? fetch(:nginx_add) : ""}
366
+ #{exists?(:nginx_add)? fetch(:nginx_add) : ""}
344
367
 
345
368
  location ~ ^/(assets)/ {
346
369
  root #{current_path}/public;
@@ -362,7 +385,7 @@ Capistrano::Configuration.instance.load do
362
385
  EOF
363
386
  if exists?(:server_redirect)
364
387
  server_redirect = fetch(:server_redirect)#.split(" ")
365
- redirect_template = <<-RED
388
+ redirect_template = <<-RED
366
389
  server {
367
390
  server_name #{server_redirect};
368
391
  rewrite ^(.*)$ http://#{server_name.split(' ').first}$1 permanent;
@@ -456,16 +479,13 @@ Capistrano::Configuration.instance.load do
456
479
  end
457
480
 
458
481
 
459
- def which(name)
460
- run "which #{name}"
461
- end
462
482
 
463
483
  namespace :runit do
464
484
  [:stop, :start, :restart, :reload].each do |action|
465
- desc "#{action.to_s} runit"
466
- task action, :roles => :web do
467
- run "#{sudo} sv #{action.to_s} #{application}"
468
- end
485
+ desc "#{action.to_s} runit"
486
+ task action, :roles => :web do
487
+ run "#{sudo} sv #{action.to_s} #{application}"
488
+ end
469
489
  end
470
490
 
471
491
  desc "init"
@@ -520,11 +540,11 @@ run "#{sudo} chown -R root:root #{runit}"
520
540
 
521
541
 
522
542
  # Check if remote file exists
523
- #
543
+ #
524
544
  def remote_file_exists?(full_path)
525
545
  'true' == capture("if [ -e #{full_path} ]; then echo 'true'; fi").strip
526
546
  end
527
-
547
+
528
548
  # Check if process is running
529
549
  #
530
550
  def remote_process_exists?(pid_file)
@@ -532,6 +552,26 @@ run "#{sudo} chown -R root:root #{runit}"
532
552
  end
533
553
 
534
554
  namespace :unicorn do
555
+ desc "init autostart unicorn"
556
+ task :autostart do
557
+ #cd /home/rails/www/three-elements/current && sudo -u rails -H /home/rails/.rvm/bin/193_bundle exec /home/rails/.rvm/bin/193_unicorn -c /home/rails/www/three-elements/current/config/unicorn.rb -E production -D
558
+ join_ruby = rvm_ruby_string[/\d.\d.\d/].delete('.')
559
+ ruby_wrapper = "#{join_ruby}_unicorn"
560
+ ruby_wrapper_path = "/home/#{user}/.rvm/bin/#{ruby_wrapper}"
561
+ bundle_wrapper = "#{join_ruby}_bundle"
562
+ bundle_wrapper_path = "/home/#{user}/.rvm/bin/#{bundle_wrapper}"
563
+
564
+ run "rvm wrapper #{rvm_ruby_string} #{join_ruby} unicorn"
565
+ run "rvm wrapper #{rvm_ruby_string} #{join_ruby} bundle"
566
+ #puts "sudo -u #{user} -H /home/#{user}/.rvm/bin/#{wrapper} -c #{unicorn_conf} -E production -D"
567
+ command = "cd #{current_path} && sudo -u #{user} -H #{bundle_wrapper_path} exec #{ruby_wrapper_path} -c #{unicorn_conf} -E production -D"
568
+ puts command
569
+
570
+ run "#{sudo} sed -i 's/exit 0//g' /etc/rc.local"
571
+ run "echo \"#{command}\" | #{sudo} tee -a /etc/rc.local"
572
+ run "echo \"exit 0\" | #{sudo} tee -a /etc/rc.local"
573
+ end
574
+
535
575
  desc "start unicorn"
536
576
  task :start do
537
577
  if remote_file_exists?(unicorn_pid)
@@ -594,31 +634,31 @@ PID=<% unicorn_pid %>
594
634
 
595
635
  case "$1" in
596
636
  start)
597
- echo -n "Starting $DESC: "
598
- $DAEMON $DAEMON_OPTS
599
- echo "$NAME."
600
- ;;
637
+ echo -n "Starting $DESC: "
638
+ $DAEMON $DAEMON_OPTS
639
+ echo "$NAME."
640
+ ;;
601
641
  stop)
602
- echo -n "Stopping $DESC: "
642
+ echo -n "Stopping $DESC: "
603
643
  kill -QUIT `cat $PID`
604
- echo "$NAME."
605
- ;;
644
+ echo "$NAME."
645
+ ;;
606
646
  restart)
607
- echo -n "Restarting $DESC: "
647
+ echo -n "Restarting $DESC: "
608
648
  kill -QUIT `cat $PID`
609
- sleep 1
610
- $DAEMON $DAEMON_OPTS
611
- echo "$NAME."
612
- ;;
649
+ sleep 1
650
+ $DAEMON $DAEMON_OPTS
651
+ echo "$NAME."
652
+ ;;
613
653
  reload)
614
654
  echo -n "Reloading $DESC configuration: "
615
655
  kill -HUP `cat $PID`
616
656
  echo "$NAME."
617
657
  ;;
618
658
  *)
619
- echo "Usage: $NAME {start|stop|restart|reload}" >&2
620
- exit 1
621
- ;;
659
+ echo "Usage: $NAME {start|stop|restart|reload}" >&2
660
+ exit 1
661
+ ;;
622
662
  esac
623
663
 
624
664
  exit 0
@@ -658,16 +698,13 @@ EOF
658
698
  #http://stackoverflow.com/questions/4883891/ruby-on-rails-production-log-rotation
659
699
  task :init do
660
700
  str = %|
661
- #{shared_path}/log/*.log {
662
- weekly
701
+ #{shared_path}/log/*.log {
702
+ size=32M
703
+ rotate 10
663
704
  missingok
664
- rotate 52
665
705
  compress
666
706
  delaycompress
667
707
  notifempty
668
- create 640 root adm
669
- sharedscripts
670
- endscript
671
708
  copytruncate
672
709
  }
673
710
  |
@@ -1,3 +1,3 @@
1
1
  module Capobvious
2
- VERSION = "0.2.8"
2
+ VERSION = "0.2.9"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capobvious
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.8
4
+ version: 0.2.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-23 00:00:00.000000000 Z
12
+ date: 2012-10-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: capistrano