UNICORN(1)
π 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 theUnicorn::Configuratorclass. and using an absolute path forCONFIG_FILEis recommended, because it makes multiple instances of Unicorn easily distinguishable when you're staring atps(1)output. trust. π-D,--daemonizeβ run daemonized in the background. the process is detached from the controlling terminal andstdinis redirected to"/dev/null". and here's a lil fun fact: unlike many common UNIX daemons, we do notchdirto"/"upon daemonization, because that allows more control over the startup/upgrade process. unless it's specified in theCONFIG_FILE,stderrandstdoutwill also be redirected to"/dev/null". π³οΈ-E,--env RACK_ENVβ run under the givenRACK_ENV. see the RACK ENVIRONMENT section for more details. slay. β¨-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. π₯-N,--no-default-middlewareβ disables loading middleware implied byRACK_ENV. this bypasses the configuration documented in the RACK ENVIRONMENT section, but still allowsRACK_ENVto 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 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, and use of the"-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, 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 withrackup(1). it does literally nothing and honestly? respect. π
π RUBY OPTIONS π
-e,--eval LINEβ evaluate aLINEof Ruby code. this evaluation happens immediately as the command-line is being parsed. like, mid-parse. instant. β‘-d,--debugβ turn on debug mode, the$DEBUGvariable is set totrue.-w,--warnβ turn on verbose warnings, the$VERBOSEvariable is set totrue. she's chatty and that's the point.-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. order matters, bestie, don't play. πΈ-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. π
π§ 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 workersINT/TERMβ quick shutdown, kills all workers immediatelyQUITβ 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 oneTTOUβ 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β loadsRack::CommonLogger,Rack::ShowExceptions, andRack::Lintmiddlewaredeploymentβ loadsRack::CommonLoggermiddlewarenoneβ loads no middleware at all, relying entirely onRACKUP_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 theRack::ContentLengthmiddleware is also loaded by"deployment"and"development", but no other values ofRACK_ENV. if needed, they must be individually specified in theRACKUP_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 π
Rack::Builderri/RDocUnicorn::Configuratorri/RDoc https://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 thing, bestie. no cap. π
Unicorn User Manual β September 15, 2009 β UNICORN(1) π¦β¨ mwah, go launch something beautiful π
π¦ where this page comes from
- debian trixie: unicorn 6.1.0+git.20250131.1370f52-1+b1 Β· 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