summaryrefslogtreecommitdiff
path: root/lib/tasks/opentox.rb
blob: 6f1284fbd7cd043c22539f0b88cfe0d525f914b7 (plain)
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
require "environment"

namespace :opentox do

	desc "Install required gems"
	task :install do
		puts `sudo gem install #{@gems}`
	end

	desc "Update gems"
	task :update do
		puts `sudo gem update #{@gems}`
	end

	namespace :services do

		desc "Run opentox services"
		task :start do
			@@config[:services].each do |service,uri|
				dir = File.join(@@config[:base_dir], service)
				case @@config[:webserver]
				when 'thin'
					port = uri.sub(/^.*:/,'').sub(/\/$/,'')
					Dir.chdir dir
					begin
						`thin --trace --rackup config.ru start -p #{port} -e #{ENV['RACK_ENV']} &`
						puts "#{service} started on port #{port}."
					rescue
						puts "Cannot start #{service} on port #{port}."
					end
				when 'passenger'
					puts "not yet implemented"
				else
					puts "not yet implemented"
				end
			end
		end

		desc "Stop opentox services"
		task :stop do
			@@config[:services].each do |service,uri|
				port = uri.sub(/^.*:/,'').sub(/\/$/,'')
				`echo "SHUTDOWN" | nc localhost #{port}` if port
			end
		end

		desc "Restart opentox services"
		task :restart => [:stop, :start]

	end

	namespace :test do

		ENV['RACK_ENV'] = 'test'
		test = "#{Dir.pwd}/test/test.rb"

		desc "Run local tests"
		task :local => "opentox:services:restart" do
			load test
		end

		task :remote do
			#load 'test.rb'
		end

	end

end