Class: Capricorn::Actors::PleskActor

Inherits:
Capricorn::Actor show all
Defined in:
lib/capricorn/actors/plesk_actor.rb

Defined Under Namespace

Modules: Config, Helper

Instance Attribute Summary

Attributes inherited from Capricorn::Actor

#satellite, #system

Instance Method Summary collapse

Methods inherited from Capricorn::Actor

#initialize

Methods included from Capricorn::Actor::Actions

included, #run_callbacks!, #run_callbacks_in_fase!

Constructor Details

This class inherits a constructor from Capricorn::Actor

Instance Method Details

#create_clientObject



14
15
16
17
18
19
20
21
# File 'lib/capricorn/actors/plesk_actor.rb', line 14

def create_client
  # only do this if this is needed
  if false
    unless system.client?(system.plesk_client)
      system.create_client(system.plesk_client, system.plesk_client, 'mypwd')
    end
  end
end

#create_databaseObject



69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/capricorn/actors/plesk_actor.rb', line 69

def create_database
  db_name = database_name_for(satellite)
  db_user = db_name[0,13]
  db_pswd = (rand(1_000_000_000) + 10_000).to_s
  
  create_database_for(satellite, :d, db_name, db_user, db_pswd)
  create_database_for(satellite, :t, db_name, db_user, db_pswd)
  create_database_for(satellite, :p, db_name, db_user, db_pswd)
  
  system.as_user(system.web_user, system.web_group) do
    db_file = File.join(system.satellite_root, 'config', 'database.yml')
    write_database_config(db_file, db_name, db_user, db_pswd)
  end
end

#create_database_for(satellite, environment, db_name, db_user, db_pswd) ⇒ Object



127
128
129
130
131
# File 'lib/capricorn/actors/plesk_actor.rb', line 127

def create_database_for(satellite, environment, db_name, db_user, db_pswd)
  db_name = "#{db_name}_#{environment}"
  db_user = "#{db_user}_u#{environment}"
  system.create_database(satellite.basedomain, db_name, db_user, db_pswd)
end

#create_domainObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/capricorn/actors/plesk_actor.rb', line 23

def create_domain
  unless system.domain?(satellite.basedomain)
    system.create_domain(system.plesk_client, satellite.basedomain,
      system.web_user[0,20], (rand(1_000_000_000) + 10_000).to_s)
  else
    httpdocs_path = "/var/www/vhosts/#{satellite.basedomain}/httpdocs"
    system.set_satellite_option(:web_user,
      system.get_user_name(File.stat(httpdocs_path).uid))
  end
    
  if satellite.subdomain? and !system.subdomain?(satellite.basedomain, satellite.subdomain)
    system.create_subdomain(satellite.basedomain, satellite.subdomain)
  end
  
  FileUtils.mkdir_p(system.satellite_root)
  FileUtils.mkdir_p(system.shared_root)
  FileUtils.chown_R(system.web_user, system.web_group, system.satellite_root)
  FileUtils.chown_R(system.web_user, system.web_group, system.shared_root)
end

#database_name_for(satellite) ⇒ Object



123
124
125
# File 'lib/capricorn/actors/plesk_actor.rb', line 123

def database_name_for(satellite)
  satellite.domain.downcase.gsub(/[^a-z]+/, '_')[0,63]
end

#drop_databasesObject



84
85
86
87
88
89
90
# File 'lib/capricorn/actors/plesk_actor.rb', line 84

def drop_databases
  db_name = satellite.domain.downcase.gsub(/[^a-z]+/, '_')[0,63]
  
  system.drop_database("#{db_name}_d")
  system.drop_database("#{db_name}_t")
  system.drop_database("#{db_name}_p")
end


43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/capricorn/actors/plesk_actor.rb', line 43

def link_htdocs
  httpdocs_path = File.join(File.dirname(system.satellite_root), 'httpdocs')
  FileUtils.rm_rf(httpdocs_path)
  FileUtils.ln_s(system.satellite_root, httpdocs_path)
  FileUtils.chown_R(system.web_user, system.web_group, httpdocs_path)
  
  File.open(File.join(system.satellite_root, '../conf/vhost.conf'), 'w+') do |f|
    f.write %{DocumentRoot #{httpdocs_path}/public
<Directory  "#{httpdocs_path}/public">
  Options All
  AllowOverride All
  Order allow,deny
  Allow from all
</Directory>
}
  end
end

#reload_subdomainsObject



61
62
63
# File 'lib/capricorn/actors/plesk_actor.rb', line 61

def reload_subdomains
  system.run("#{system.plesk_websrvmng_bin} --reconfigure-vhost --vhost-name=#{satellite.basedomain}")
end

#restart_apacheObject



65
66
67
# File 'lib/capricorn/actors/plesk_actor.rb', line 65

def restart_apache
  system.run("#{system.plesk_httpd_bin} restart")
end

#write_database_config(db_file, db_name, db_user, db_pswd) ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/capricorn/actors/plesk_actor.rb', line 92

def write_database_config(db_file, db_name, db_user, db_pswd)
  File.open(db_file, 'w+') { |f| f.write(%{
development:
  adapter: mysql
  database: #{db_name}_d
  username: #{db_user}_ud
  password: #{db_pswd}
  host: localhost
  encoding: utf8
  socket: /var/lib/mysql/mysql.sock

test:
  adapter: mysql
  database: #{db_name}_t
  username: #{db_user}_ut
  password: #{db_pswd}
  host: localhost
  encoding: utf8
  socket: /var/lib/mysql/mysql.sock

production:
  adapter: mysql
  database: #{db_name}_p
  username: #{db_user}_up
  password: #{db_pswd}
  host: localhost
  encoding: utf8
  socket: /var/lib/mysql/mysql.sock
}) }
end