Class: DBRocket::Command::Server
- Inherits:
-
Base
- Object
- Base
- DBRocket::Command::Server
show all
- Defined in:
- lib/db_rockets/cli/commands/server.rb
Instance Attribute Summary
Attributes inherited from Base
#args
Instance Method Summary
collapse
Methods inherited from Base
#ask, #ask_for_config_file, #conf_to_uri_hash, #config_file, #confirm, #display, #error, #extract_option, #home_directory, #initialize, #load_taps, #make_config_file, #make_url_from_config, #parse_database_yml, #parse_taps_opts, #running_on_windows?, #shell, #taps_client, #uri_hash_to_url, #userinfo_from_uri
Instance Method Details
#parse_server_taps_opts ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/db_rockets/cli/commands/server.rb', line 43
def parse_server_taps_opts
opts = {}
opts[:environment] = ("--environment") || ENV['RAILS_ENV'] || ENV['MERB_ENV'] || ENV['RACK_ENV'] || 'development'
opts[:database_url] = args.shift.strip rescue ''
if opts[:database_url] == ''
opts[:database_url] = parse_database_yml(opts[:environment])
display "Auto-detected local database: #{opts[:database_url]}" if opts[:database_url] != ''
end
raise(CommandFailed, "Invalid database url") if opts[:database_url] == ''
if ("--debug")
opts[:debug] = true
end
conf = YAML.load(File.read(Dir.pwd + "/#{config_file}"))[opts[:environment]]
opts[:login] = conf['http_user']
opts[:password] = conf['http_password']
opts[:port] = conf['port']
opts
end
|
#pid_file ⇒ Object
39
40
41
|
# File 'lib/db_rockets/cli/commands/server.rb', line 39
def pid_file
'/tmp/db_rockets.pid'
end
|
#start ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/db_rockets/cli/commands/server.rb', line 6
def start
if File.exists?(pid_file)
puts "db_rocket server is running...."
else
load_taps
opts = parse_server_taps_opts
Taps.log.level = Logger::DEBUG if opts[:debug]
Taps::Config.database_url = opts[:database_url]
Taps::Config.login = opts[:login]
Taps::Config.password = opts[:password]
Taps::Config.verify_database_url
require 'taps/server'
pid = fork do
Taps::Server.run!({
:port => opts[:port],
:environment => :production,
:logging => true,
:dump_errors => true,
})
end
File.open(pid_file, 'w') {|f| f.write(pid) }
end
end
|
#stop ⇒ Object
31
32
33
34
35
36
37
|
# File 'lib/db_rockets/cli/commands/server.rb', line 31
def stop
if File.exists?(pid_file)
process_id = File.open(pid_file,'r').readline
Process.kill 9, process_id.to_i
FileUtils.rm(pid_file)
end
end
|