Class: Neo4j::RakeTasks::ServerManager

Inherits:
Object
  • Object
show all
Defined in:
lib/neo4j/rake_tasks/server_manager.rb

Overview

Represents and manages a server installation at a specific path

Direct Known Subclasses

StarnixServerManager, WindowsServerManager

Constant Summary collapse

BASE_INSTALL_DIR =
Pathname.new('db/neo4j')

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ ServerManager

Returns a new instance of ServerManager.



10
11
12
13
# File 'lib/neo4j/rake_tasks/server_manager.rb', line 10

def initialize(path)
  @path = Pathname.new(path)
  FileUtils.mkdir_p(@path)
end

Class Method Details

.change_password!Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/neo4j/rake_tasks/server_manager.rb', line 64

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

.class_for_osObject



107
108
109
# File 'lib/neo4j/rake_tasks/server_manager.rb', line 107

def self.class_for_os
  OS::Underlying.windows? ? WindowsServerManager : StarnixServerManager
end

.new_for_os(path) ⇒ Object



111
112
113
# File 'lib/neo4j/rake_tasks/server_manager.rb', line 111

def self.new_for_os(path)
  class_for_os.new(path)
end

Instance Method Details

#config_auth_enabeled!(enabled) ⇒ Object



79
80
81
82
83
84
# File 'lib/neo4j/rake_tasks/server_manager.rb', line 79

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



86
87
88
89
90
91
92
# File 'lib/neo4j/rake_tasks/server_manager.rb', line 86

def config_port!(port)
  puts "Config ports #{port} / #{port - 1}"

  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

#infoObject



41
42
43
44
45
# File 'lib/neo4j/rake_tasks/server_manager.rb', line 41

def info
  validate_is_system_admin!

  system_or_fail(neo4j_command_path(:info))
end

#install(edition_string) ⇒ Object

MAIN COMMANDS



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/neo4j/rake_tasks/server_manager.rb', line 17

def install(edition_string)
  version = version_from_edition(edition_string)
  puts "Installing neo4j-#{version}"

  return false if neo4j_binary_path.exist?

  archive_path = download_neo4j(version)
  extract!(archive_path)

  FileUtils.rm archive_path

  puts "Neo4j installed to: #{@path}"
end

#modify_config_file(properties) ⇒ Object

END MAIN COMMANDS



96
97
98
99
100
101
102
103
104
105
# File 'lib/neo4j/rake_tasks/server_manager.rb', line 96

def modify_config_file(properties)
  contents = File.read(property_configuration_path)

  File.open(property_configuration_path, 'w') do |file|
    result = properties.inject(contents) do |r, (property, value)|
      r.gsub(/#{property}\s*=\s*(\w+)/, "#{property}=#{value}")
    end
    file << result
  end
end

#resetObject



53
54
55
56
57
58
59
60
61
62
# File 'lib/neo4j/rake_tasks/server_manager.rb', line 53

def reset
  validate_is_system_admin!

  stop

  FileUtils.rm_rf(@path.join('data/graph.db/*'))
  FileUtils.rm_rf(@path.join('data/log/*'))

  start
end

#restartObject



47
48
49
50
51
# File 'lib/neo4j/rake_tasks/server_manager.rb', line 47

def restart
  validate_is_system_admin!

  system_or_fail(neo4j_command_path(:restart))
end

#start(wait = true) ⇒ Object



31
32
33
# File 'lib/neo4j/rake_tasks/server_manager.rb', line 31

def start(wait = true)
  system_or_fail(neo4j_command_path(start_argument(wait)))
end

#stopObject



35
36
37
38
39
# File 'lib/neo4j/rake_tasks/server_manager.rb', line 35

def stop
  validate_is_system_admin!

  system_or_fail(neo4j_command_path(:stop))
end