-
Notifications
You must be signed in to change notification settings - Fork 8
Rango Boot Process
This page is up to date for Rango 0.1.
Rango doesn’t provide any scripts for running server, console or whatever. Instead of it, you have just two executables: init.rb and config.ru.
You can use shebang for pointing the executable to the correct interpreter, but the fun just begins here: you may also specify an arguments, like --disable-gems for Ruby or -s thin or -p 4000 for rackup, so it will knows every time which server and port you want to use.
Unfortunately this is highly platform-dependent. This will work on Linux, but won’t work on OS X:
#!/usr/bin/ruby1.9 --disable-gems
On the opposite, this will work on OS X, but won’t work on Linux:
#!/usr/bin/env ruby1.9 --disable-gems
And yeah, Windows don’t have shebang support at all. But never mind, you can run ruby init.rb resp. bin/rackup config.ru directly. The shebang is just a helper for you.
You also don’t have to care if it will work on your server, because there your webserver probably just take config.ru and load it, so it’s no job for you to do.
This is actually Bundler file, but it’s important for $LOAD_PATH setup. When you invoke environment task, the only thing it does is that it will require this file. See bundling for further explanation.
This script should setup Rango environment. Since it’s an executable, you can use it as script/runner in Rails. But it also takes -i argument, and then you can use it as a console. What it actually does:
- Setup environments
- Load dependencies
- Boot Rango through Rango.boot
- Load custom Ruby/Rackup script if it’s provided in ARGV
Script config.ru should load init.rb and then initialize Rack environment. Please notice this file has extension ru, not rb, so interpret isn’t ruby, but rackup. Also when you are in the rackup file, you are in context of Rack::Builder instance, so it may behave differently, for example File will refer to Rack::File etc.
The default shebang is #!/usr/bin/env ./init.rb -p 4000 -s webrick, change it to fit your needs better.
- middlewares setup
- routes
In your plugins, you may need to run some tasks after Rango environment will be initialized. And there bootloaders come. Here is an example from my Pupu gem: