-
Notifications
You must be signed in to change notification settings - Fork 5
/
Rakefile
78 lines (58 loc) · 1.92 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# Bundler is messing with that later on
GEM_PATH = ENV['_ORIGINAL_GEM_PATH']
# Setup bundler environment
TOP_DIR = File.dirname(File.symlink?(__FILE__) ? File.readlink(__FILE__) : __FILE__)
ENV['BUNDLE_GEMFILE'] = File.join(TOP_DIR, 'Gemfile')
require 'bundler'
Bundler.setup()
require 'yaml'
require 'god'
require 'rake/testtask'
task :default => :test
Rake::TestTask.new do |t|
t.libs << 'test'
t.pattern = "test/**/*_spec.rb"
t.verbose = true
end
desc "Starting Labwiki as a daemon"
task :start, :config do |t, args|
config = args[:config] || ENV['LW_CONFIG'] || "etc/labwiki/local.yaml"
config = File.expand_path(config)
abort "Config file '#{config}' NOT found" unless File.exist?(config)
system("/usr/bin/env LW_CONFIG=#{config} bundle exec god -c etc/labwiki/labwiki.god")
system('/usr/bin/env bundle exec god start labwiki')
end
desc "Stop the Labwiki Daemon"
task :stop do |t, args|
system('/usr/bin/env bundle exec god stop labwiki')
end
desc "Print the status of the Labwiki daemon"
task :status do |t, args|
system('/usr/bin/env bundle exec god status labwiki')
end
desc "Run Labwiki in this shell"
task :run do |t, args|
system("#{TOP_DIR}/bin/labwiki #{args.join(' ')} start")
end
desc "Call after 'bundle install --path vendor'"
task 'post-install' => [:create_server_bin]
task 'create_server_bin' do
target = 'bin/labwiki'
unless File.readable?("#{target}.in")
abort "Can't find '#{target}.in' in local directory"
end
tmpl = File.read("#{target}.in")
home = ENV['HOME']
rvm_home = ruby = gemset = ''
rvm_bin_path = ENV["rvm_bin_path"]
if rvm_bin_path
rvm_home = rvm_bin_path.match(/.*rvm/)[0]
d, ruby, gemset = GEM_PATH.match(/.*(ruby.*)@(.*)/).to_a
end
s = tmpl.gsub('%HOME%', home).gsub('%RVM_HOME%', rvm_home).gsub('%RUBY%', ruby).gsub('%GEMSET%', gemset)
File.open(target, 'w') do |f|
f.write(s)
end
File.chmod(0755, target)
puts ".. Created '#{target}'."
end