class Deamons::Litecoind

Simple process to add wash trades to a market in order to simulate trade matching for QA and dev

Public Class Methods

new() click to toggle source
# File lib/Deamons/litecoind.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

Public Instance Methods

redirect(outfile, errfile) click to toggle source

Send stdout and stderr to log files for the child process @param [String] outfile @param [String] errfile @return [TrueClass]

# File lib/Deamons/litecoind.rb, line 44
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() click to toggle source
# File lib/Deamons/litecoind.rb, line 19
def start
  cmd = "litecoind -daemon -testnet -rest -server -rpcuser=ovex -rpcpassword=Pass123"
  system(cmd)
  rescue ::StandardError => e
    STDERR.puts e.backtrace
    STDERR.puts '\n'
end
write_pid_file(pid, pidfile) click to toggle source

Attempts to write the pid of the forked process to the pid file. @param [Integer] pid @param [String] pidfile @return [Integer and File]

# File lib/Deamons/litecoind.rb, line 31
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