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
12a9362f
Commit
12a9362f
authored
Jun 03, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
packer/plugin: Swallow interrupts in plugins
parent
3956b3a5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
0 deletions
+18
-0
packer/plugin/plugin.go
packer/plugin/plugin.go
+18
-0
No files found.
packer/plugin/plugin.go
View file @
12a9362f
...
@@ -15,6 +15,7 @@ import (
...
@@ -15,6 +15,7 @@ import (
"net"
"net"
"net/rpc"
"net/rpc"
"os"
"os"
"os/signal"
"strconv"
"strconv"
"strings"
"strings"
)
)
...
@@ -75,6 +76,19 @@ func serve(server *rpc.Server) (err error) {
...
@@ -75,6 +76,19 @@ func serve(server *rpc.Server) (err error) {
return
return
}
}
// Registers a signal handler to "swallow" interrupts so that the
// plugin isn't killed. The main host Packer process is responsible
// for killing the plugins when interrupted.
func
swallowInterrupts
()
{
ch
:=
make
(
chan
os
.
Signal
,
1
)
signal
.
Notify
(
ch
,
os
.
Interrupt
)
go
func
()
{
<-
ch
log
.
Println
(
"Received interrupt signal. Ignoring."
)
}()
}
// Serves a builder from a plugin.
// Serves a builder from a plugin.
func
ServeBuilder
(
builder
packer
.
Builder
)
{
func
ServeBuilder
(
builder
packer
.
Builder
)
{
log
.
Println
(
"Preparing to serve a builder plugin..."
)
log
.
Println
(
"Preparing to serve a builder plugin..."
)
...
@@ -82,6 +96,7 @@ func ServeBuilder(builder packer.Builder) {
...
@@ -82,6 +96,7 @@ func ServeBuilder(builder packer.Builder) {
server
:=
rpc
.
NewServer
()
server
:=
rpc
.
NewServer
()
packrpc
.
RegisterBuilder
(
server
,
builder
)
packrpc
.
RegisterBuilder
(
server
,
builder
)
swallowInterrupts
()
if
err
:=
serve
(
server
);
err
!=
nil
{
if
err
:=
serve
(
server
);
err
!=
nil
{
log
.
Panic
(
err
)
log
.
Panic
(
err
)
}
}
...
@@ -94,6 +109,7 @@ func ServeCommand(command packer.Command) {
...
@@ -94,6 +109,7 @@ func ServeCommand(command packer.Command) {
server
:=
rpc
.
NewServer
()
server
:=
rpc
.
NewServer
()
packrpc
.
RegisterCommand
(
server
,
command
)
packrpc
.
RegisterCommand
(
server
,
command
)
swallowInterrupts
()
if
err
:=
serve
(
server
);
err
!=
nil
{
if
err
:=
serve
(
server
);
err
!=
nil
{
log
.
Panic
(
err
)
log
.
Panic
(
err
)
}
}
...
@@ -106,6 +122,7 @@ func ServeHook(hook packer.Hook) {
...
@@ -106,6 +122,7 @@ func ServeHook(hook packer.Hook) {
server
:=
rpc
.
NewServer
()
server
:=
rpc
.
NewServer
()
packrpc
.
RegisterHook
(
server
,
hook
)
packrpc
.
RegisterHook
(
server
,
hook
)
swallowInterrupts
()
if
err
:=
serve
(
server
);
err
!=
nil
{
if
err
:=
serve
(
server
);
err
!=
nil
{
log
.
Panic
(
err
)
log
.
Panic
(
err
)
}
}
...
@@ -118,6 +135,7 @@ func ServeProvisioner(p packer.Provisioner) {
...
@@ -118,6 +135,7 @@ func ServeProvisioner(p packer.Provisioner) {
server
:=
rpc
.
NewServer
()
server
:=
rpc
.
NewServer
()
packrpc
.
RegisterProvisioner
(
server
,
p
)
packrpc
.
RegisterProvisioner
(
server
,
p
)
swallowInterrupts
()
if
err
:=
serve
(
server
);
err
!=
nil
{
if
err
:=
serve
(
server
);
err
!=
nil
{
log
.
Panic
(
err
)
log
.
Panic
(
err
)
}
}
...
...
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