Skip to content

Commit

Permalink
ugly attempt at a multi-os installer
Browse files Browse the repository at this point in the history
  • Loading branch information
maxdemarzi committed Nov 2, 2011
1 parent 764a146 commit 066ed4f
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 10 deletions.
3 changes: 3 additions & 0 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ It will add the following rake tasks to your project:
rake neo4j:restart # Restart Neo4j
rake neo4j:reset_yes_i_am_sure # Wipe your Neo4j Database

Windows users will need to run in a command prompt with Administrative Privileges
in order to install Neo4j as a Service.

=== Documentation

@neo = Neography::Rest.new({:protocol => 'http://',
Expand Down
2 changes: 2 additions & 0 deletions lib/neography.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ def find_and_require_user_defined_code
require 'json'
require 'logger'
require 'ostruct'
require 'os'
require 'zip/zipfilesystem'

require 'neography/config'
require 'neography/rest'
Expand Down
99 changes: 89 additions & 10 deletions lib/neography/tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,113 @@
desc "Install Neo4j"
task :install do
puts 'Installing Neo4j...'
%x[wget http://dist.neo4j.org/neo4j-community-1.5.M02-unix.tar.gz]
%x[tar -xvzf neo4j-community-1.5.M02-unix.tar.gz]
%x[mv neo4j-community-1.5.M02 neo4j]
%x[rm neo4j-community-1.5.M02-unix.tar.gz]
puts "Neo4j Installed in to neo4j directory."

if OS::Underlying.windows?
# Download Neo4j
unless File.exist?('neo4j.zip')
df = File.open('neo4j.zip', 'wb')
begin
df << HTTParty.get("http://dist.neo4j.org/neo4j-community-1.5.M02-windows.zip")
ensure
df.close()
end
end

# Extract and move to neo4j directory
unless File.exist?('neo4j')
Zip::ZipFile.open('neo4j.zip') do |zip_file|
zip_file.each do |f|
f_path=File.join(".", f.name)
FileUtils.mkdir_p(File.dirname(f_path))
begin
zip_file.extract(f, f_path) unless File.exist?(f_path)
rescue
puts f.name + " failed to extract."
end
end
end
FileUtils.mv "neo4j-community-1.5.M02", "neo4j"
end

# Install if running with Admin Privileges
if %x[reg query "HKU\\S-1-5-19"].size > 0
%x[neo4j/bin/neo4j install]
puts "Neo4j Installed as a service."
end

else
%x[wget http://dist.neo4j.org/neo4j-community-1.5.M02-unix.tar.gz]
%x[tar -xvzf neo4j-community-1.5.M02-unix.tar.gz]
%x[mv neo4j-community-1.5.M02 neo4j]
%x[rm neo4j-community-1.5.M02-unix.tar.gz]
puts "Neo4j Installed in to neo4j directory."
end
puts "Type 'rake neo4j:start' to start it"
end

desc "Start the Neo4j Server"
task :start do
puts "Starting Neo4j..."
%x[neo4j/bin/neo4j start]
if OS::Underlying.windows?
if %x[reg query "HKU\\S-1-5-19"].size > 0
%x[neo4j/bin/Neo4j.bat start] #start service
else
puts "Starting Neo4j directly, not as a service."
%x[neo4j/bin/Neo4j.bat]
end
else
%x[neo4j/bin/neo4j start]
end
end

desc "Stop the Neo4j Server"
task :stop do
puts "Stopping Neo4j..."
%x[neo4j/bin/neo4j stop]
if OS::Underlying.windows?
if %x[reg query "HKU\\S-1-5-19"].size > 0
%x[neo4j/bin/Neo4j.bat stop] #stop service
else
puts "You do not have administrative rights to stop the Neo4j Service"
end
else
%x[neo4j/bin/neo4j stop]
end
end

desc "Restart the Neo4j Server"
task :restart do
puts "Restarting Neo4j..."
%x[neo4j/bin/neo4j restart]
if OS::Underlying.windows?
if %x[reg query "HKU\\S-1-5-19"].size > 0
%x[neo4j/bin/Neo4j.bat restart]
else
puts "You do not have administrative rights to stop the Neo4j Service"
end
else
%x[neo4j/bin/neo4j restart]
end
end

desc "Reset the Neo4j Server"
task :reset_yes_i_am_sure do
# Stop the server
# Stop the server
if OS::Underlying.windows?
if %x[reg query "HKU\\S-1-5-19"].size > 0
%x[neo4j/bin/Neo4j.bat stop]

# Reset the database
FileUtils.rm_rf("neo4j/data/graph.db")
FileUtils.mkdir("neo4j/data/graph.db")

# Remove log files
FileUtils.rm_rf("neo4j/data/log")
FileUtils.mkdir("neo4j/data/log")

%x[neo4j/bin/Neo4j.bat start]
else
puts "You do not have administrative rights to reset the Neo4j Service"
end
else
%x[neo4j/bin/neo4j stop]

# Reset the database
Expand All @@ -46,5 +124,6 @@
# Start the server
%x[neo4j/bin/neo4j start]
end
end

end
end
2 changes: 2 additions & 0 deletions neography.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ Gem::Specification.new do |s|
s.add_development_dependency "rake", "~> 0.8.7"
s.add_dependency "httparty", "~> 0.7.3"
s.add_dependency "json"
s.add_dependency "os"
s.add_dependency "rubyzip"
end

0 comments on commit 066ed4f

Please sign in to comment.