raystool 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/__rays_exec.rb +31 -0
- data/bin/__rays_init +79 -0
- data/lib/rays/config/backup.rb +42 -0
- data/lib/rays/config/configuration.rb +376 -0
- data/lib/rays/config/environment.rb +73 -0
- data/lib/rays/config/templates/global/global.yml +3 -0
- data/lib/rays/config/templates/global/scripts/rays +187 -0
- data/lib/rays/config/templates/project/.rays +0 -0
- data/lib/rays/config/templates/project/config/environment.yml +68 -0
- data/lib/rays/config/templates/project/config/project.yml +4 -0
- data/lib/rays/core.rb +128 -0
- data/lib/rays/exceptions/rays_exception.rb +25 -0
- data/lib/rays/interface/commander.rb +394 -0
- data/lib/rays/interface/controller.rb +365 -0
- data/lib/rays/loaders/highline.rb +24 -0
- data/lib/rays/loaders/logging.rb +60 -0
- data/lib/rays/models/appmodule/base.rb +185 -0
- data/lib/rays/models/appmodule/content.rb +35 -0
- data/lib/rays/models/appmodule/ext.rb +36 -0
- data/lib/rays/models/appmodule/hook.rb +36 -0
- data/lib/rays/models/appmodule/layout.rb +36 -0
- data/lib/rays/models/appmodule/manager.rb +130 -0
- data/lib/rays/models/appmodule/portlet.rb +36 -0
- data/lib/rays/models/appmodule/servicebuilder.rb +36 -0
- data/lib/rays/models/appmodule/theme.rb +36 -0
- data/lib/rays/models/project.rb +116 -0
- data/lib/rays/servers/base.rb +70 -0
- data/lib/rays/servers/database.rb +73 -0
- data/lib/rays/servers/liferay.rb +64 -0
- data/lib/rays/servers/solr.rb +111 -0
- data/lib/rays/services/application_service.rb +116 -0
- data/lib/rays/services/backup_service.rb +94 -0
- data/lib/rays/services/database.rb +59 -0
- data/lib/rays/services/remote.rb +75 -0
- data/lib/rays/services/scm.rb +92 -0
- data/lib/rays/services/sync.rb +90 -0
- data/lib/rays/utils/common_utils.rb +153 -0
- data/lib/rays/utils/file_utils.rb +118 -0
- data/lib/rays/utils/network_utils.rb +50 -0
- data/lib/rays/workers/base.rb +134 -0
- data/lib/rays/workers/builder.rb +63 -0
- data/lib/rays/workers/cleaner.rb +42 -0
- data/lib/rays/workers/deployer.rb +92 -0
- data/lib/rays/workers/generator.rb +49 -0
- metadata +175 -0
@@ -0,0 +1,111 @@
|
|
1
|
+
=begin
|
2
|
+
Copyright (c) 2012 Dmitri Carpov
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
a copy of this software and associated documentation files (the
|
6
|
+
"Software"), to deal in the Software without restriction, including
|
7
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
=end
|
23
|
+
|
24
|
+
module Rays
|
25
|
+
module Server
|
26
|
+
|
27
|
+
class SolrServer < BaseServer
|
28
|
+
attr_reader :solr_instance
|
29
|
+
|
30
|
+
def initialize(name, host, remote, java_home, java_bin, port, url, application_service)
|
31
|
+
super(name, host, remote, java_home, java_bin)
|
32
|
+
@port = port
|
33
|
+
@url = url
|
34
|
+
@solr_instance = RSolr.connect(:url => solr_url)
|
35
|
+
@service = application_service
|
36
|
+
end
|
37
|
+
|
38
|
+
def port
|
39
|
+
raise RaysException.new(missing_environment_option('SOLR server', 'port')) if @port.nil?
|
40
|
+
@port
|
41
|
+
end
|
42
|
+
|
43
|
+
def url
|
44
|
+
raise RaysException.new(missing_environment_option('SOLR server', 'instance')) if @url.nil?
|
45
|
+
@url
|
46
|
+
end
|
47
|
+
|
48
|
+
def service
|
49
|
+
raise RaysException.new(missing_environment_option('SOLR service', 'service')) if @service.nil?
|
50
|
+
@service
|
51
|
+
end
|
52
|
+
|
53
|
+
def alive?
|
54
|
+
begin
|
55
|
+
@solr_instance.get('select', :params => { :q => '*:*', :limit => 1})
|
56
|
+
return true
|
57
|
+
rescue
|
58
|
+
return false
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def clean_all
|
63
|
+
solr_transaction do
|
64
|
+
@solr_instance.delete_by_query('*:*')
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
def solr_transaction
|
70
|
+
$log.info("Connecting to the solr server ...")
|
71
|
+
unless alive?
|
72
|
+
$log.error("Cannot connect to the solr server.")
|
73
|
+
return
|
74
|
+
end
|
75
|
+
begin
|
76
|
+
log_block("execute solr query") do
|
77
|
+
yield
|
78
|
+
@solr_instance.commit
|
79
|
+
end
|
80
|
+
rescue Errno::ECONNREFUSED => e
|
81
|
+
rollback
|
82
|
+
$log.error("Cannot connect to the solr server. URL: " + solr_url)
|
83
|
+
$log.debug("Cause: #{e.message}.\tBacktrace:\r\n#{e.backtrace.join("\r\n")}")
|
84
|
+
rescue RSolr::Error::Http => e
|
85
|
+
rollback
|
86
|
+
$log.error("Bad solr request. URL: " + solr_url)
|
87
|
+
$log.debug("Cause: #{e.message}.\tBacktrace:\r\n#{e.backtrace.join("\r\n")}")
|
88
|
+
rescue => e
|
89
|
+
rollback
|
90
|
+
$log.error("Unknown solr error.")
|
91
|
+
$log.debug("Cause: #{e.message}.\tBacktrace:\r\n#{e.backtrace.join("\r\n")}")
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def solr_url
|
96
|
+
url_string = "http://#{host}"
|
97
|
+
url_string << ":#{port}"
|
98
|
+
url_string << "/#{url}"
|
99
|
+
url_string
|
100
|
+
end
|
101
|
+
|
102
|
+
def rollback
|
103
|
+
begin
|
104
|
+
@solr_instance.rollback
|
105
|
+
rescue
|
106
|
+
# stub
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
=begin
|
2
|
+
Copyright (c) 2012 Dmitri Carpov
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
a copy of this software and associated documentation files (the
|
6
|
+
"Software"), to deal in the Software without restriction, including
|
7
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
=end
|
23
|
+
|
24
|
+
module Rays
|
25
|
+
module Service
|
26
|
+
class ApplicationService
|
27
|
+
|
28
|
+
def initialize(name, host, port, start_script, debug_script, stop_script, log_file, remote)
|
29
|
+
@name = name
|
30
|
+
@host = host
|
31
|
+
@port = port
|
32
|
+
@start_script = start_script
|
33
|
+
@debug_script = debug_script
|
34
|
+
@stop_script = stop_script
|
35
|
+
@log_file = log_file
|
36
|
+
@remote = remote
|
37
|
+
end
|
38
|
+
|
39
|
+
def host
|
40
|
+
raise RaysException.new(missing_environment_option('Service', 'host')) if @host.nil?
|
41
|
+
@host
|
42
|
+
end
|
43
|
+
|
44
|
+
def port
|
45
|
+
raise RaysException.new(missing_environment_option('Service', 'port')) if @port.nil?
|
46
|
+
@port
|
47
|
+
end
|
48
|
+
|
49
|
+
# Start service
|
50
|
+
def start
|
51
|
+
unless alive?
|
52
|
+
execute @start_script
|
53
|
+
else
|
54
|
+
raise RaysException.new('service is already running')
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# Debug service
|
59
|
+
def debug
|
60
|
+
if @debug_script.nil?
|
61
|
+
$log.warn('debug is disabled for this server')
|
62
|
+
return
|
63
|
+
end
|
64
|
+
unless alive?
|
65
|
+
execute @debug_script
|
66
|
+
else
|
67
|
+
raise RaysException.new('service is already running')
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
# Stop service
|
72
|
+
def stop
|
73
|
+
if alive?
|
74
|
+
execute @stop_script
|
75
|
+
else
|
76
|
+
raise RaysException.new('service is not running')
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
# Show logs (live)
|
81
|
+
def log
|
82
|
+
if remote?
|
83
|
+
remote.exec(command)
|
84
|
+
else
|
85
|
+
Thread.new do
|
86
|
+
exec("tail -f #{@log_file}")
|
87
|
+
end
|
88
|
+
end
|
89
|
+
$log.info("Following logs of #{@name} service on #{@host}.\nUse ctrl+c to interrupt.")
|
90
|
+
end
|
91
|
+
|
92
|
+
# Is the service resides on a remote service?
|
93
|
+
# returns true if the service is on a remote server and false if the service is local.
|
94
|
+
def remote?
|
95
|
+
!@remote.nil?
|
96
|
+
end
|
97
|
+
|
98
|
+
# Is the service running?
|
99
|
+
# Returns true is the service is running or false otherwise
|
100
|
+
def alive?
|
101
|
+
Utils::NetworkUtils.port_open?(@host, @port)
|
102
|
+
end
|
103
|
+
|
104
|
+
private
|
105
|
+
|
106
|
+
# Executing command on local or a remote server depending on the service configuration.
|
107
|
+
def execute(command)
|
108
|
+
if remote?
|
109
|
+
remote.exec(command)
|
110
|
+
else
|
111
|
+
rays_exec(command)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
=begin
|
2
|
+
Copyright (c) 2012 Dmitri Carpov
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
a copy of this software and associated documentation files (the
|
6
|
+
"Software"), to deal in the Software without restriction, including
|
7
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
=end
|
23
|
+
|
24
|
+
module Rays
|
25
|
+
module Service
|
26
|
+
class Backup
|
27
|
+
|
28
|
+
def initialize(environment = $rays_config.environment)
|
29
|
+
@environment = environment
|
30
|
+
@backup_directory = create_backup_directory
|
31
|
+
@dump_file_name = 'db.dump'
|
32
|
+
@package_file = "archive-#{Time.now.to_i.to_s}.tar"
|
33
|
+
end
|
34
|
+
|
35
|
+
def backup
|
36
|
+
package = ''
|
37
|
+
|
38
|
+
service_safe(@environment.backup.stop_server) do
|
39
|
+
database
|
40
|
+
data
|
41
|
+
package = pack
|
42
|
+
end
|
43
|
+
|
44
|
+
package
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def create_backup_directory
|
50
|
+
base_directory = @environment.backup.directory
|
51
|
+
# remove until multiple backups support
|
52
|
+
execute("rm -rf #{base_directory}")
|
53
|
+
execute("mkdir #{base_directory}")
|
54
|
+
backup_directory = File.join(base_directory, Time.now.to_i.to_s)
|
55
|
+
execute("mkdir #{backup_directory}")
|
56
|
+
backup_directory
|
57
|
+
end
|
58
|
+
|
59
|
+
def execute(command)
|
60
|
+
if @environment.liferay.remote?
|
61
|
+
@environment.liferay.remote.exec(command)
|
62
|
+
else
|
63
|
+
rays_exec(command)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
#
|
68
|
+
# Database backup
|
69
|
+
#
|
70
|
+
def database
|
71
|
+
dump_file = File.join(@backup_directory, 'db.dump')
|
72
|
+
task("creating database backup", "done", "failed") do
|
73
|
+
execute(@environment.database.instance.export_command(@environment.database.db_name, dump_file))
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
#
|
78
|
+
# Data backup
|
79
|
+
#
|
80
|
+
def data
|
81
|
+
task("creating data backup", "done", "failed") do
|
82
|
+
execute("cp -r #{@environment.liferay.data_directory} #{@backup_directory}")
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def pack
|
87
|
+
task("creating backup archive", "done", "failed") do
|
88
|
+
execute("cd #{@backup_directory} && tar -cf #{@package_file} * && mv #{@package_file} .. && cd .. && rm -rf #{@backup_directory}")
|
89
|
+
end
|
90
|
+
"#{@environment.backup.directory}/#{@package_file}"
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
=begin
|
2
|
+
Copyright (c) 2012 Dmitri Carpov
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
a copy of this software and associated documentation files (the
|
6
|
+
"Software"), to deal in the Software without restriction, including
|
7
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
=end
|
23
|
+
|
24
|
+
module Rays
|
25
|
+
module Database
|
26
|
+
class MySQL
|
27
|
+
def initialize(host, port, username, password, db_name=nil)
|
28
|
+
@host = host
|
29
|
+
@port = port
|
30
|
+
@username = username
|
31
|
+
@password = password
|
32
|
+
@db_name = db_name
|
33
|
+
end
|
34
|
+
|
35
|
+
def export_command(db_name, dump_file)
|
36
|
+
"mysqldump -u#{@username} #{pass_param} -h#{@host} --port=#{@port} #{db_name} > #{dump_file}"
|
37
|
+
end
|
38
|
+
|
39
|
+
def import_command(db_name, dump_file)
|
40
|
+
"mysql -u#{@username} #{pass_param} #{db_name} < #{dump_file}"
|
41
|
+
end
|
42
|
+
|
43
|
+
def create_database_command(db_name)
|
44
|
+
"mysqladmin -u#{@username} #{pass_param} create #{db_name}"
|
45
|
+
end
|
46
|
+
|
47
|
+
def delete_database_command(db_name)
|
48
|
+
"mysqladmin -u#{@username} #{pass_param} -f drop #{db_name}"
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
def pass_param
|
53
|
+
password = ''
|
54
|
+
password = "-p#{@password}" unless @password.nil? or @password.empty?
|
55
|
+
password
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
=begin
|
2
|
+
Copyright (c) 2012 Dmitri Carpov
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
a copy of this software and associated documentation files (the
|
6
|
+
"Software"), to deal in the Software without restriction, including
|
7
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
=end
|
23
|
+
|
24
|
+
module Rays
|
25
|
+
module Service
|
26
|
+
module Remote
|
27
|
+
class SSH
|
28
|
+
|
29
|
+
def initialize(host, port, user)
|
30
|
+
@host = host
|
31
|
+
@port = port # TODO: not used for now.
|
32
|
+
@user = user
|
33
|
+
defaults
|
34
|
+
end
|
35
|
+
|
36
|
+
def host
|
37
|
+
raise RaysException.new(missing_environment_option('ssh', 'host')) if @host.nil?
|
38
|
+
@host
|
39
|
+
end
|
40
|
+
|
41
|
+
def port
|
42
|
+
raise RaysException.new(missing_environment_option('ssh', 'port')) if @port.nil?
|
43
|
+
@port
|
44
|
+
end
|
45
|
+
|
46
|
+
def user
|
47
|
+
raise RaysException.new(missing_environment_option('ssh', 'user')) if @user.nil?
|
48
|
+
@user
|
49
|
+
end
|
50
|
+
|
51
|
+
def exec(command)
|
52
|
+
response = ""
|
53
|
+
Net::SSH.start("#{host}", "#{user}") do |ssh|
|
54
|
+
response = ssh.exec!(command)
|
55
|
+
$log.debug(response)
|
56
|
+
end
|
57
|
+
response
|
58
|
+
end
|
59
|
+
|
60
|
+
def copy_to(local_file, remote_file)
|
61
|
+
rays_exec("#{$rays_config.scp} #{local_file} #{user}@#{host}:#{remote_file}")
|
62
|
+
end
|
63
|
+
|
64
|
+
def copy_from(remote_file, local_file)
|
65
|
+
rays_exec("#{$rays_config.scp} #{user}@#{host}:#{remote_file} #{local_file}")
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
def defaults
|
70
|
+
@port ||= 22
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
=begin
|
2
|
+
Copyright (c) 2012 Dmitri Carpov
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
a copy of this software and associated documentation files (the
|
6
|
+
"Software"), to deal in the Software without restriction, including
|
7
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
=end
|
23
|
+
|
24
|
+
#
|
25
|
+
# NOT SUPPORTED
|
26
|
+
#
|
27
|
+
module Rays
|
28
|
+
|
29
|
+
class SCM
|
30
|
+
def initialize(path, username, password, type)
|
31
|
+
raise RaysException "unknown SCM type." if type.nil?
|
32
|
+
if type.eql? "svn"
|
33
|
+
@instance = SVN.new path, username, password, $rays_config.project_root
|
34
|
+
else
|
35
|
+
@instance = Git.new path, Rays::Utils::FileUtils.project_root
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def update
|
40
|
+
@instance.update
|
41
|
+
end
|
42
|
+
|
43
|
+
def checkout
|
44
|
+
@instance.checkout
|
45
|
+
end
|
46
|
+
|
47
|
+
def clean_checkout
|
48
|
+
@instance.checkout "/tmp/#{Project.instance.name}"
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
class Git
|
56
|
+
def initialize path, source_dir
|
57
|
+
@path = path
|
58
|
+
@source_dir = source_dir
|
59
|
+
end
|
60
|
+
|
61
|
+
def checkout dir = nil
|
62
|
+
dir ||= @source_dir
|
63
|
+
rays_exec "git clone #{@path} #{dir}"
|
64
|
+
@source_dir = dir
|
65
|
+
end
|
66
|
+
|
67
|
+
def update
|
68
|
+
in_directory(@source_dir) do
|
69
|
+
rays_exec "git pull origin"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
class SVN
|
75
|
+
def initialize path, username, password, source_dir
|
76
|
+
@path = path
|
77
|
+
@username = username
|
78
|
+
@password = password
|
79
|
+
@source_dir = source_dir
|
80
|
+
end
|
81
|
+
|
82
|
+
def checkout(dir = nil)
|
83
|
+
dir ||= @source_dir
|
84
|
+
rays_exec("svn co #{@path} --username=#{@username} --password=#{@password} #{dir}")
|
85
|
+
@source_dir = dir
|
86
|
+
end
|
87
|
+
|
88
|
+
def update
|
89
|
+
system_exec("cd #{@source_dir} && svn up", $rays_config.debug)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
=begin
|
2
|
+
Copyright (c) 2012 Dmitri Carpov
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
a copy of this software and associated documentation files (the
|
6
|
+
"Software"), to deal in the Software without restriction, including
|
7
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
=end
|
23
|
+
|
24
|
+
module Rays
|
25
|
+
module Service
|
26
|
+
class Sync
|
27
|
+
|
28
|
+
def initialize
|
29
|
+
@import_directory = '/tmp/rays_import'
|
30
|
+
@dump_file_name = 'db.dump'
|
31
|
+
@data_dir_name = 'data'
|
32
|
+
recreate_import_directory
|
33
|
+
@import_package = File.join(@import_directory, 'import_package.tar')
|
34
|
+
end
|
35
|
+
|
36
|
+
def sync(environment = $rays_config.environment)
|
37
|
+
backup = Backup.new(environment)
|
38
|
+
package_location = backup.backup
|
39
|
+
task("copy backup file from #{environment.name}", 'done', 'failed') do
|
40
|
+
environment.liferay.remote.copy_from(package_location, @import_package)
|
41
|
+
end
|
42
|
+
task('unpack backup file', 'done', 'failed') do
|
43
|
+
in_directory(@import_directory) do
|
44
|
+
rays_exec("tar -xf #{@import_package}")
|
45
|
+
File.delete(@import_package)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
task('check backup integrity', 'backup looks OK', 'failed') do
|
49
|
+
in_directory(@import_directory) do
|
50
|
+
raise RaysException.new('Cannot find dump.db') unless File.exists?(@dump_file_name)
|
51
|
+
raise RaysException.new('Cannot find data folder') unless Dir.exists?(@data_dir_name)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
in_local_environment do
|
56
|
+
service_safe do
|
57
|
+
# create local backup
|
58
|
+
Backup.new.backup
|
59
|
+
in_directory(@import_directory) do
|
60
|
+
db = $rays_config.environment.database.instance
|
61
|
+
db_name = $rays_config.environment.database.db_name
|
62
|
+
begin
|
63
|
+
rays_exec(db.delete_database_command(db_name))
|
64
|
+
rescue => ex
|
65
|
+
$log.warn("Cannot drop database #{db_name}")
|
66
|
+
end
|
67
|
+
task("re-create database #{db_name}", 'done', 'failed') do
|
68
|
+
rays_exec(db.create_database_command(db_name))
|
69
|
+
end
|
70
|
+
task('import database dump', 'done', 'failed') do
|
71
|
+
rays_exec(db.import_command(db_name, File.join(@import_directory, @dump_file_name)))
|
72
|
+
end
|
73
|
+
task('re-create data folder', 'done', 'failed') do
|
74
|
+
FileUtils.rm_rf($rays_config.environment.liferay.data_directory)
|
75
|
+
FileUtils.cp_r(@data_dir_name, $rays_config.environment.liferay.data_directory)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
private
|
83
|
+
def recreate_import_directory
|
84
|
+
FileUtils.rm_rf(@import_directory) if Dir.exist?(@import_directory)
|
85
|
+
FileUtils.mkdir_p(@import_directory)
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|