Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
beego
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
beego
Commits
eb50221a
Commit
eb50221a
authored
Dec 06, 2016
by
Faissal Elamraoui
Committed by
Faissal Elamraoui
Dec 06, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added method to register Pre/Post signal handlers
parent
fc480149
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
3 deletions
+17
-3
server.go
grace/server.go
+17
-3
No files found.
grace/server.go
View file @
eb50221a
...
...
@@ -162,9 +162,7 @@ func (srv *Server) handleSignals() {
signal
.
Notify
(
srv
.
sigChan
,
syscall
.
SIGHUP
,
syscall
.
SIGINT
,
syscall
.
SIGTERM
,
hookableSignals
...
,
)
pid
:=
syscall
.
Getpid
()
...
...
@@ -290,3 +288,19 @@ func (srv *Server) fork() (err error) {
return
}
// RegisterSignalHook registers a function to be run PreSignal or PostSignal for a given signal.
func
(
srv
*
Server
)
RegisterSignalHook
(
ppFlag
int
,
sig
os
.
Signal
,
f
func
())
(
err
error
)
{
if
ppFlag
!=
PreSignal
&&
ppFlag
!=
PostSignal
{
err
=
fmt
.
Errorf
(
"Invalid ppFlag argument. Must be either grace.PreSignal or grace.PostSignal."
)
return
}
for
_
,
s
:=
range
hookableSignals
{
if
s
==
sig
{
srv
.
SignalHooks
[
ppFlag
][
sig
]
=
append
(
srv
.
SignalHooks
[
ppFlag
][
sig
],
f
)
return
}
}
err
=
fmt
.
Errorf
(
"Signal '%v' is not supported."
,
sig
)
return
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment