Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
T

trinidad

> 编程语言
Open source

Web server for Rails/Rack applications built upon JRuby::Rack and Apache Tomcat

438 stars0 likes0 views
WebsiteGitHub

About

Web server for Rails/Rack applications built upon JRuby::Rack and Apache Tomcat

Trinidad

Trinidad allows you to run Rails and/or Rack applications within an embedded Tomcat container. Apache Tomcat (formerly also Jakarta Tomcat) is an open source web server and Servlet container with a long history that dates back to the previous millenia.

Trinidad's goals with bringing Tomcat into JRuby land are mostly the following :

  • flexibility especially in terms of configuration it allows you to tune (almost) everything from a simple trinidad.yml (or .rb) configuration file
  • portability there's no vendor lock-in as we use JRuby::Rack, thus even if you do some Java integration or use it's Rack Servlet extensions you're still able to migrate to a standalone Tomcat or any other Servlet container
  • easy Java integration (just in-case you need it, it's there)
  • extensions such as connection pooling (sharing pools between deployed Rails apps) and (threaded) worker adapters for Resque and Delayed::Job

Installation

$ jruby -S gem install trinidad

NOTE: please use 1.5.0.B2 gem install trinidad --pre, esp. on JRuby 9K, as Trinidad 1.4 will no longer receive Tomcat (7.0.x) security updates.

Trinidad 1.4 requires (and supports) JRuby 1.6.8 or later (latest 1.7.x recommended).

Quick Start

$ cd a-rails-app
$ jruby -S trinidad

Setup

If you use Bundler, you might want to add Trinidad to your Gemfile :

gem 'trinidad', :require => nil

However this is not absolutely necessary, you might simply gem install trinidad and than run trinidad - keep in mind a server is not an application dependency.

Rails

Trinidad supports the same Rails version as the JRuby-Rack it founds on (or is specified/locked in your Gemfile), which are 4.x, 3.x and even 2.3 for JRuby-Rack 1.1.x (and the up coming 1.2). Merb is not supported.

$ trinidad

or if you prefer to use the Rack handler (e.g. for development) use :

$ rails s trinidad

Please note all configuration options will work using the Rack handler mode, you should usually only use it for development/tests and run trinidad on production.

Sinatra

$ ruby app.rb -s Trinidad

or configure your application to always use Trinidad :

ruby
require 'sinatra'
require 'trinidad'

configure do
  set :server, :trinidad
end

Rack

Trinidad auto-detects a plain-old Rack application (if there's a config.ru) :

$ trinidad

You can as well pass the server name to rackup to start the Rack handler :

$ rackup -s trinidad

Or you can set Trinidad as the default server in your config.ru file :

#\ -s trinidad

Trinidad solves the Rack "chicken-egg" problem when booting from a rackup file the same way as JRuby-Rack (since it boots all applications), that is :

  • if a Bundler Gemfile is detected, it first does a bundle/setup to load rack
  • otherwise the rack (gem) version might be specified using a magic comment in config.ru as # rack.version: ~>1.4.0 (or the latest installed gem is used)

NOTE: We recommend to use the plain trinidad mode for running apps (in production), since it supports runtime pooling while the "rackup" mode does not, it also provides you with better Java integration possibilities.

Also note that Trinidad does not mimic JRuby-Rack's (1.1.x) backwards compatible behavior of starting a pool for Rails but booting a thread-safe runtime for plain Rack applications by default. Runtime pooling is the default with Trinidad 1.4 and stays the same no matter the type of the application. This has changed in Trinidad 1.5 and it assumes thread-safe applications by default.

All major rack versions ( web application root directory

  • -e, --env ENVIRONMENT => rack (rails) environment
  • --rackup [RACKUP_FILE] => rackup configuration file
  • --public PUBLIC_DIR => web application public root
  • -c, --context CONTEXT => application context path
  • --monitor MONITOR_FILE => monitor for application re-deploys
  • -t, --threadsafe => force thread-safe mode (use single runtime)
  • --runtimes MIN:MAX => use given number of min/max jruby runtimes
  • -f, --config [CONFIG_FILE] => configuration file
  • --address ADDRESS => host address
  • -p, --port PORT => port to bind to
  • -s, --ssl [SSL_PORT] => enable secure socket layout
  • -a, --ajp [AJP_PORT] => enable the AJP web protocol
  • --java_lib LIB_DIR => contains .jar files used by the app
  • --java_classes CLASSES_DIR => contains java classes used by the app
  • -l, --load EXTENSION_NAMES => load options for extensions
  • --apps_base APPS_BASE_DIR => set applications base directory
  • -g, --log LEVEL => set logging level
…

$ jruby -S trinidad --config my_trinidad.yml


```yml
---
  port: 4242
  address: 0.0.0.0

Ruby Configuration

As an alternative to the config/trinidad.yml file, a .rb configuration file might be used to setup Trinidad. It follows the same convention as the YAML configuration - the file config/trinidad.rb is loaded by default if exists.

ruby
Trinidad.configure do |config|
  config.port = 4242
  config.address = '0.0.0.0'
  #config[:custom] = 'custom'
end

Logging

As you might notice on your first trinidad the server uses standard output :

kares@theborg:~/workspace/trinidad/MegaUpload$ trinidad -p 8000 -e staging
Initializing ProtocolHandler ["http-bio-8000"]
Starting Servlet Engine: Apache Tomcat/7.0.28
Starting ProtocolHandler ["http-bio-8000"]
Context with name [/] has started rolling
Context with name [/] has completed rolling

…

yml
---
  public:
    root: public # same as the above "public: public" setting
    cached: true # enable (in-memory) asset caching on for env != 'development'
    cache_ttl: 5000 # cache TTL in millis (might want to increase this)
    cache_max_size: 10240 # the maximum cache size in kB
    cache_object_max_size: 512 # max size for a cached object (asset) in kB
    #aliases: # allows to "link" other directories into the public root e.g. :
      #/home: /var/local/www

…


JRUBY_OPTS="$JRUBY_OPTS -J-XX:+UseConcMarkSweepGC -J-XX:+CMSClassUnloadingEnabled"

Configure the reload strategy per web application or globally e.g. :

yaml
---
  port: 8080
  environment: production
  reload_strategy: rolling

Virtual Hosts

It's possible to use Trinidad with multiple hosts and load the applications under them automatically. A (virtual) host represents an association of a network name (such as "www.example.com" with the particular server on which Tomcat is running. Please remember that each host must have its applications in a different directory. You can find out more at Tomcat's documentation.

ruby
Trinidad.configure do |config|
  config.hosts = {
    # applications path (host app base directory) => host names
    # (first one is the "main" host name, other ones are aliases)
    '/var/www/local/apps' => ['localhost', '127.0.0.1'],
    '/home/trinidad/apps' => 'appshost'
    # NOTE: by default a (default) 'localhost' host is setup
  }
end

Detailed host configuration is also possible using supported host options :

yaml
---
  port: 8080
  hosts:
    localhost:
      app_base: /home/trinidad/apps
      auto_deploy: false
      unpackWARs: true

If applications are configured via the web_apps section, the host for each application can be added with the host (or hosts) key, if a specified host does not exists (e.g. not configured or not "localhost") it will be created. If several applications belong to the same host, they are expected to reside under the same parent directory e.g. :

ruby
Trinidad.configure do |config|
  config.web_apps = {
    :mock1 => {
      :root_dir => 'rails_apps/mock1',
      :host     => ['rails.virtual.host', 'rails.host']
    },
    :mock2 => {
      :root_dir => 'rails_apps/mock2',
      :host     => 'rails.virtual.host'
    },
    :mock3 => {
      :root_dir => 'rack_apps/mock3',
      :host     => ['rack.virtual.host', 'rack.host']
    }
  }
end

Extensions

Trinidad allows to extend itself with more (not just Tomcat) features using extensions, they're essentially components hooked into Tomcat's life-cycle. Here is a list of the available extensions that are "officially supported" :

  • Database Connection Pooling : http://github.com/trinidad/trinidad_dbpool_extension
  • Daemonize Trinidad, based on Akuma (Unix only) : http://github.com/trinidad/trinidad_daemon_extension
  • Init Services (for Unix and Windows), based on Commons Daemon : http://github.com/trinidad/trinidad_init_services
  • Scheduler, based on Quartz : http://github.com/trinidad/trinidad_scheduler_extension
  • Worker, threaded workers (supports Resque, Delayed::Job) : http://github.com/trinidad/trinidad_worker_extension
  • Logging, enhance Trinidad's logging system : http://github.com/trinidad/trinidad_logging_extension
  • Application and Server Lifecycle Management : http://github.com/trinidad/trinidad_lifecycle_extension
  • Valves - components inserted into the request pipeline (e.g. Access Log) : http://github.com/trinidad/trinidad_valve_extension
  • Application/Deployment Monitoring based on PSI-Probe : http://github.com/trinidad/trinidad_probe_extension
  • Enable remote JMX monitoring capabilities for Trinidad : http://github.com/trinidad/trinidad_jmx_remote_extension

You can find further information on how to write extensions in the wiki.

Support

  • ask us for help on gitter or use SO ... we shall get notified
  • we're also on the JRuby mailing List: http://wiki.jruby.org/MailingLists
  • and the #jruby IRC channel
  • please report issues at: https://github.com/trinidad/trinidad/issues

Copyright

Copyright (c) 2016 Team Trinidad. See LICENSE (http://en.wikipedia.org/wiki/MIT_License) for details.

Issues· 22 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Ruby

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言