Process management cleanups
[unicorn.git] / SIGNALS
blobb1a3141a6037cd8aa298a6001942500641755b17
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
36  * QUIT - gracefully exit after finishing the current request
38  * USR1 - reopen all logs owned by the worker process
39    See Unicorn::Util.reopen_logs for what is considered a log.
41 === Procedure to replace a running unicorn executable
43 You may replace a running instance of unicorn with a new one without
44 losing any incoming connections.  Doing so will reload all of your
45 application code, Unicorn config, Ruby executable, and all libraries.
46 The only things that will not change (due to OS limitations) are:
48 1. The listener backlog size of already-bound sockets
50 2. The path to the unicorn executable script.  If you want to change to
51    a different installation of Ruby, you can modify the shebang
52    line to point to your alternative interpreter.
54 The procedure is exactly like that of nginx:
56 1. Send USR2 to the master process
58 2. Check your process manager or pid files to see if a new master spawned
59    successfully.  If you're using a pid file, the old process will have
60    ".oldbin" appended to its path.  You should have two master instances
61    of unicorn running now, both of which will have workers servicing
62    requests.  Your process tree should look something like this:
64    unicorn master (old)
65    \_ unicorn worker[0]
66    \_ unicorn worker[1]
67    \_ unicorn worker[2]
68    \_ unicorn worker[3]
69    \_ unicorn master
70       \_ unicorn worker[0]
71       \_ unicorn worker[1]
72       \_ unicorn worker[2]
73       \_ unicorn worker[3]
75 4. You can now send WINCH to the old master process so only the new workers
76    serve requests.  If your unicorn process is bound to an interactive
77    terminal, you can skip this step.  Step 5 will be more difficult but
78    you can also skip it if your process is not daemonized.
80 5. You should now ensure that everything is running correctly with the
81    new workers as the old workers die off.
83 6a. If everything seems ok, then send QUIT to the old master.  You're done!
85 6b. If something is broken, then send HUP to the old master to reload
86     the config and restart its workers.  Then send QUIT to the new master
87     process.