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 the Unicorn::Configurator class for the full list of directives available from the DSL. also: using an absolute path for CONFIG_FILE is recommended, because it makes multiple instances of Unicorn easily distinguishable when you're looking at ps(1) output. trust, you'll want that πŸ‘‘
  • -D, --daemonize β€” run daemonized in the background. the process gets detached from the controlling terminal and stdin is redirected to "/dev/null". and here's the fun part: unlike many common UNIX daemons, we do not chdir to "/" upon daemonization, because we want more control over the startup/upgrade process. unless specified in the CONFIG_FILE, stderr and stdout will also be redirected to "/dev/null". daemonization will skip loading of the Rails::Rack::LogTailer middleware 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 given RAILS_ENV. this sets the RAILS_ENV environment 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 given ADDRESS. ADDRESS may be in the form of HOST:PORT or PATH. HOST:PORT is taken to mean a TCP socket, and PATH is 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 in CONFIG_FILE is recommended, because it allows fine-tuning of socket options. do it for the plot 🫢

πŸ”₯ RACKUP COMPATIBILITY OPTIONS πŸ”₯

these exist for compatibility with rackup(1). the recommended move is the -l/--listen switch instead. iykyk πŸ’…
  • -o, --host HOST β€” listen on a TCP socket belonging to HOST, 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 the rackup(1) command, use of "-l"/"--listen" switch is recommended instead ✨
  • -p, --port PORT β€” listen on the specified TCP PORT, default is 8080. if specified multiple times on the command-line, only the last-specified value takes effect. this option only exists for compatibility with the rackup(1) command, use of "-l"/"--listen" switch is recommended instead ✨
  • --path PATH β€” mounts the Rails application at the given PATH (instead of "/"). this is equivalent to setting the RAILS_RELATIVE_URL_ROOT environment 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 a LINE of 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 $DEBUG variable is set to true. for Rails >= 2.3.x, this loads the Rails::Rack::Debugger middleware πŸ›
  • -w, --warn β€” turn on verbose warnings, the $VERBOSE variable is set to true. it's giving "tell me everything" πŸ“’
  • -I, --include PATH β€” specify $LOAD_PATH. PATH will 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_PATH take place immediately and in the order they were specified on the command-line 🌈
  • -r, --require LIBRARY β€” require a specified LIBRARY before 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. See Unicorn::Util.reopen_logs for what is considered a log πŸ“œ
  • USR2 β€” reexecute the running binary. a separate QUIT should 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 πŸ‘€


πŸ’– 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