LinuxCommandLibrary

shotgun

Manage and automate VFX, games, animation workflows

SYNOPSIS

shotgun [options] [config.ru]

PARAMETERS

-p, --port PORT
    Specifies the port to listen on. Default: 9393.

-o, --host HOST
    Specifies the host address to bind to. Default: 0.0.0.0 (all interfaces).

-e, --env ENVIRONMENT
    Sets the Rack environment (e.g., development, production). Default: development.

-d, --daemonize
    Runs the server in the background as a daemon.

-r, --reload-dir DIR
    Specifies a directory to watch for file changes to trigger a reload. If not specified, the current directory is watched.

-v, --version
    Displays the Shotgun version.

-h, --help
    Displays help information and available options.

DESCRIPTION

Shotgun is a Ruby gem that provides a development web server for Rack applications. Its primary function is to automatically reload application code on every incoming HTTP request without requiring a server restart. This significantly speeds up the development workflow for Ruby web applications, as developers can make changes to their code and see the effects instantly in the browser. It achieves this by forking a new process for each request, ensuring that the latest version of the application's code is loaded. While incredibly convenient for development, Shotgun's per-request forking makes it unsuitable for production environments due to performance overhead. It's often used in conjunction with rackup or directly from a Rakefile.

CAVEATS

Shotgun is not suitable for production use due to its per-request forking model, which incurs significant performance overhead. Its primary design goal is to facilitate rapid development by providing instant code reloading. It can also be slower than traditional development servers for requests that do not involve code changes, as it always reloads the application code.

<I>USAGE WITH RACKUP</I>

Shotgun is often used by simply navigating to your Rack application's root directory and running shotgun. If you have a config.ru file, it will automatically load it. You can also specify the config.ru file explicitly as an argument, e.g., shotgun my_app/config.ru.
It typically binds to localhost:9393 by default, which can be accessed through your web browser.

<I>HOW IT WORKS</I>

For each incoming HTTP request, Shotgun forks a new Ruby process. This new process loads the entire application code from scratch. This ensures that any changes made to the application's files since the last request are picked up immediately, without the need to restart the main Shotgun server process. The child process handles the request and then exits, making it a very robust mechanism for development reloading.

HISTORY

Shotgun was developed as a Ruby gem to address a common pain point in Ruby web development: the need to manually restart the development server after every code change to see updates. It leveraged Ruby's process forking capabilities to provide immediate code reloading, making it an indispensable tool for many developers working with Rack-based frameworks like Sinatra. Its simplicity and effectiveness in streamlining the feedback loop cemented its place in the Ruby developer's toolkit.

SEE ALSO

rackup(1), ruby(1), thin(1), puma(1), unicorn(1)

Copied to clipboard