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