Class: Deamons::Geth
- Inherits:
-
Object
- Object
- Deamons::Geth
- Defined in:
- lib/Deamons/geth.rb
Overview
Simple process to add wash trades to a market in order to simulate trade matching for QA and dev
Instance Method Summary collapse
-
#initialize ⇒ Geth
constructor
A new instance of Geth.
-
#redirect(outfile, errfile) ⇒ TrueClass
Send stdout and stderr to log files for the child process.
- #start ⇒ Object
-
#write_pid_file(pid, pidfile) ⇒ Integer and File
Attempts to write the pid of the forked process to the pid file.
Constructor Details
#initialize ⇒ Geth
Returns a new instance of Geth.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/Deamons/geth.rb', line 8 def initialize Process.fork do Process.daemon(true) pid = Process.pid redirect("#{pid}.outfile", "#{pid}.errfile") write_pid_file(pid, "#{pid}.pid") start end puts "Starting Daemon..." end |
Instance Method Details
#redirect(outfile, errfile) ⇒ TrueClass
Send stdout and stderr to log files for the child process
46 47 48 49 50 51 52 53 |
# File 'lib/Deamons/geth.rb', line 46 def redirect(outfile, errfile) $stdin.reopen '/dev/null' out = File.new outfile, "a" err = File.new errfile, "a" $stdout.reopen out $stderr.reopen err $stdout.sync = $stderr.sync = true end |
#start ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/Deamons/geth.rb', line 19 def start cmd = "#{ENV.fetch('GETH')} --syncmode=light --rinkeby --rpc --rpcaddr=0.0.0.0 --rpcport=8545 --port=30303 --rpcapi='db,personal,eth,net,web3' --rpccorsdomain='*' --rpcvhosts='*'" system(cmd) cmd = "#{ENV.fetch('NGROK')}./ngrok http 8545" system(cmd) rescue ::StandardError => e STDERR.puts e.backtrace STDERR.puts '\n' end |
#write_pid_file(pid, pidfile) ⇒ Integer and File
Attempts to write the pid of the forked process to the pid file.
33 34 35 36 37 38 39 40 |
# File 'lib/Deamons/geth.rb', line 33 def write_pid_file(pid, pidfile) File.open pidfile, "w" do |f| f.write pid end rescue ::Exception => e $stderr.puts "While writing the PID to file, unexpected #{e.class}: #{e}" Process.kill "HUP", pid end |