Class: Neo4j::RakeTasks::ServerManager
- Inherits:
-
Object
- Object
- Neo4j::RakeTasks::ServerManager
show all
- Defined in:
- lib/neo4j/rake_tasks/server_manager.rb
Overview
Represents and manages a server installation at a specific path
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of ServerManager.
8
9
10
11
|
# File 'lib/neo4j/rake_tasks/server_manager.rb', line 8
def initialize(path)
@path = Pathname.new(path)
FileUtils.mkdir_p(@path)
end
|
Class Method Details
.change_password! ⇒ Object
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
# File 'lib/neo4j/rake_tasks/server_manager.rb', line 94
def self.change_password!
puts 'This will change the password for a Neo4j server'
address, old_password, new_password = prompt_for_address_and_passwords!
body = change_password_request(address, old_password, new_password)
if body['errors']
puts "An error was returned: #{body['errors'][0]['message']}"
else
puts 'Password changed successfully! Please update your app to use:'
puts 'username: neo4j'
puts "password: #{new_password}"
end
end
|
.new_for_os(path) ⇒ Object
170
171
172
|
# File 'lib/neo4j/rake_tasks/server_manager.rb', line 170
def self.new_for_os(path)
class_for_os.new(path)
end
|
Instance Method Details
#config_auth_enabeled!(enabled) ⇒ Object
113
114
115
116
117
118
|
# File 'lib/neo4j/rake_tasks/server_manager.rb', line 113
def config_auth_enabeled!(enabled)
value = enabled ? 'true' : 'false'
modify_config_file(
'dbms.security.authorization_enabled' => value,
'dbms.security.auth_enabled' => value)
end
|
#config_port!(port) ⇒ Object
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
# File 'lib/neo4j/rake_tasks/server_manager.rb', line 120
def config_port!(port)
puts "Config ports #{port} (HTTP) / #{port - 1} (HTTPS) / #{port - 2} (Bolt)"
if server_version_greater_than_or_equal_to?('3.1.0')
modify_config_file('dbms.connector.https.enabled' => false,
'dbms.connector.http.enabled' => true,
'dbms.connector.http.listen_address' => "localhost:#{port}",
'dbms.connector.https.listen_address' => "localhost:#{port - 1}",
'dbms.connector.bolt.listen_address' => "localhost:#{port - 2}")
elsif server_version_greater_than_or_equal_to?('3.0.0')
modify_config_file('dbms.connector.https.enabled' => false,
'dbms.connector.http.enabled' => true,
'dbms.connector.http.address' => "localhost:#{port}",
'dbms.connector.https.address' => "localhost:#{port - 1}",
'dbms.connector.bolt.address' => "localhost:#{port - 2}")
else
modify_config_file('org.neo4j.server.webserver.https.enabled' => false,
'org.neo4j.server.webserver.port' => port,
'org.neo4j.server.webserver.https.port' => port - 1)
end
end
|
#console ⇒ Object
48
49
50
|
# File 'lib/neo4j/rake_tasks/server_manager.rb', line 48
def console
system_or_fail(neo4j_command_path(:console))
end
|
#get_config_property(property) ⇒ Object
151
152
153
154
155
156
157
158
|
# File 'lib/neo4j/rake_tasks/server_manager.rb', line 151
def get_config_property(property)
lines = File.read(property_configuration_path).lines
config_lines = lines.grep(/^\s*[^#]/).map(&:strip).reject(&:empty?)
lines.find do |line|
line.match(/\s*#{property}=/)
end.split('=')[1]
end
|
#info ⇒ Object
62
63
64
65
66
|
# File 'lib/neo4j/rake_tasks/server_manager.rb', line 62
def info
validate_is_system_admin!
system_or_fail(neo4j_command_path(:info))
end
|
#install(edition_string) ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/neo4j/rake_tasks/server_manager.rb', line 15
def install(edition_string)
version = version_from_edition(edition_string)
if !neo4j_binary_path.exist?
archive_path = download_neo4j(version)
puts "Installing neo4j-#{version}"
(archive_path)
FileUtils.rm archive_path
end
config_port!(7474) if server_version_greater_than_or_equal_to?('3.0.0')
puts "Neo4j installed to: #{@path}"
end
|
#modify_config_contents(contents, properties) ⇒ Object
160
161
162
163
164
|
# File 'lib/neo4j/rake_tasks/server_manager.rb', line 160
def modify_config_contents(contents, properties)
properties.inject(contents) do |r, (property, value)|
r.gsub(/^\s*(#\s*)?#{property}\s*=\s*(.+)/, "#{property}=#{value}")
end
end
|
#modify_config_file(properties) ⇒ Object
145
146
147
148
149
|
# File 'lib/neo4j/rake_tasks/server_manager.rb', line 145
def modify_config_file(properties)
contents = File.read(property_configuration_path)
File.open(property_configuration_path, 'w') { |file| file << modify_config_contents(contents, properties) }
end
|
#print_constraints ⇒ Object
178
179
180
|
# File 'lib/neo4j/rake_tasks/server_manager.rb', line 178
def print_constraints
print_indexes_or_constraints(:constraint)
end
|
#print_indexes ⇒ Object
174
175
176
|
# File 'lib/neo4j/rake_tasks/server_manager.rb', line 174
def print_indexes
print_indexes_or_constraints(:index)
end
|
#reset ⇒ Object
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/neo4j/rake_tasks/server_manager.rb', line 74
def reset
validate_is_system_admin!
stop
paths = if server_version_greater_than_or_equal_to?('3.0.0')
['data/databases/graph.db/*', 'logs/*']
else
['data/graph.db/*', 'data/log/*']
end
paths.each do |path|
delete_path = @path.join(path)
puts "Deleting all files matching #{delete_path}"
FileUtils.rm_rf(Dir.glob(delete_path))
end
start
end
|
#restart ⇒ Object
68
69
70
71
72
|
# File 'lib/neo4j/rake_tasks/server_manager.rb', line 68
def restart
validate_is_system_admin!
system_or_fail(neo4j_command_path(:restart))
end
|
#shell ⇒ Object
52
53
54
55
56
57
58
59
60
|
# File 'lib/neo4j/rake_tasks/server_manager.rb', line 52
def shell
not_started = !pid_path.exist?
start if not_started
system_or_fail(neo4j_shell_binary_path.to_s)
stop if not_started
end
|
#start(wait = true) ⇒ Object
31
32
33
34
35
|
# File 'lib/neo4j/rake_tasks/server_manager.rb', line 31
def start(wait = true)
system_or_fail(neo4j_command_path(start_argument(wait))).tap do
@pid = pid_path.read.to_i
end
end
|
#stop(timeout = nil) ⇒ Object
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/neo4j/rake_tasks/server_manager.rb', line 37
def stop(timeout = nil)
validate_is_system_admin!
Timeout.timeout(timeout) do
system_or_fail(neo4j_command_path(:stop))
end
rescue Timeout::Error
puts 'Shutdown timeout reached, killing process...'
Process.kill('KILL', @pid) if @pid
end
|
#supports_auth? ⇒ Boolean
109
110
111
|
# File 'lib/neo4j/rake_tasks/server_manager.rb', line 109
def supports_auth?
Gem::Version.new(server_version) >= Gem::Version.new('2.2.0')
end
|