Sha256: 8533014c5186f91f753b0ffc617c602f0f75d51c2e1502009459551a72972432

Contents?: true

Size: 1.8 KB

Versions: 6

Compression:

Stored size: 1.8 KB

Contents

require 'capistrano'
require 'kapify/base'

Capistrano::Configuration.instance.load do
  set_default(:nginx_server_name) { Capistrano::CLI.ui.ask "Nginx server name: " }
  set_default(:nginx_use_ssl, false)
  set_default(:nginx_ssl_certificate) { "#{nginx_server_name}.crt" }
  set_default(:nginx_ssl_certificate_key) { "#{nginx_server_name}.key" }
  set_default(:nginx_ssl_certificate_local_path) {Capistrano::CLI.ui.ask "Local path to ssl certificate: "}
  set_default(:nginx_ssl_certificate_key_local_path) {Capistrano::CLI.ui.ask "Local path to ssl certificate key: "}

  namespace :kapify do
    namespace :nginx do
      desc "Setup nginx configuration for this application"
      task :setup, roles: :web do
        kapify_template("nginx", "nginx_conf.erb", "/tmp/#{application}")
        run "#{sudo} mv /tmp/#{application} /etc/nginx/sites-available/#{application}"
        run "#{sudo} ln -fs /etc/nginx/sites-available/#{application} /etc/nginx/sites-enabled/#{application}"

        if nginx_use_ssl
          put File.read(nginx_ssl_certificate_local_path), "/tmp/#{nginx_ssl_certificate}"
          put File.read(nginx_ssl_certificate_key_local_path), "/tmp/#{nginx_ssl_certificate_key}"

          run "#{sudo} mv /tmp/#{nginx_ssl_certificate} /etc/ssl/certs/#{nginx_ssl_certificate}"
          run "#{sudo} mv /tmp/#{nginx_ssl_certificate_key} /etc/ssl/private/#{nginx_ssl_certificate_key}"

          run "#{sudo} chown root:root /etc/ssl/certs/#{nginx_ssl_certificate}"
          run "#{sudo} chown root:root /etc/ssl/private/#{nginx_ssl_certificate_key}"
        end
      end

      after "deploy:setup", "kapify:nginx:setup"
      after "deploy:setup", "kapify:nginx:reload"

      desc "Reload nginx configuration"
      task :reload, roles: :web do
        run "#{sudo} /etc/init.d/nginx reload"
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
kapify-0.0.6 lib/kapify/nginx/configuration.rb
kapify-0.0.5 lib/kapify/nginx/configuration.rb
kapify-0.0.4 lib/kapify/nginx/configuration.rb
kapify-0.0.3 lib/kapify/nginx/configuration.rb
kapify-0.0.2 lib/kapify/nginx/configuration.rb
kapify-0.0.1 lib/kapify/nginx/configuration.rb