UNICORN(1)

πŸ“¦
version 6.1.0+git.20250131.1370f52 Β· 2 versions
, in debian trixie, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’– UNICORN(1) β€” the unicorn command, bestie edition πŸ’–

okay so hi, welcome to unicorn(1), the manual page for unicorn β€” a rackup-like command that launches the Unicorn HTTP server. sit down, grab a boba, we're gonna get you fully caught up. ✨


🌸 NAME 🌸

unicorn β€” a rackup-like command to launch the Unicorn HTTP server. that's it, that's the whole name section, she's brief but she's iconic. πŸ’…


πŸ¦‹ SYNOPSIS πŸ¦‹

unicorn [-c CONFIG_FILE] [-E RACK_ENV] [-D] [RACKUP_FILE]

like, that's the vibe. those are the options you actually want. πŸ‘‘


✨ DESCRIPTION ✨

okay so unicorn is a rackup(1)-like command that launches Rack applications using Unicorn. you're expected to start it in your application root, aka APP_ROOT β€” that's the whole point β€” but ngl you can use the working_directory directive inside your CONFIG_FILE if you wanna be extra about it. 🫢

and here's the thing: while unicorn takes a myriad of command-line options for compatibility with ruby(1) and rackup(1), the actual recommendation β€” like, the advice, the moment of clarity β€” is to stick to the few command-line options in the SYNOPSIS and use the CONFIG_FILE as much as possible. the flags are there, but the config file is the main character. periodt. πŸ’–


πŸŽ€ RACKUP FILE πŸŽ€

this defaults to "config.ru" in APP_ROOT. it should be the same file that rackup(1) and other Rack launchers use β€” it uses the Rack::Builder DSL. so like, same file, same energy, no notes. 🌈

embedded command-line options are mostly parsed for compatibility with rackup(1) but they're strongly discouraged. not me telling you to keep those out of your life πŸ™ˆ β€” i literally am, don't do it.


πŸ’… UNICORN OPTIONS πŸ’…

  • -c, --config-file CONFIG_FILE β€” the path to your Unicorn-specific config file. bestie, this config file is implemented as a Ruby DSL, so Ruby code may be executed in there. for the full list of directives available from the DSL, go read the RDoc/ri for the Unicorn::Configurator class. and using an absolute path for CONFIG_FILE is recommended, because it makes multiple instances of Unicorn easily distinguishable when you're staring at ps(1) output. trust. πŸ‘‘
  • -D, --daemonize β€” run daemonized in the background. the process is detached from the controlling terminal and stdin is redirected to "/dev/null". and here's a lil fun fact: unlike many common UNIX daemons, we do not chdir to "/" upon daemonization, because that allows more control over the startup/upgrade process. unless it's specified in the CONFIG_FILE, stderr and stdout will also be redirected to "/dev/null". πŸ•³οΈ
  • -E, --env RACK_ENV β€” run under the given RACK_ENV. see the RACK ENVIRONMENT section for more details. slay. ✨
  • -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. πŸ”₯
  • -N, --no-default-middleware β€” disables loading middleware implied by RACK_ENV. this bypasses the configuration documented in the RACK ENVIRONMENT section, but still allows RACK_ENV to be used for application/framework-specific purposes. so it's not useless, it's just minding its own business. πŸ’œ

🌟 RACKUP COMPATIBILITY OPTIONS 🌟

these exist for the rackup girlies. use them if you must, but the -l/--listen switch is the recommended one, ok? 🫢

  • -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, and use of the "-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, and use of the "-l"/"--listen" switch is recommended instead. same energy as above, fr fr.
  • -s, --server SERVER β€” no-op. this exists only for compatibility with rackup(1). it does literally nothing and honestly? respect. πŸ’€

πŸ“ RUBY OPTIONS πŸ“

  • -e, --eval LINE β€” evaluate a LINE of Ruby code. this evaluation happens immediately as the command-line is being parsed. like, mid-parse. instant. ⚑
  • -d, --debug β€” turn on debug mode, the $DEBUG variable is set to true.
  • -w, --warn β€” turn on verbose warnings, the $VERBOSE variable is set to true. she's chatty and that's the point.
  • -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. order matters, bestie, don't play. 🌸
  • -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. πŸ’–

🧚 SIGNALS 🧚

the following UNIX signals may be sent to the master process. take notes, this section is the drama:

  • 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. 🫑


🌈 RACK ENVIRONMENT 🌈

the accepted values of RACK_ENV and the middleware they automatically load (outside of RACKUP_FILE) are exactly as those in rackup(1):

  • development β€” loads Rack::CommonLogger, Rack::ShowExceptions, and Rack::Lint middleware
  • deployment β€” loads Rack::CommonLogger middleware
  • none β€” loads no middleware at all, relying entirely on RACKUP_FILE

all unrecognized values for RACK_ENV are assumed to be "none". production deployments are strongly encouraged to use "deployment" or "none" for maximum performance. do it for the speed. πŸ”₯

as of Unicorn 0.94.0, RACK_ENV is exported as a process-wide environment variable as well. while not current a part of the Rack specification as of Rack 1.0.1, this has become a de facto standard in the Rack world. iconic behavior honestly. πŸ‘‘

note the Rack::ContentLength middleware is also loaded by "deployment" and "development", but no other values of RACK_ENV. if needed, they must be individually specified in the RACKUP_FILE, some frameworks do not require them.

🐚 ENVIRONMENT VARIABLES 🐚

the RACK_ENV variable is set by the aforementioned -E switch. all application or library-specific environment variables (e.g. TMPDIR) 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. πŸ¦‹

UNICORN_FD is a comma-delimited list of one or more file descriptors used to implement USR2 upgrades. init systems may bind listen sockets itself and spawn unicorn with UNICORN_FD set to the file descriptor numbers of the listen socket(s). ✨

as of unicorn 5.0, LISTEN_PID and LISTEN_FDS are used for socket activation as documented in the sd_listen_fds(3) manpage. users relying on this feature do not need to specify a listen socket in the unicorn config file. you don't gotta configure a thing, she just shows up. πŸ’…


πŸ‘€ SEE ALSO πŸ‘€


🫢 AUTHORS 🫢

The Unicorn Community <unicorn-public@yhbt.net>.


and that's the whole thing, bestie. no cap. πŸ’–

Unicorn User Manual β€” September 15, 2009 β€” UNICORN(1) πŸ¦„βœ¨ mwah, go launch something beautiful πŸ’‹

πŸ“¦ where this page comes from