fix const error responses for Rainbows!
[unicorn.git] / SIGNALS
blob88517752bf1b7771ba5f99a7ccbc05d7207c9d08
1 == Signal handling
3 In general, signals need only be sent to the master process.  However,
4 the signals Unicorn uses internally to communicate with the worker
5 processes are documented here as well.  With the exception of TTIN/TTOU,
6 signal handling matches the behavior of {nginx}[http://nginx.net/] so it
7 should be possible to easily share process management scripts between
8 Unicorn and nginx.
10 === Master Process
12 * HUP - reloads config file and gracefully restart all workers.
13   If the "preload_app" directive is false (the default), then workers
14   will also pick up any application code changes when restarted.  If
15   "preload_app" is true, then application code changes will have no
16   effect; USR2 + QUIT (see below) must be used to load newer code in
17   this case.  When reloading the application, +Gem.refresh+ will
18   be called so updated code for your application can pick up newly
19   installed RubyGems.  It is not recommended that you uninstall
20   libraries your application depends on while Unicorn is running,
21   as respawned workers may enter a spawn loop when they fail to
22   load an uninstalled dependency.
24 * INT/TERM - quick shutdown, kills all workers immediately
26 * QUIT - graceful shutdown, waits for workers to finish their
27   current request before finishing.
29 * USR1 - reopen all logs owned by the master and all workers
30   See Unicorn::Util.reopen_logs for what is considered a log.
32 * USR2 - reexecute the running binary.  A separate QUIT
33   should be sent to the original process once the child is verified to
34   be up and running.
36 * WINCH - gracefully stops workers but keep the master running.
37   This will only work for daemonized processes.
39 * TTIN - increment the number of worker processes by one
41 * TTOU - decrement the number of worker processes by one
43 === Worker Processes
45 Sending signals directly to the worker processes should not normally be
46 needed.  If the master process is running, any exited worker will be
47 automatically respawned.
49 * INT/TERM - Quick shutdown, immediately exit.
50   Unless WINCH has been sent to the master (or the master is killed),
51   the master process will respawn a worker to replace this one.
53 * QUIT - Gracefully exit after finishing the current request.
54   Unless WINCH has been sent to the master (or the master is killed),
55   the master process will respawn a worker to replace this one.
57 * USR1 - Reopen all logs owned by the worker process.
58   See Unicorn::Util.reopen_logs for what is considered a log.
59   Log files are not reopened until it is done processing
60   the current request, so multiple log lines for one request
61   (as done by Rails) will not be split across multiple logs.
63   It is NOT recommended to send the USR1 signal directly to workers via
64   "killall -USR1 unicorn" if you are using user/group-switching support
65   in your workers.  You will encounter incorrect file permissions and
66   workers will need to be respawned.  Sending USR1 to the master process
67   first will ensure logs have the correct permissions before the master
68   forwards the USR1 signal to workers.
70 === Procedure to replace a running unicorn executable
72 You may replace a running instance of unicorn with a new one without
73 losing any incoming connections.  Doing so will reload all of your
74 application code, Unicorn config, Ruby executable, and all libraries.
75 The only things that will not change (due to OS limitations) are:
77 1. The path to the unicorn executable script.  If you want to change to
78    a different installation of Ruby, you can modify the shebang
79    line to point to your alternative interpreter.
81 The procedure is exactly like that of nginx:
83 1. Send USR2 to the master process
85 2. Check your process manager or pid files to see if a new master spawned
86    successfully.  If you're using a pid file, the old process will have
87    ".oldbin" appended to its path.  You should have two master instances
88    of unicorn running now, both of which will have workers servicing
89    requests.  Your process tree should look something like this:
91      unicorn master (old)
92      \_ unicorn worker[0]
93      \_ unicorn worker[1]
94      \_ unicorn worker[2]
95      \_ unicorn worker[3]
96      \_ unicorn master
97         \_ unicorn worker[0]
98         \_ unicorn worker[1]
99         \_ unicorn worker[2]
100         \_ unicorn worker[3]
102 3. You can now send WINCH to the old master process so only the new workers
103    serve requests.  If your unicorn process is bound to an interactive
104    terminal, you can skip this step.  Step 5 will be more difficult but
105    you can also skip it if your process is not daemonized.
107 4. You should now ensure that everything is running correctly with the
108    new workers as the old workers die off.
110 5. If everything seems ok, then send QUIT to the old master.  You're done!
112    If something is broken, then send HUP to the old master to reload
113    the config and restart its workers.  Then send QUIT to the new master
114    process.