test_socket_helper: disable GC for this test
[unicorn.git] / SIGNALS
blobfc0fa31eab386ed104fb38faf82a0e7c83349892
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.
7 === Master Process
9  * HUP - reload config file and gracefully restart all workers
10    If "preload_app" is false (the default), the application code
11    will be reloaded when workers are restarted as well.
13  * INT/TERM - quick shutdown, kills all workers immediately
15  * QUIT - graceful shutdown, waits for workers to finish their
16    current request before finishing.
18  * USR1 - reopen all logs owned by the master and all workers
19    See Unicorn::Util.reopen_logs for what is considered a log.
21  * USR2 - reexecute the running binary.  A separate QUIT
22    should be sent to the original process once the child is verified to
23    be up and running.
25  * WINCH - gracefully stops workers but keep the master running.
26    This will only work for daemonized processes.
28 === Worker Processes
30 Sending signals directly to the worker processes should not normally be
31 needed.  If the master process is running, any exited worker will be
32 automatically respawned.
34  * INT/TERM - Quick shutdown, immediately exit.
35    Unless WINCH has been sent to the master (or the master is killed),
36    the master process will respawn a worker to replace this one.
38  * QUIT - Gracefully exit after finishing the current request.
39    Unless WINCH has been sent to the master (or the master is killed),
40    the master process will respawn a worker to replace this one.
42  * USR1 - Reopen all logs owned by the worker process.
43    See Unicorn::Util.reopen_logs for what is considered a log.
44    Log files are not reopened until it is done processing
45    the current request, so multiple log lines for one request
46    (as done by Rails) will not be split across multiple logs.
48 === Procedure to replace a running unicorn executable
50 You may replace a running instance of unicorn with a new one without
51 losing any incoming connections.  Doing so will reload all of your
52 application code, Unicorn config, Ruby executable, and all libraries.
53 The only things that will not change (due to OS limitations) are:
55 1. The listener backlog size of already-bound sockets
57 2. The path to the unicorn executable script.  If you want to change to
58    a different installation of Ruby, you can modify the shebang
59    line to point to your alternative interpreter.
61 The procedure is exactly like that of nginx:
63 1. Send USR2 to the master process
65 2. Check your process manager or pid files to see if a new master spawned
66    successfully.  If you're using a pid file, the old process will have
67    ".oldbin" appended to its path.  You should have two master instances
68    of unicorn running now, both of which will have workers servicing
69    requests.  Your process tree should look something like this:
71      unicorn master (old)
72      \_ unicorn worker[0]
73      \_ unicorn worker[1]
74      \_ unicorn worker[2]
75      \_ unicorn worker[3]
76      \_ unicorn master
77         \_ unicorn worker[0]
78         \_ unicorn worker[1]
79         \_ unicorn worker[2]
80         \_ unicorn worker[3]
82 3. You can now send WINCH to the old master process so only the new workers
83    serve requests.  If your unicorn process is bound to an interactive
84    terminal, you can skip this step.  Step 5 will be more difficult but
85    you can also skip it if your process is not daemonized.
87 4. You should now ensure that everything is running correctly with the
88    new workers as the old workers die off.
90 5. If everything seems ok, then send QUIT to the old master.  You're done!
92    If something is broken, then send HUP to the old master to reload
93    the config and restart its workers.  Then send QUIT to the new master
94    process.