Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
packer
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kristopher Ruzic
packer
Commits
893c9e02
Commit
893c9e02
authored
Aug 30, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
packer/plugin: Count number of interrupts atomically
parent
71379bc8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
8 deletions
+15
-8
packer/plugin/plugin.go
packer/plugin/plugin.go
+15
-8
No files found.
packer/plugin/plugin.go
View file @
893c9e02
...
...
@@ -19,8 +19,14 @@ import (
"os/signal"
"runtime"
"strconv"
"sync/atomic"
)
// This is a count of the number of interrupts the process has received.
// This is updated with sync/atomic whenever a SIGINT is received and can
// be checked by the plugin safely to take action.
var
Interrupts
int32
=
0
const
MagicCookieKey
=
"PACKER_PLUGIN_MAGIC_COOKIE"
const
MagicCookieValue
=
"d602bf8f470bc67ca7faa0386276bbdd4330efaf76d1a219cb4d6991ca9872b2"
...
...
@@ -86,17 +92,18 @@ func serve(server *rpc.Server) (err error) {
return
}
// Registers a signal handler to
"swallow"
interrupts so that the
// Registers a signal handler to
swallow and count
interrupts so that the
// plugin isn't killed. The main host Packer process is responsible
// for killing the plugins when interrupted.
func
swallow
Interrupts
()
{
func
count
Interrupts
()
{
ch
:=
make
(
chan
os
.
Signal
,
1
)
signal
.
Notify
(
ch
,
os
.
Interrupt
)
go
func
()
{
for
{
<-
ch
log
.
Println
(
"Received interrupt signal. Ignoring."
)
newCount
:=
atomic
.
AddInt32
(
&
Interrupts
,
1
)
log
.
Printf
(
"Received interrupt signal (count: %d). Ignoring."
,
newCount
)
}
}()
}
...
...
@@ -108,7 +115,7 @@ func ServeBuilder(builder packer.Builder) {
server
:=
rpc
.
NewServer
()
packrpc
.
RegisterBuilder
(
server
,
builder
)
swallow
Interrupts
()
count
Interrupts
()
if
err
:=
serve
(
server
);
err
!=
nil
{
log
.
Printf
(
"ERROR: %s"
,
err
)
os
.
Exit
(
1
)
...
...
@@ -122,7 +129,7 @@ func ServeCommand(command packer.Command) {
server
:=
rpc
.
NewServer
()
packrpc
.
RegisterCommand
(
server
,
command
)
swallow
Interrupts
()
count
Interrupts
()
if
err
:=
serve
(
server
);
err
!=
nil
{
log
.
Printf
(
"ERROR: %s"
,
err
)
os
.
Exit
(
1
)
...
...
@@ -136,7 +143,7 @@ func ServeHook(hook packer.Hook) {
server
:=
rpc
.
NewServer
()
packrpc
.
RegisterHook
(
server
,
hook
)
swallow
Interrupts
()
count
Interrupts
()
if
err
:=
serve
(
server
);
err
!=
nil
{
log
.
Printf
(
"ERROR: %s"
,
err
)
os
.
Exit
(
1
)
...
...
@@ -150,7 +157,7 @@ func ServePostProcessor(p packer.PostProcessor) {
server
:=
rpc
.
NewServer
()
packrpc
.
RegisterPostProcessor
(
server
,
p
)
swallow
Interrupts
()
count
Interrupts
()
if
err
:=
serve
(
server
);
err
!=
nil
{
log
.
Printf
(
"ERROR: %s"
,
err
)
os
.
Exit
(
1
)
...
...
@@ -164,7 +171,7 @@ func ServeProvisioner(p packer.Provisioner) {
server
:=
rpc
.
NewServer
()
packrpc
.
RegisterProvisioner
(
server
,
p
)
swallow
Interrupts
()
count
Interrupts
()
if
err
:=
serve
(
server
);
err
!=
nil
{
log
.
Printf
(
"ERROR: %s"
,
err
)
os
.
Exit
(
1
)
...
...
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