Skip to content

Commit 4a3aa54

Browse files
committed
Explicit support for Restart.
1 parent 990f2d3 commit 4a3aa54

File tree

5 files changed

+20
-6
lines changed

5 files changed

+20
-6
lines changed

guides/getting-started/readme.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ controller.run
7474

7575
## Signal Handling
7676

77+
`SIGINT` is the reload signal. You may send this to a program to request that it reload its configuration. The default behavior is to gracefully reload the container.
78+
7779
`SIGINT` is the interrupt signal. The terminal sends it to the foreground process when the user presses **ctrl-c**. The default behavior is to terminate the process, but it can be caught or ignored. The intention is to provide a mechanism for an orderly, graceful shutdown.
7880

7981
`SIGQUIT` is the dump core signal. The terminal sends it to the foreground process when the user presses **ctrl-\\**. The default behavior is to terminate the process and dump core, but it can be caught or ignored. The intention is to provide a mechanism for the user to abort the process. You can look at `SIGINT` as "user-initiated happy termination" and `SIGQUIT` as "user-initiated unhappy termination."

lib/async/container/controller.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,18 +219,18 @@ def run
219219

220220
interrupt_action = Signal.trap(:INT) do
221221
# We use `Thread.current.raise(...)` so that exceptions are filtered through `Thread.handle_interrupt` correctly.
222-
# $stderr.puts "Received Interrupt signal, terminating...", caller
222+
# $stderr.puts "Received INT signal, interrupting...", caller
223223
::Thread.current.raise(Interrupt)
224224
end
225225

226226
terminate_action = Signal.trap(:TERM) do
227-
# $stderr.puts "Received Terminate signal, terminating...", caller
227+
# $stderr.puts "Received TERM signal, terminating...", caller
228228
::Thread.current.raise(Terminate)
229229
end
230230

231231
hangup_action = Signal.trap(:HUP) do
232-
# $stderr.puts "Received Hangup signal, restarting...", caller
233-
::Thread.current.raise(Hangup)
232+
# $stderr.puts "Received HUP signal, restarting...", caller
233+
::Thread.current.raise(Restart)
234234
end
235235

236236
::Thread.handle_interrupt(SignalException => :never) do

lib/async/container/error.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def initialize
1919
end
2020
end
2121

22-
class Hangup < SignalException
22+
class Restart < SignalException
2323
SIGHUP = Signal.list["HUP"]
2424

2525
def initialize

lib/async/container/process.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def self.fork(**options)
6868
# We use `Thread.current.raise(...)` so that exceptions are filtered through `Thread.handle_interrupt` correctly.
6969
Signal.trap(:INT) {::Thread.current.raise(Interrupt)}
7070
Signal.trap(:TERM) {::Thread.current.raise(Terminate)}
71-
Signal.trap(:HUP) {::Thread.current.raise(Hangup)}
71+
Signal.trap(:HUP) {::Thread.current.raise(Restart)}
7272

7373
# This could be a configuration option:
7474
::Thread.handle_interrupt(SignalException => :immediate) do
@@ -153,6 +153,13 @@ def terminate!
153153
end
154154
end
155155

156+
# Send `SIGHUP` to the child process.
157+
def restart!
158+
unless @status
159+
::Process.kill(:HUP, @pid)
160+
end
161+
end
162+
156163
# Wait for the child process to exit.
157164
# @asynchronous This method may block.
158165
#

lib/async/container/thread.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,11 @@ def terminate!
152152
@thread.raise(Terminate)
153153
end
154154

155+
# Raise {Restart} in the child thread.
156+
def restart!
157+
@thread.raise(Restart)
158+
end
159+
155160
# Wait for the thread to exit and return he exit status.
156161
# @returns [Status]
157162
def wait

0 commit comments

Comments
 (0)