Top Level Namespace

Defined Under Namespace

Modules: Caploy, Database, Util

Instance Method Summary collapse

Instance Method Details

#close_sessionsObject



101
102
103
104
# File 'lib/caploy/recipes/nginx.rb', line 101

def close_sessions
  sessions.values.each { |session| session.close }
  sessions.clear
end

#config_file_path(config_file_name) ⇒ Object



42
43
44
45
46
47
48
49
50
# File 'lib/caploy/recipes/setup.rb', line 42

def config_file_path(config_file_name)
  config_file = "#{rails_root}/config/#{config_file_name}"
  if File.exists? config_file
    config_file
  else
    puts "\e[0;31mNo config file '#{config_file}'"
    nil
  end
end

#create_databaseObject



62
63
64
65
66
67
68
# File 'lib/caploy/recipes/setup.rb', line 62

def create_database
  create_sql = <<-SQL
      CREATE DATABASE #{db_name};
  SQL

  run "mysql --user=#{db_admin_user} --password=#{db_admin_password} --execute=\"#{create_sql}\""
end

#database_exits?Boolean

Returns:

  • (Boolean)


52
53
54
55
56
57
58
59
60
# File 'lib/caploy/recipes/setup.rb', line 52

def database_exits?
  exists = false

  run "mysql --user=#{db_admin_user} --password=#{db_admin_password} --execute=\"show databases;\"" do |channel, stream, data|
    exists = exists || data.include?(db_name)
  end

  exists
end

#process_exists?(pid_file) ⇒ Boolean

Check if process is running

Returns:

  • (Boolean)


9
10
11
# File 'lib/caploy/recipes/unicorn.rb', line 9

def process_exists?(pid_file)
  capture("ps -p $(cat #{pid_file}) ; true").strip.split("\n").size == 2
end

#remote_file_exists?(full_path) ⇒ Boolean

Check if remote file exists

Returns:

  • (Boolean)


3
4
5
# File 'lib/caploy/recipes/unicorn.rb', line 3

def remote_file_exists?(full_path)
  'true' == capture("if [ -e #{full_path} ]; then echo 'true'; fi").strip
end

#render_erb_template(template_path, vars = {}) ⇒ Object



3
4
5
6
7
8
# File 'lib/caploy/render.rb', line 3

def render_erb_template(template_path, vars={})
  raise "file '#{template_path}' not exists" unless File.exist? template_path

  template = File.open(template_path, 'r').read
  Erubis::Eruby.new(template).result(vars)
end

#setup_database_permissionsObject



70
71
72
73
74
75
76
# File 'lib/caploy/recipes/setup.rb', line 70

def setup_database_permissions
  grant_sql = <<-SQL
     GRANT ALL PRIVILEGES ON #{db_name}.* TO #{db_user_name}@localhost IDENTIFIED BY '#{db_user_password}';
  SQL

  run "mysql --user=#{db_admin_user} --password=#{db_admin_password} --execute=\"#{grant_sql}\""
end

#tail(path) ⇒ Object



18
19
20
21
22
# File 'lib/caploy/recipes/taillog.rb', line 18

def tail(path)
  with_verbosity(Logger::DEBUG) do
    execute "tail -f #{path}"
  end
end

#with_user(new_user, &block) ⇒ Object



92
93
94
95
96
97
98
99
# File 'lib/caploy/recipes/nginx.rb', line 92

def with_user(new_user, &block)
  old_user = user
  set :user, new_user
  close_sessions
  yield
  set :user, old_user
  close_sessions
end

#with_verbosity(output_verbosity) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/caploy/recipes/taillog.rb', line 8

def with_verbosity(output_verbosity)
  old_verbosity = SSHKit.config.output_verbosity
  begin
    SSHKit.config.output_verbosity = output_verbosity
    yield
  ensure
    SSHKit.config.output_verbosity = old_verbosity
  end
end