Sha256: d7388b4f3ba34af09bce78f5e62a1ff624ca55cec77670682e3c5f2b17b571f9

Contents?: true

Size: 1.61 KB

Versions: 5

Compression:

Stored size: 1.61 KB

Contents

require 'erb'

module Capistrano
  module SimpleUnicorn
    module Helpers
      def template template_name
        StringIO.new(template_to_s(template_name))
      end

      def template_to_s template_name
        config_file = File.join(File.dirname(__FILE__), "../../generators/capistrano/simple_unicorn/templates/#{template_name}")
        ERB.new(File.read(config_file), nil, '-').result(binding)
      end

      def sudo_upload! from, to
        filename = File.basename(to)
        to_dir = File.dirname(to)
        tmp_file = "/tmp/#{filename}"
        upload! from, tmp_file
        sudo :mv, tmp_file, to_dir
      end

      def file_exists? path
        test "[ -e #{path} ]"
      end

      def deploy_user
        capture :id, '-un'
      end

      def os_is_ubuntu?
        capture(:cat, "/etc/*-release").include? "ubuntu"
      end

      def nginx_config_file
        if os_is_ubuntu?
          "/etc/nginx/sites-available/#{fetch(:nginx_config_name)}.conf"
        else
          "/etc/nginx/conf.d/#{fetch(:nginx_config_name)}.conf"
        end
      end

      def unicorn_initd_file
        "/etc/init.d/#{fetch(:unicorn_service)}"
      end

      def unicorn_sock_path
        shared_path.join("tmp", "unicorn.sock")
      end

      def unicorn_config_path
        shared_path.join("config", "unicorn.rb")
      end

      def unicorn_pid_path
        shared_path.join("tmp", "pids", "unicorn.pid")
      end

      def unicorn_error_log_file
        shared_path.join("log", "unicorn.stderr.log")
      end

      def unicorn_log_file
        shared_path.join("log", "unicorn.stdout.log")
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
capistrano-simple-unicorn-1.1.4 lib/capistrano/simple_unicorn/helpers.rb
capistrano-simple-unicorn-1.1.3 lib/capistrano/simple_unicorn/helpers.rb
capistrano-simple-unicorn-1.1.2 lib/capistrano/simple_unicorn/helpers.rb
capistrano-simple-unicorn-1.1.1 lib/capistrano/simple_unicorn/helpers.rb
capistrano-simple-unicorn-1.1.0 lib/capistrano/simple_unicorn/helpers.rb