Class: Zold::Node
- Inherits:
-
Object
- Object
- Zold::Node
- Defined in:
- lib/zold/commands/node.rb
Overview
NODE command
Defined Under Namespace
Classes: NohupLog, WebrickLog
Instance Method Summary collapse
-
#initialize(wallets:, remotes:, copies:, log: Log::Quiet.new) ⇒ Node
constructor
A new instance of Node.
- #run(args = []) ⇒ Object
Constructor Details
Instance Method Details
#run(args = []) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/zold/commands/node.rb', line 50 def run(args = []) opts = Slop.parse(args, help: true, suppress_errors: true) do |o| o. = 'Usage: zold node [options]' o.string '--invoice', 'The invoice you want to collect money to or the wallet ID', required: true o.integer '--port', "TCP port to open for the Net (default: #{Remotes::PORT})", default: Remotes::PORT o.integer '--bind-port', "TCP port to listen on (default: #{Remotes::PORT})", default: Remotes::PORT o.string '--host', "Host name (default: #{ip})", default: ip o.integer '--strength', "The strength of the score (default: #{Score::STRENGTH})", default: Score::STRENGTH o.integer '--threads', 'How many threads to use for scores finding (default: 4)', default: 4 o.bool '--standalone', 'Never communicate with other nodes (mostly for testing)', default: false o.bool '--ignore-score-weakness', 'Ignore score weakness of incoming requests and register those nodes anyway', default: false o.boolean '--nohup', 'Run it in background, rebooting when a higher version is available in the network', default: false o.string '--nohup-command', 'The command to run in server "nohup" mode (default: "gem install zold")', default: 'gem install zold' o.string '--nohup-log', 'The file to log output into (default: zold.log)', default: 'zold.log' o.string '--save-pid', 'The file to save process ID into right after start (only in NOHUP mode)' o.bool '--never-reboot', 'Don\'t reboot when a new version shows up in the network', default: false o.bool '--routine-immediately', 'Run all routines immediately, without waiting between executions (for testing mostly)', default: false o.string '--expose-version', "The version of the software to expose in JSON (default: #{VERSION})", default: VERSION o.string '--bonus-wallet', 'The ID of the wallet to regularly send bonuses from (for nodes online)' o.string '--bonus-amount', 'The amount of ZLD to pay to each remote as a bonus', default: '1' o.string '--private-key', 'The location of RSA private key (default: ~/.ssh/id_rsa)', default: '~/.ssh/id_rsa' o.bool '--help', 'Print instructions' end if opts.help? @log.info(opts.to_s) return end raise '--invoice is mandatory' unless opts['invoice'] if opts[:nohup] pid = nohup(opts) File.write(opts['save-pid'], pid) if opts['save-pid'] @log.debug("Process ID #{pid} saved into \"#{opts['save-pid']}\"") @log.info(pid) return end Front.set(:log, @log) Front.set(:version, opts['expose-version']) Front.set(:logging, @log.debug?) Front.set(:home, Dir.pwd) @log.info("Home directory: #{Dir.pwd}") Front.set( :server_settings, Logger: WebrickLog.new(@log), AccessLog: [] ) if opts['standalone'] @remotes = Remotes::Empty.new @log.debug('Running in standalone mode! (will never talk to other remotes)') end Front.set(:ignore_score_weakness, opts['ignore-score-weakness']) Front.set(:wallets, @wallets) Front.set(:remotes, @remotes) Front.set(:copies, @copies) address = "#{opts[:host]}:#{opts[:port]}".downcase Front.set(:address, address) entrance = Entrance.new(@wallets, @remotes, @copies, address, log: @log) Front.set(:entrance, entrance) Front.set(:root, Dir.pwd) Front.set(:port, opts['bind-port']) Front.set(:reboot, !opts['never-reboot']) invoice = opts[:invoice] unless invoice.include?('@') require_relative 'pull' Pull.new(wallets: @wallets, remotes: @remotes, copies: @copies, log: @log).run(['pull', invoice]) require_relative 'invoice' invoice = Invoice.new(wallets: @wallets, log: @log).run(['invoice', invoice]) end farm = Farm.new(invoice, File.join(Dir.pwd, 'farm'), log: @log) farm.start( opts[:host], opts[:port], threads: opts[:threads], strength: opts[:strength] ) Front.set(:farm, farm) metronome = metronome(farm, opts) begin @log.info("Starting up the web front at http://#{opts[:host]}:#{opts[:port]}...") Front.run! ensure farm.stop metronome.stop end end |