Class: Ronin::App::CLI Private

Inherits:
Core::CLI::Command
  • Object
show all
Includes:
CommandKit::OpenApp, CommandKit::Options::Version, Core::CLI::Logging
Defined in:
lib/ronin/app/cli.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Starts the ronin web app.

Usage

ronin-app [options]

Options

-V, --version                    Prints the version and exits
-H, --host IP                    The host to listen on (Default: localhost)
    --db NAME                    The ronin-db database to connect to
    --db-uri URI                 The ronin-db database URI to connect to
-p, --port PORT                  The port to listen on (Default: 1337)
-h, --help                       Print help information

Instance Method Summary collapse

Instance Method Details

#app_envHash{String => String}

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The environment variables Hash for the app processes.

Returns:

  • (Hash{String => String})

    The env Hash to pass into the app processes.



183
184
185
186
187
188
189
190
191
192
193
# File 'lib/ronin/app/cli.rb', line 183

def app_env
  env = {}

  if options[:db_uri]
    env['DATABASE_URL'] = options[:db_uri]
  elsif options[:db]
    env['DATABASE_NAME'] = options[:db].to_s
  end

  return env
end

#is_redis_running?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Determines if the Redis server is running.

Returns:

  • (Boolean)

    Specifies whether the redis-server process is running or not.



140
141
142
# File 'lib/ronin/app/cli.rb', line 140

def is_redis_running?
  !`pgrep redis-server`.empty?
end

#runObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Runs the ronin-app command.



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
# File 'lib/ronin/app/cli.rb', line 96

def run
  host = options[:host]
  port = options[:port]

  pids = []

  # switch to the app directory
  Dir.chdir(ROOT)

  begin
    unless is_redis_running?
      log_info "Starting Redis server ..."
      pids << start_redis
      sleep 1
    end

    # start the web server process
    log_info "Starting Web server on #{host}:#{port} ..."
    pids << start_web_server
    sleep 1

    # start the sidekiq process
    log_info "Starting Sidekiq ..."
    pids << start_sidekiq
    sleep 1

    open_app_for("http://#{host}:#{port}") if stdout.tty?
    sleep
  ensure
    pids.each do |pid|
      Process.kill('TERM',pid)
      Process.kill('HUP',pid)
    end

    Process.waitall
  end
end

#start_redisInteger

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Starts the Redis server.

Returns:

  • (Integer)

    The PID of the redis-server process.



150
151
152
# File 'lib/ronin/app/cli.rb', line 150

def start_redis
  Process.spawn('redis-server')
end

#start_sidekiqInteger

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Starts the sidekiq background job process.

Returns:

  • (Integer)

    The PID of the sidekiq process.



173
174
175
# File 'lib/ronin/app/cli.rb', line 173

def start_sidekiq
  Process.spawn(app_env,"sidekiq -C ./config/sidekiq.yml -e production -r ./config/sidekiq.rb -r ./workers.rb")
end

#start_web_serverInteger

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Starts the web server process.

Returns:

  • (Integer)

    The PID of the puma web server process.



160
161
162
163
164
165
# File 'lib/ronin/app/cli.rb', line 160

def start_web_server
  command = %w[puma -C ./config/puma.rb -e production]
  command << '-b' << "tcp://#{options[:host]}:#{options[:port]}"

  Process.spawn(app_env,*command)
end