-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfile.signals.html
159 lines (120 loc) · 10 KB
/
file.signals.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<!DOCTYPE html>
<html>
<head>
<meta charset='UTF-8'>
<meta name='viewport' content='width=device-width, initial-scale=1.0, user-scalable=no'>
<meta name='apple-touch-fullscreen' content='yes'>
<meta name='apple-mobile-web-app-capable' content='yes'>
<meta name='apple-mobile-web-app-status-bar-style' content='rgba(228,228,228,1.0)'>
<title>File: Signals — Puma master</title>
<link rel='stylesheet' type='text/css' href='../css/y_fonts.css' />
<link rel='stylesheet' type='text/css' href='../css/highlight.github.css' />
<link rel='stylesheet' type='text/css' href='../css/y_style.css' />
<link rel='stylesheet' type='text/css' href='../css/y_list.css' />
<link rel='stylesheet' type='text/css' href='../css/y_color.css' />
<script type='text/javascript'>
var pathId = "signals",
relpath = '';
var t2Info = {
CSEP: '.',
ISEP: '#',
NSEP: '::'
};
</script>
<script type='text/javascript' charset='utf-8' src='../js/highlight.pack.js'></script>
<script type='text/javascript' charset='utf-8' src='../js/y_app.js'></script>
</head>
<body>
<svg id='y_wait' class viewBox='0 0 90 90'></svg>
<div id='settings' class='hidden'></div>
<div id='y_list' class='d h'>
<header id='list_header'></header>
<nav id= 'list_nav' class='y_nav l_nav'>
<ul id='list_items'></ul>
</nav>
</div>
<div id='y_toc' class='f h'>
<header id='toc_header'></header>
<nav id= 'toc_nav' class='y_nav t_nav'>
<ol id='toc_items'></ol>
</nav>
</div>
<div id='y_main' tabindex='-1'>
<header id='y_header'>
<div id='y_menu'>
<a id='home_no_xhr' href='/'>Home</a> »
<a href='.'>Puma master</a> »
<a href='_index.html'>Index</a> »
<span class='title'><a id='t2_doc_top' href='#'>File: Signals ▲</a></span>
</div>
<a id='list_href' href="class_list.html"></a>
<div id='y_measure_em' class='y_measure'></div>
<div id='y_measure_vh' class='y_measure'></div>
<span id='y_measure_50pre' class='y_measure'><code>123456789_123456789_123456789_123456789_123456789_</code></span>
</header>
<div id='content' class='file'>
<p>The <a href="https://en.wikipedia.org/wiki/Unix_signal">unix signal</a> is a method of sending messages between <a href="https://en.wikipedia.org/wiki/Process_(computing)">processes</a>. When a signal is sent, the operating system interrupts the target process's normal flow of execution. There are standard signals that are used to stop a process, but there are also custom signals that can be used for other purposes. This document is an attempt to list all supported signals that <a href="Puma.html" title="Puma (module)"><code>Puma</code></a> will respond to. In general, signals need only be sent to the master process of a cluster.</p>
<h2>Sending Signals</h2>
<p>If you are new to signals, it can be helpful to see how they are used. When a process starts in a *nix-like operating system, it will have a <a href="https://en.wikipedia.org/wiki/Process_identifier">PID - or process identifier</a> that can be used to send signals to the process. For demonstration, we will create an infinitely running process by tailing a file:</p>
<pre class="code sh"><code class="sh">$ echo "foo" >> my.log
$ irb
> pid = Process.spawn 'tail -f my.log'
</code></pre>
<p>From here, we can see that the tail process is running by using the <code>ps</code> command:</p>
<pre class="code sh"><code class="sh">$ ps aux | grep tail
schneems 87152 0.0 0.0 2432772 492 s032 S+ 12:46PM 0:00.00 tail -f my.log
</code></pre>
<p>You can send a signal in Ruby using the <a href="https://ruby-doc.org/3.2.2/Process.html#method-c-kill">Process module</a>:</p>
<pre class="code ruby"><code class="ruby"><span class='gvar'>$ </span><span class='id identifier rubyid_irb'>irb</span>
<span class='op'>></span> <span class='id identifier rubyid_puts'>puts</span> <span class='id identifier rubyid_pid'>pid</span>
<span class='comment'>#=> 87152
</span><span class='const'>Process</span>.<span class='id identifier rubyid_detach'>detach</span>(<span class='id identifier rubyid_pid'>pid</span>) <span class='comment'># https://ruby-doc.org/3.2.2/Process.html#method-c-detach
</span><span class='const'>Process</span>.<span class='id identifier rubyid_kill'>kill</span>(<span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>TERM</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='id identifier rubyid_pid'>pid</span>)</code></pre>
<p>Now you will see via <code>ps</code> that there is no more <code>tail</code> process. Sometimes when referring to signals, the <code>SIG</code> prefix will be used. For example, <code>SIGTERM</code> is equivalent to sending <code>TERM</code> via <code>Process.kill</code>.</p>
<h2>Puma Signals</h2>
<p>Puma cluster responds to these signals:</p>
<ul>
<li><code>TTIN</code> increment the worker count by 1</li>
<li><code>TTOU</code> decrement the worker count by 1</li>
<li><code>TERM</code> send <code>TERM</code> to worker. The worker will attempt to finish then exit.</li>
<li><code>USR2</code> restart workers. This also reloads the Puma configuration file, if there is one.</li>
<li><code>USR1</code> restart workers in phases, a rolling restart. This will not reload the configuration file.</li>
<li><code>HUP</code> reopen log files defined in stdout_redirect configuration parameter. If there is no stdout_redirect option provided, it will behave like <code>INT</code></li>
<li><code>INT</code> equivalent of sending Ctrl-C to cluster. Puma will attempt to finish then exit.</li>
<li><code>CHLD</code></li>
<li><code>URG</code> refork workers in phases from worker 0 if <code>fork_workers</code> option is enabled.</li>
<li><code>INFO</code> print backtraces of all puma threads</li>
</ul>
<h2>Callbacks order in case of different signals</h2>
<h3>Start application</h3>
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_puma'>puma</span> <span class='id identifier rubyid_configuration'>configuration</span> <span class='id identifier rubyid_file'>file</span> <span class='id identifier rubyid_reloaded'>reloaded</span><span class='comma'>,</span> <span class='kw'>if</span> <span class='id identifier rubyid_there'>there</span> <span class='id identifier rubyid_is'>is</span> <span class='id identifier rubyid_one'>one</span>
<span class='op'>*</span> <span class='const'>Pruning</span> <span class='const'>Bundler</span> <span class='id identifier rubyid_environment'>environment</span>
<span class='id identifier rubyid_puma'>puma</span> <span class='id identifier rubyid_configuration'>configuration</span> <span class='id identifier rubyid_file'>file</span> <span class='id identifier rubyid_reloaded'>reloaded</span><span class='comma'>,</span> <span class='kw'>if</span> <span class='id identifier rubyid_there'>there</span> <span class='id identifier rubyid_is'>is</span> <span class='id identifier rubyid_one'>one</span>
<span class='id identifier rubyid_before_fork'>before_fork</span>
<span class='id identifier rubyid_on_worker_fork'>on_worker_fork</span>
<span class='id identifier rubyid_after_worker_fork'>after_worker_fork</span>
<span class='const'>Gemfile</span> <span class='kw'>in</span> <span class='id identifier rubyid_context'>context</span>
<span class='id identifier rubyid_on_worker_boot'>on_worker_boot</span>
<span class='const'>Code</span> <span class='id identifier rubyid_of'>of</span> <span class='id identifier rubyid_the'>the</span> <span class='id identifier rubyid_app'>app</span> <span class='id identifier rubyid_is'>is</span> <span class='id identifier rubyid_loaded'>loaded</span> <span class='kw'>and</span> <span class='id identifier rubyid_running'>running</span></code></pre>
<h3>Send USR2</h3>
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_on_worker_shutdown'>on_worker_shutdown</span>
<span class='id identifier rubyid_on_restart'>on_restart</span>
<span class='id identifier rubyid_puma'>puma</span> <span class='id identifier rubyid_configuration'>configuration</span> <span class='id identifier rubyid_file'>file</span> <span class='id identifier rubyid_reloaded'>reloaded</span><span class='comma'>,</span> <span class='kw'>if</span> <span class='id identifier rubyid_there'>there</span> <span class='id identifier rubyid_is'>is</span> <span class='id identifier rubyid_one'>one</span>
<span class='id identifier rubyid_before_fork'>before_fork</span>
<span class='id identifier rubyid_on_worker_fork'>on_worker_fork</span>
<span class='id identifier rubyid_after_worker_fork'>after_worker_fork</span>
<span class='const'>Gemfile</span> <span class='kw'>in</span> <span class='id identifier rubyid_context'>context</span>
<span class='id identifier rubyid_on_worker_boot'>on_worker_boot</span>
<span class='const'>Code</span> <span class='id identifier rubyid_of'>of</span> <span class='id identifier rubyid_the'>the</span> <span class='id identifier rubyid_app'>app</span> <span class='id identifier rubyid_is'>is</span> <span class='id identifier rubyid_loaded'>loaded</span> <span class='kw'>and</span> <span class='id identifier rubyid_running'>running</span></code></pre>
<h3>Send USR1</h3>
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_on_worker_shutdown'>on_worker_shutdown</span>
<span class='id identifier rubyid_on_worker_fork'>on_worker_fork</span>
<span class='id identifier rubyid_after_worker_fork'>after_worker_fork</span>
<span class='const'>Gemfile</span> <span class='kw'>in</span> <span class='id identifier rubyid_context'>context</span>
<span class='id identifier rubyid_on_worker_boot'>on_worker_boot</span>
<span class='const'>Code</span> <span class='id identifier rubyid_of'>of</span> <span class='id identifier rubyid_the'>the</span> <span class='id identifier rubyid_app'>app</span> <span class='id identifier rubyid_is'>is</span> <span class='id identifier rubyid_loaded'>loaded</span> <span class='kw'>and</span> <span class='id identifier rubyid_running'>running</span></code></pre>
<div id='footer'></div>
</div> <!-- content -->
</div> <!-- y_main -->
</body>
</html>