Class: StellarCoreCommander::LocalProcess
- Inherits:
-
Process
- Object
- Process
- StellarCoreCommander::LocalProcess
show all
- Includes:
- Contracts
- Defined in:
- lib/stellar_core_commander/local_process.rb
Instance Attribute Summary collapse
Attributes inherited from Process
#base_port, #identity, #server, #working_dir
Instance Method Summary
collapse
Methods inherited from Process
#close_ledger, #close_timeout, #http_host, #http_port, #latest_ledger, #peer_port, #required_ports, #rm_working_dir, #sequence_for, #submit_transaction, #transaction_result, #wait_for_ready
Constructor Details
#initialize(working_dir, base_port, identity, opts) ⇒ LocalProcess
Returns a new instance of LocalProcess.
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/stellar_core_commander/local_process.rb', line 9
def initialize(working_dir, base_port, identity, opts)
stellar_core_bin = opts[:stellar_core_bin]
if stellar_core_bin.blank?
search = `which stellar-core`.strip
if $?.success?
stellar_core_bin = search
else
$stderr.puts "Could not find a `stellar-core` binary, please use --stellar-core-bin to specify"
exit 1
end
end
FileUtils.cp(stellar_core_bin, "#{working_dir}/stellar-core")
super
end
|
Instance Attribute Details
#pid ⇒ Object
Returns the value of attribute pid.
6
7
8
|
# File 'lib/stellar_core_commander/local_process.rb', line 6
def pid
@pid
end
|
#wait ⇒ Object
Returns the value of attribute wait.
7
8
9
|
# File 'lib/stellar_core_commander/local_process.rb', line 7
def wait
@wait
end
|
Instance Method Details
#cleanup ⇒ Object
101
102
103
104
105
106
|
# File 'lib/stellar_core_commander/local_process.rb', line 101
def cleanup
database.disconnect
shutdown
drop_database
rm_working_dir
end
|
#create_database ⇒ Object
45
46
47
48
|
# File 'lib/stellar_core_commander/local_process.rb', line 45
def create_database
run_cmd "createdb", [database_name]
raise "Could not create db: #{database_name}" unless $?.success?
end
|
#database ⇒ Object
117
118
119
|
# File 'lib/stellar_core_commander/local_process.rb', line 117
def database
@database ||= Sequel.postgres(database_name)
end
|
#database_name ⇒ Object
122
123
124
|
# File 'lib/stellar_core_commander/local_process.rb', line 122
def database_name
"stellar_core_tmp_#{basename}"
end
|
#drop_database ⇒ Object
51
52
53
54
|
# File 'lib/stellar_core_commander/local_process.rb', line 51
def drop_database
run_cmd "dropdb", [database_name]
raise "Could not drop db: #{database_name}" unless $?.success?
end
|
#dsn ⇒ Object
127
128
129
|
# File 'lib/stellar_core_commander/local_process.rb', line 127
def dsn
"postgresql://dbname=#{database_name}"
end
|
#dump_database ⇒ Object
109
110
111
112
113
|
# File 'lib/stellar_core_commander/local_process.rb', line 109
def dump_database
Dir.chdir(@working_dir) do
`pg_dump #{database_name} --clean --no-owner`
end
end
|
#forcescp ⇒ Object
27
28
29
30
|
# File 'lib/stellar_core_commander/local_process.rb', line 27
def forcescp
run_cmd "./stellar-core", ["--forcescp"]
raise "Could not set --forcescp" unless $?.success?
end
|
#initialize_database ⇒ Object
39
40
41
42
|
# File 'lib/stellar_core_commander/local_process.rb', line 39
def initialize_database
run_cmd "./stellar-core", ["--newdb"]
raise "Could not initialize db" unless $?.success?
end
|
#initialize_history ⇒ Object
33
34
35
36
|
# File 'lib/stellar_core_commander/local_process.rb', line 33
def initialize_history
run_cmd "./stellar-core", ["--newhist", "main"]
raise "Could not initialize history" unless $?.success?
end
|
#run ⇒ Object
70
71
72
73
74
75
|
# File 'lib/stellar_core_commander/local_process.rb', line 70
def run
raise "already running!" if running?
forcescp
launch_stellar_core
end
|
#running? ⇒ Boolean
79
80
81
82
83
84
85
|
# File 'lib/stellar_core_commander/local_process.rb', line 79
def running?
return false unless @pid
::Process.kill 0, @pid
true
rescue Errno::ESRCH
false
end
|
#setup ⇒ Object
62
63
64
65
66
67
|
# File 'lib/stellar_core_commander/local_process.rb', line 62
def setup
write_config
create_database
initialize_history
initialize_database
end
|
#shutdown(graceful = true) ⇒ Object
88
89
90
91
92
93
94
95
96
97
98
|
# File 'lib/stellar_core_commander/local_process.rb', line 88
def shutdown(graceful=true)
return true if !running?
if graceful
::Process.kill "INT", @pid
else
::Process.kill "KILL", @pid
end
@wait.value.success?
end
|
#write_config ⇒ Object
57
58
59
|
# File 'lib/stellar_core_commander/local_process.rb', line 57
def write_config
IO.write("#{@working_dir}/stellar-core.cfg", config)
end
|