-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
82 lines (68 loc) · 2.42 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
78
79
80
81
82
# Bundler is messing with that later on
GEM_PATH = ENV['_ORIGINAL_GEM_PATH'] || ENV['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'
desc "Starting the Slice Service as a daemon"
task :start, :config do |t, args|
config = args[:config]
system("/usr/bin/env JOB_CONFIG=#{config} bundle exec god -c etc/omf_slice_service.god")
system('/usr/bin/env bundle exec god start slice_service')
end
desc "Stop the Service Daemon"
task :stop do |t, args|
system('/usr/bin/env bundle exec god stop slice_service')
end
desc "Print the status of the Service daemon"
task :status do |t, args|
system('/usr/bin/env bundle exec god status slice_service')
end
desc "Run the Service in this shell"
task :run do |t, args|
system("#{TOP_DIR}/bin/omf_slice_service --dm-auto-upgrade start")
end
desc "Call after 'bundle install --path vendor'"
task 'post-install' => [:create_server_bin]
# task 'create_server_bin' do
# target = 'bin/omf_slice_service'
# unless File.readable?("#{target}.in")
# abort "Can't find '#{target}.in' in local directory"
# end
# tmpl = File.read("#{target}.in")
# puts ">>>> #{tmpl}"
# home = ENV['HOME']
# rvm_home = ENV["rvm_bin_path"].match(/.*rvm/)[0]
# d, ruby, gemset = (GEM_PATH || ENV['_ORIGINAL_GEM_PATH'] || ENV['GEM_PATH']).match(/.*(ruby.*)@(.*)/).to_a
# puts "HOME: #{home} rvm_home: #{rvm_home} ruby: #{ruby} gemset: #{gemset}"
# 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
task 'create_server_bin' do
target = 'bin/omf_slice_service'
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_path = ENV["rvm_path"]
if rvm_path
rvm_home = rvm_path
d, ruby, gemset = GEM_PATH.match(/.*(ruby.*)@(.*)/).to_a
end
puts [home, rvm_home, ruby, gemset].inspect
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