UNICORN_RAILS(1)
π UNICORN_RAILS π
okay bestie, we're doing unicorn_rails(1) β it's a unicorn launcher for Rails 1.x and 2.x users, and yes it's giving vintage, we love that for it π
β¨ NAME β¨
unicorn_rails β a unicorn launcher for Rails 1.x and 2.x users π¦
β¨ SYNOPSIS β¨
unicorn_rails [-c CONFIG_FILE] [-E RAILS_ENV] [-D] [RACKUP_FILE]
β¨ DESCRIPTION β¨
so basically it's a rackup(1)-like command that launches your ancient Rails apps (2.x and earlier, we're talking fossil era, no shade) using Unicorn. Rails 3 and later support Rack natively, so bestie, if that's you, you're being encouraged to use unicorn(1) instead of unicorn_rails(1). it's not a vibe thing, it's just literally built in π
it expects to be started in your Rails application root (RAILS_ROOT), but you can use the "working_directory" directive in the CONFIG_FILE instead if you want to be extra about it.
the outward interface? lowkey resembles rackup(1). the internals and the default middleware loading? designed like the script/server command that ships with Rails. so it looks like one thing and thinks like another, main character energy fr fr πΈ
and like β Unicorn takes a myriad of command-line options for compatibility with ruby(1) and rackup(1), but pls. stick to the few command-line options in the SYNOPSIS and use the CONFIG_FILE as much as possible. that's the whole tea β
π UNICORN OPTIONS π
-c,--config-file CONFIG_FILEβ path to the Unicorn-specific config file. it's implemented as a Ruby DSL, so yes, actual Ruby code may be executed in there (iconic and slightly feral). check the RDoc/ri for theUnicorn::Configuratorclass for the full list of directives available from the DSL. also: using an absolute path forCONFIG_FILEis recommended, because it makes multiple instances of Unicorn easily distinguishable when you're looking atps(1)output. trust, you'll want that π-D,--daemonizeβ run daemonized in the background. the process gets detached from the controlling terminal andstdinis redirected to"/dev/null". and here's the fun part: unlike many common UNIX daemons, we do notchdirto"/"upon daemonization, because we want more control over the startup/upgrade process. unless specified in theCONFIG_FILE,stderrandstdoutwill also be redirected to"/dev/null". daemonization will skip loading of theRails::Rack::LogTailermiddleware under Rails >= 2.3.x. by default,unicorn_rails(1)will create a PID file in"RAILS_ROOT/tmp/pids/unicorn.pid". you may override this by specifying the"pid"directive to override this Unicorn config file π-E,--env RAILS_ENVβ run under the givenRAILS_ENV. this sets theRAILS_ENVenvironment variable. acceptable values are exactly those you expect in your Rails application, typically"development"or"production". no surprises, no plot twists π-l,--listen ADDRESSβ listens on a givenADDRESS.ADDRESSmay be in the form ofHOST:PORTorPATH.HOST:PORTis taken to mean a TCP socket, andPATHis meant to be a path to a UNIX domain socket. defaults to"0.0.0.0:8080"(all addresses on TCP port 8080). for production deployments, specifying the"listen"directive inCONFIG_FILEis recommended, because it allows fine-tuning of socket options. do it for the plot π«Ά
π₯ RACKUP COMPATIBILITY OPTIONS π₯
these exist for compatibility withrackup(1). the recommended move is the-l/--listenswitch instead. iykyk π
-o,--host HOSTβ listen on a TCP socket belonging toHOST, default is"0.0.0.0"(all addresses). if specified multiple times on the command-line, only the last-specified value takes effect. this option only exists for compatibility with therackup(1)command, use of"-l"/"--listen"switch is recommended instead β¨-p,--port PORTβ listen on the specified TCPPORT, default is8080. if specified multiple times on the command-line, only the last-specified value takes effect. this option only exists for compatibility with therackup(1)command, use of"-l"/"--listen"switch is recommended instead β¨--path PATHβ mounts the Rails application at the givenPATH(instead of"/"). this is equivalent to setting theRAILS_RELATIVE_URL_ROOTenvironment variable. this is only supported under Rails 2.3 or later at the moment. ngl, "at the moment" is doing a lot of work in that sentence π
π RUBY OPTIONS π
-e,--eval LINEβ evaluate aLINEof Ruby code. this evaluation happens immediately as the command-line is being parsed. so like, order matters, bestie β-d,--debugβ turn on debug mode, the$DEBUGvariable is set totrue. for Rails >= 2.3.x, this loads theRails::Rack::Debuggermiddleware π-w,--warnβ turn on verbose warnings, the$VERBOSEvariable is set totrue. it's giving "tell me everything" π’-I,--include PATHβ specify$LOAD_PATH.PATHwill be prepended to$LOAD_PATH. the':'character may be used to delimit multiple directories. this directive may be used more than once. modifications to$LOAD_PATHtake place immediately and in the order they were specified on the command-line π-r,--require LIBRARYβrequirea specifiedLIBRARYbefore executing the application. the"require"statement will be executed immediately and in the order they were specified on the command-line π
π§ RACKUP FILE π§
this defaults to "config.ru" in RAILS_ROOT. it should be the same file used by rackup(1) and other Rack launchers β it uses the Rack::Builder DSL.
unlike many other Rack applications, RACKUP_FILE is completely optional for Rails, but it may be used to disable some of the default middleware for performance. so like, skip it if you want, or use it to β¨optimizeβ¨, your call.
embedded command-line options are mostly parsed for compatibility with rackup(1) but are strongly discouraged. no cap π«
πΈ ENVIRONMENT VARIABLES πΈ
the RAILS_ENV variable is set by the aforementioned -E switch. the RAILS_RELATIVE_URL_ROOT is set by the aforementioned --path switch. either of these variables may also be set in the shell or the Unicorn CONFIG_FILE.
all application or library-specific environment variables (e.g. TMPDIR, RAILS_ASSET_ID) may always be set in the Unicorn CONFIG_FILE in addition to the spawning shell.
when transparently upgrading Unicorn, all environment variables set in the old master process are inherited by the new master process. Unicorn only uses (and will overwrite) the UNICORN_FD environment variable internally when doing transparent upgrades π
β‘ SIGNALS β‘
the following UNIX signals may be sent to the master process:
HUPβ reload config file, app, and gracefully restart all workers πINT/TERMβ quick shutdown, kills all workers immediately πQUITβ graceful shutdown, waits for workers to finish their current request before finishing π«ΆUSR1β reopen all logs owned by the master and all workers. SeeUnicorn::Util.reopen_logsfor what is considered a log πUSR2β reexecute the running binary. a separateQUITshould be sent to the original process once the child is verified to be up and running βWINCHβ gracefully stops workers but keep the master running. this will only work for daemonized processes πTTINβ increment the number of worker processes by one βTTOUβ decrement the number of worker processes by one β
See the SIGNALS (https://yhbt.net/unicorn/SIGNALS.html) document for full description of all signals used by Unicorn π
π SEE ALSO π
unicorn(1)Rack::Builderri/RDocUnicorn::Configuratorri/RDochttps://yhbt.net/unicorn/Unicorn/Configurator.html- unicorn RDoc
https://yhbt.net/unicorn/ - Rack RDoc
https://www.rubydoc.info/github/rack/rack/ - Rackup HowTo
https://github.com/rack/rack/wiki/(tutorial)-rackup-howto
π AUTHORS π
The Unicorn Community <unicorn-public@yhbt.net>.
and that's the whole page bestie!! Unicorn User Manual, September 17, 2009 β yes it's old, yes it still slays, periodt π β¨π
π¦ where this page comes from
- debian bookworm: unicorn 6.0.0-2+b4 Β· Ruby OR GPL-2.0-or-later
- debian trixie: unicorn 6.1.0+git.20250131.1370f52-1+b1 Β· Ruby OR GPL-2.0-or-later
- ubuntu jammy: unicorn 6.0.0-2build1 Β· Ruby OR GPL-2.0-or-later
- ubuntu noble: unicorn 6.1.0-2build2 Β· Ruby OR GPL-2.0-or-later
- ubuntu questing: unicorn 6.1.0+git.20250131.1370f52-1
- ubuntu resolute: unicorn 6.1.0+git.20250131.1370f52-1build1 Β· Ruby OR GPL-2.0-or-later
- ubuntu stonking: unicorn 6.1.0+git.20250131.1370f52-2 Β· Ruby OR GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms