Module: MagicRecipes::PrivatePub

Defined in:
lib/magic_recipes/private_pub.rb

Overview

PrivatePub - Deploy-Recipes

Easy deployment of private_pub .. which can be frustrating on nginx because of the tcp server

Tasks:

:reconf # => Generate the thin yml configuration file.

:setup # => Generate the nginx configuration file.

:yml_file # => Generate the private_pup yml configuration file.

:start # => Start the private_pup server

:stop # => Start the private_pup server

:restart # => Restart the private_pup server

Callbacks:

before “thin:start”, “private_pub:yml_file”

after “thin:start”, “private_pub:start”

after “thin:stop”, “private_pub:stop”

after “nginx:setup”, “private_pub:setup”

after “thin:reconf”, “private_pub:reconf”

Class Method Summary collapse

Class Method Details

.load_into(configuration) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/magic_recipes/private_pub.rb', line 32

def self.load_into(configuration)
  configuration.load do
    
    set_default :private_pub_domain, "0.0.0.0"            # => private_pub domain
    #set_default :private_pub_instances, 1                # => private_pub server instances .. for now only 1 !
    set_default :private_pub_host, 9200                   # => public port
    set_default :private_pub_port, 9292                   # => intern port
    set_default(:private_pub_key, "882293e492b7e7a2fed266a5f38062420e12fb75eae5f145e256af60dc9681bc")

    namespace :private_pub do
      
      # needs nginx_tcp_proxy_module ... https://github.com/yaoweibin/nginx_tcp_proxy_module
      desc "reconf private_pub .. "
      task :reconf do
        template "thin_private_pub_yml.erb", "#{current_path}/config/thin_pp.yml"
        run "#{sudo} ln -sf #{current_path}/config/thin_pp.yml #{thin_path}/thin_#{app_name}_pp.yml"
      end
      
      
      desc "setup private_pub .. "
      task :setup do
        reconf
        template "nginx_private_pub.erb", "/tmp/nginx_tcp_conf"
        run "#{sudo} mv /tmp/nginx_tcp_conf #{tcp_enabled_path}/#{app_name}_private_pub.conf"
      end
      
      
      desc "write config/private_pup.yml"
      task :yml_file do
        template "private_pub_yml.erb", "#{current_path}/config/private_pub.yml"
      end
      
      
      desc "start private_pub server"
      task :start, roles: :app do
        if use_rvm
          run <<-CMD
            #{rvm_cmd} && 
            cd #{current_path} && 
            RAILS_ENV=production bundle exec rackup private_pub.ru -s thin -E production -p #{private_pub_port} -o #{server_ip} -D
          CMD
        else
          run "cd #{current_path} && RAILS_ENV=production bundle exec rackup private_pub.ru -s thin -E production -p #{private_pub_port} -o #{server_ip} -D"
        end
        # => run <<-CMD
        # =>     source '/usr/local/rvm/scripts/rvm' && 
        # =>     rvm use 1.9.3 && 
        # =>     cd #{current_path} && 
        # =>     RAILS_ENV=production bundle exec rackup private_pub.ru -s thin -E production -p #{private_pub_port} -o #{server_ip} -D
        # =>   CMD
      end
      
      
      desc "stop private_pub server"
      task :stop, roles: :app do
        run "if [ `lsof -t -i:#{private_pub_port}` ]; then #{sudo} kill $(#{sudo} lsof -t -i:#{private_pub_port}); fi"
      end
      
      
      desc "restart private_pub server"
      task :restart, roles: :app do
        stop
        start
      end
      
      
      before "thin:start", "private_pub:yml_file"
      after "thin:start", "private_pub:start"
      after "thin:stop", "private_pub:stop"
      after "nginx:setup", "private_pub:setup"
      after "thin:reconf", "private_pub:reconf"
      
      
    end
    
    # eof
    
  end
end