Class: StellarCoreCommander::LocalProcess
- Inherits:
-
Process
- Object
- Process
- StellarCoreCommander::LocalProcess
show all
- Includes:
- Contracts
- Defined in:
- lib/stellar_core_commander/local_process.rb
Constant Summary
Constants inherited
from Process
Process::DEFAULT_HOST, Process::SPECIAL_PEERS
Instance Attribute Summary collapse
Attributes inherited from Process
#atlas, #atlas_interval, #base_port, #host, #identity, #name, #network_passphrase, #server, #transactor, #unverified, #working_dir
Instance Method Summary
collapse
Methods inherited from Process
#account_count, #account_row, #await_sync?, #balance_for, #catchup, #check_equal, #check_equal_ledger_objects, #check_ledger_sequence_is_prefix_of, #check_no_error_metrics, #checkdb_runs, #close_ledger, #close_timeout, #crashed?, #database, #database_host, #database_name, #database_password, #database_port, #database_uri, #database_url, #database_user, #db_store_state, #dsn, #dump_info, #dump_metrics, #dump_scp_state, #dump_server_query, #has_special_peers?, #history_archive_state, #hostname, #http_port, #idname, #info, #info_field, #latest_ledger, #latest_ledger_hash, #launched?, #ledger_num, #load_generation_runs, #manual_close?, #metrics, #metrics_1m_rate, #metrics_count, #node_map_or_special_field, #objects_checked, #offer_count, #operations_per_second, #peer_connections, #peer_names, #peer_port, #prepare, #quorum, #required_ports, #run, #run_cmd, #scp_ballots_prepared, #scp_quorum_heard, #sequence_for, #start_checkdb, #start_load_generation, #stopped?, #submit_transaction, #sync_timeout, #synced?, #ten_accounts, #ten_offers, #ten_trustlines, #transaction_result, #transactions_applied, #transactions_per_second, #trustline_count, #wait_for_ready
Constructor Details
Returns a new instance of LocalProcess.
8
9
10
11
12
13
14
15
16
17
|
# File 'lib/stellar_core_commander/local_process.rb', line 8
def initialize(params)
raise "`host` param is unsupported on LocalProcess, please use `-p docker` for this recipe." if params[:host]
$stderr.puts "Warning: Ignoring `atlas` param since LocalProcess doesn't support this." if params[:atlas]
super
@stellar_core_bin = params[:stellar_core_bin]
@database_url = params[:database].try(:strip)
setup_working_dir
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
|
Instance Method Details
#cleanup ⇒ Object
98
99
100
101
102
103
104
105
106
|
# File 'lib/stellar_core_commander/local_process.rb', line 98
def cleanup
database.disconnect
dump_database
dump_scp_state
dump_info
dump_metrics
shutdown
drop_database unless @keep_database
end
|
#crash ⇒ Object
122
123
124
|
# File 'lib/stellar_core_commander/local_process.rb', line 122
def crash
`kill -ABRT #{@pid}`
end
|
#create_database ⇒ Object
39
40
41
42
|
# File 'lib/stellar_core_commander/local_process.rb', line 39
def create_database
run_cmd "createdb", [database_name]
raise "Could not create db: #{database_name}" unless $?.success?
end
|
#default_database_url ⇒ Object
118
119
120
|
# File 'lib/stellar_core_commander/local_process.rb', line 118
def default_database_url
"postgres:///#{idname}"
end
|
#drop_database ⇒ Object
45
46
47
48
|
# File 'lib/stellar_core_commander/local_process.rb', line 45
def drop_database
run_cmd "dropdb", [database_name]
raise "Could not drop db: #{database_name}" unless $?.success?
end
|
#dump_database ⇒ Object
109
110
111
112
113
114
115
|
# File 'lib/stellar_core_commander/local_process.rb', line 109
def dump_database
fname = "#{working_dir}/database-#{Time.now.to_i}-#{rand 100000}.sql"
$stderr.puts "dumping database to #{fname}"
sql = `pg_dump #{database_name} --clean --no-owner --no-privileges`
File.open(fname, 'w') {|f| f.write(sql) }
fname
end
|
#forcescp ⇒ Object
20
21
22
23
|
# File 'lib/stellar_core_commander/local_process.rb', line 20
def forcescp
run_cmd "./stellar-core", ["--forcescp"]
raise "Could not set --forcescp" unless $?.success?
end
|
#history_dir ⇒ Object
56
57
58
|
# File 'lib/stellar_core_commander/local_process.rb', line 56
def history_dir
File.expand_path("#{working_dir}/../history-archives")
end
|
#initialize_database ⇒ Object
33
34
35
36
|
# File 'lib/stellar_core_commander/local_process.rb', line 33
def initialize_database
run_cmd "./stellar-core", ["--newdb"]
raise "Could not initialize db" unless $?.success?
end
|
#initialize_history ⇒ Object
26
27
28
29
30
|
# File 'lib/stellar_core_commander/local_process.rb', line 26
def initialize_history
Dir.mkdir(history_dir) unless File.exists?(history_dir)
run_cmd "./stellar-core", ["--newhist", @name.to_s]
raise "Could not initialize history" unless $?.success?
end
|
#launch_process ⇒ Object
69
70
71
72
|
# File 'lib/stellar_core_commander/local_process.rb', line 69
def launch_process
forcescp if @forcescp
launch_stellar_core
end
|
#running? ⇒ Boolean
76
77
78
79
80
81
82
|
# File 'lib/stellar_core_commander/local_process.rb', line 76
def running?
return false unless @pid
::Process.kill 0, @pid
true
rescue Errno::ESRCH
false
end
|
#setup ⇒ Object
61
62
63
64
65
66
|
# File 'lib/stellar_core_commander/local_process.rb', line 61
def setup
write_config
create_database unless @keep_database
initialize_history
initialize_database
end
|
#shutdown(graceful = true) ⇒ Object
85
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/stellar_core_commander/local_process.rb', line 85
def shutdown(graceful=true)
return true if !running?
if graceful
::Process.kill "INT", @pid
else
::Process.kill "KILL", @pid
end
@wait_value == 0
end
|
#write_config ⇒ Object
51
52
53
|
# File 'lib/stellar_core_commander/local_process.rb', line 51
def write_config
IO.write("#{@working_dir}/stellar-core.cfg", config)
end
|