tests: replace non-portable "date +%s" with ruby equivalent
[rainbows.git] / SIGNALS
blob7b61172943c48410105e7af916c45422d417aa98
1 == Signal handling
3 In general, signals need only be sent to the master process.  However,
4 the signals Rainbows! 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 and {nginx}[http://nginx.net/]
7 so it should be possible to easily share process management scripts
8 between \Rainbows!, Unicorn and nginx.
10 === Master Process
12 * HUP - reload config file, app, and gracefully restart all workers
14 * INT/TERM - quick shutdown, kills all workers immediately
16 * QUIT - graceful shutdown, waits for workers to finish their
17   current request before finishing.  This currently does not
18   wait for requests deferred to a separate thread when using
19   EventMachine (when app.deferred?(env) => true)
21 * USR1 - reopen all logs owned by the master and all workers
22   See Unicorn::Util.reopen_logs for what is considered a log.
24 * USR2 - reexecute the running binary.  A separate QUIT
25   should be sent to the original process once the child is verified to
26   be up and running.
28 * WINCH - gracefully stops workers but keep the master running.
29   This will only work for daemonized processes.
31 * TTIN - increment the number of worker processes by one
33 * TTOU - decrement the number of worker processes by one
35 === Worker Processes
37 Sending signals directly to the worker processes should not normally be
38 needed.  If the master process is running, any exited worker will be
39 automatically respawned.
41 * INT/TERM - Quick shutdown, immediately exit.
42   Unless WINCH has been sent to the master (or the master is killed),
43   the master process will respawn a worker to replace this one.
45 * QUIT - Gracefully exit after finishing the current request.
46   Unless WINCH has been sent to the master (or the master is killed),
47   the master process will respawn a worker to replace this one.
48   This currently does not wait for requests deferred to a separate
49   thread when using EventMachine (when app.deferred?(env) => true)
51 * USR1 - Reopen all logs owned by the worker process.
52   See Unicorn::Util.reopen_logs for what is considered a log.
53   Unlike Unicorn, log files are reopened immediately in \Rainbows!
54   since worker processes are likely to be serving multiple clients
55   simutaneously, we can't wait for all of them to finish.
57 === Procedure to replace a running rainbows executable
59 You may replace a running instance of rainbows with a new one without
60 losing any incoming connections.  Doing so will reload all of your
61 application code, Unicorn/Rainbows! config, Ruby executable, and all
62 libraries.  The only things that will not change (due to OS limitations)
63 are:
65 1. The path to the rainbows executable script.  If you want to change to
66    a different installation of Ruby, you can modify the shebang
67    line to point to your alternative interpreter.
69 The procedure is exactly like that of nginx:
71 1. Send USR2 to the master process
73 2. Check your process manager or pid files to see if a new master spawned
74    successfully.  If you're using a pid file, the old process will have
75    ".oldbin" appended to its path.  You should have two master instances
76    of rainbows running now, both of which will have workers servicing
77    requests.  Your process tree should look something like this:
79      rainbows master (old)
80      \_ rainbows worker[0]
81      \_ rainbows worker[1]
82      \_ rainbows worker[2]
83      \_ rainbows worker[3]
84      \_ rainbows master
85         \_ rainbows worker[0]
86         \_ rainbows worker[1]
87         \_ rainbows worker[2]
88         \_ rainbows worker[3]
90 3. You can now send WINCH to the old master process so only the new workers
91    serve requests.  If your rainbows process is bound to an
92    interactive terminal, you can skip this step.  Step 5 will be more
93    difficult but you can also skip it if your process is not daemonized.
95 4. You should now ensure that everything is running correctly with the
96    new workers as the old workers die off.
98 5. If everything seems ok, then send QUIT to the old master.  You're done!
100    If something is broken, then send HUP to the old master to reload
101    the config and restart its workers.  Then send QUIT to the new master
102    process.