Sha256: 3adf10e87769645bb80ad610c7922ccb972ac84d9f85b77b24042fba71bae859

Contents?: true

Size: 1.44 KB

Versions: 13

Compression:

Stored size: 1.44 KB

Contents

# frozen_string_literal: true

module Deamons
  # Simple process to add wash trades to a market in order to simulate trade matching for QA and dev
  class Bitcoind
    require 'utils'

    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

    def start
      cmd = "bitcoind -daemon -testnet -rest -server -rpcuser=ovex -rpcpassword=Pass123"
      system(cmd)
      rescue ::StandardError => e
        STDERR.puts e.backtrace
        STDERR.puts '\n'
    end

    # Attempts to write the pid of the forked process to the pid file.
    # @param [Integer]  pid
    # @param [String]  pidfile
    # @return [Integer and File]
    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

    # Send stdout and stderr to log files for the child process
    # @param [String]  outfile
    # @param [String]  errfile
    # @return [TrueClass]
    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
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
SimBot-0.1.43 lib/Deamons/bitcoind.rb
SimBot-0.1.42 lib/Deamons/bitcoind.rb
SimBot-0.1.41 lib/Deamons/bitcoind.rb
SimBot-0.1.40 lib/Deamons/bitcoind.rb
SimBot-0.1.39 lib/Deamons/bitcoind.rb
SimBot-0.1.38 lib/Deamons/bitcoind.rb
SimBot-0.1.37 lib/Deamons/bitcoind.rb
SimBot-0.1.36 lib/Deamons/bitcoind.rb
SimBot-0.1.35 lib/Deamons/bitcoind.rb
SimBot-0.1.34 lib/Deamons/bitcoind.rb
SimBot-0.1.33 lib/Deamons/bitcoind.rb
SimBot-0.1.32 lib/Deamons/bitcoind.rb
SimBot-0.1.31 lib/Deamons/bitcoind.rb