Module: Capistrano3::UnicornNginx::Helpers

Defined in:
lib/capistrano3/unicorn_nginx/helpers.rb

Instance Method Summary collapse

Instance Method Details

#deploy_userObject



30
31
32
# File 'lib/capistrano3/unicorn_nginx/helpers.rb', line 30

def deploy_user
  capture :id, '-un'
end

#file_exists?(path) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/capistrano3/unicorn_nginx/helpers.rb', line 26

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

#nginx_config_fileObject



38
39
40
41
42
43
44
# File 'lib/capistrano3/unicorn_nginx/helpers.rb', line 38

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

#os_is_ubuntu?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/capistrano3/unicorn_nginx/helpers.rb', line 34

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

#sudo_upload!(from, to) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/capistrano3/unicorn_nginx/helpers.rb', line 18

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

#template(template_name) ⇒ Object



6
7
8
# File 'lib/capistrano3/unicorn_nginx/helpers.rb', line 6

def template template_name
  StringIO.new(template_to_s(template_name))
end

#template_to_s(template_name) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/capistrano3/unicorn_nginx/helpers.rb', line 10

def template_to_s template_name
  config_file = "#{fetch(:templates_path)}/#{template_name}"
  unless File.exists?(config_file)
    config_file = File.join(File.dirname(__FILE__), "../../generators/capistrano3/unicorn_nginx/templates/#{template_name}")
  end
  ERB.new(File.read(config_file), nil, '-').result(binding)
end

#unicorn_config_pathObject



50
51
52
# File 'lib/capistrano3/unicorn_nginx/helpers.rb', line 50

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

#unicorn_error_log_fileObject



58
59
60
# File 'lib/capistrano3/unicorn_nginx/helpers.rb', line 58

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

#unicorn_log_fileObject



62
63
64
# File 'lib/capistrano3/unicorn_nginx/helpers.rb', line 62

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

#unicorn_pid_pathObject



54
55
56
# File 'lib/capistrano3/unicorn_nginx/helpers.rb', line 54

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

#unicorn_sock_pathObject



46
47
48
# File 'lib/capistrano3/unicorn_nginx/helpers.rb', line 46

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