In my previous post I wrote about using the thin web server to run your Rack app locally. This works fine, but there is one issue. If you change your code or configuration you have to restart the server. This is not a big deal, but it do get quite annoying after a while. The solution is a gem called Shotgun.

From the readme:

The shotgun command starts one of Rack's supported servers (e.g., mongrel, thin, webrick) and listens for requests but does not load any part of the actual application. Each time a request is received, it forks, loads the application in the child process, processes the request, and exits the child process. The result is clean, application-wide reloading of all source files and templates on each request.

As you can see, there in no longer a need to restart your server when code has changed, Shotgun does it for you. Nice.

To get going you need to install the gem

1 $ sudo gem install shotgun

To start the web server, simply type

1 $ shotgun

if the current directory contains the file, or specify the config file like this

1 $ shotgun

The output should be something like

1 == Shotgun/Mongrel on

telling you which server got started and on what port it is listening.

There are some more options available, which you can find by looking at the help

 1 $ shotgun --help
 3 Ruby options:
 4   -e, --eval LINE          evaluate a LINE of code
 5   -d, --debug              set debugging flags (set $DEBUG to true)
 6   -w, --warn               turn warnings on for your script
 7   -I, --include PATH       specify $LOAD_PATH (may be used more than once)
 8   -r, --require LIBRARY    require the library, before executing your script
10 Rack options:
11   -s, --server SERVER      server (webrick, mongrel, thin, etc.)
12   -o, --host HOST          listen on HOST (default:
13   -p, --port PORT          use PORT (default: 9393)
14   -E, --env ENVIRONMENT    use ENVIRONMENT for defaults (default: development)
16 Shotgun options:
17   -O, --browse             open browser immediately after starting
18   -u, --url URL            specify url path (default: /)
19   -P, --public PATH        serve static files under PATH
20   -h, --help               show this message
21       --version            show version