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
4c1873d1
Commit
4c1873d1
authored
Jun 14, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
command/build: Redo interrupt handling to be more robust
parent
ea01d7b2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
34 deletions
+21
-34
command/build/build.go
command/build/build.go
+0
-4
command/build/command.go
command/build/command.go
+21
-30
No files found.
command/build/build.go
deleted
100644 → 0
View file @
ea01d7b2
package
build
type
config
struct
{
}
command/build/command.go
View file @
4c1873d1
...
...
@@ -161,12 +161,28 @@ func (c Command) Run(env packer.Environment, args []string) int {
}
// Run all the builds in parallel and wait for them to complete
var
wg
sync
.
WaitGroup
var
interruptWg
,
wg
sync
.
WaitGroup
interrupted
:=
false
artifacts
:=
make
(
map
[
string
]
packer
.
Artifact
)
for
_
,
b
:=
range
builds
{
// Increment the waitgroup so we wait for this item to finish properly
wg
.
Add
(
1
)
// Handle interrupts for this build
sigCh
:=
make
(
chan
os
.
Signal
,
1
)
signal
.
Notify
(
sigCh
,
os
.
Interrupt
)
defer
signal
.
Stop
(
sigCh
)
go
func
(
b
packer
.
Build
)
{
<-
sigCh
interruptWg
.
Add
(
1
)
defer
interruptWg
.
Done
()
interrupted
=
true
log
.
Printf
(
"Stopping build: %s"
,
b
.
Name
())
b
.
Cancel
()
log
.
Printf
(
"Build cancelled: %s"
,
b
.
Name
())
}(
b
)
// Run the build in a goroutine
go
func
(
b
packer
.
Build
)
{
defer
wg
.
Done
()
...
...
@@ -187,37 +203,13 @@ func (c Command) Run(env packer.Environment, args []string) int {
log
.
Printf
(
"Debug enabled, so waiting for build to finish: %s"
,
b
.
Name
())
wg
.
Wait
()
}
}
// Handle signals
var
interruptWg
sync
.
WaitGroup
interrupted
:=
false
sigCh
:=
make
(
chan
os
.
Signal
,
1
)
signal
.
Notify
(
sigCh
,
os
.
Interrupt
)
go
func
()
{
<-
sigCh
interruptWg
.
Add
(
1
)
defer
interruptWg
.
Done
()
interrupted
=
true
log
.
Println
(
"Interrupted! Cancelling builds..."
)
var
wg
sync
.
WaitGroup
for
_
,
b
:=
range
builds
{
wg
.
Add
(
1
)
go
func
(
b
packer
.
Build
)
{
defer
wg
.
Done
()
log
.
Printf
(
"Stopping build: %s"
,
b
.
Name
())
b
.
Cancel
()
log
.
Printf
(
"Build cancelled: %s"
,
b
.
Name
())
}(
b
)
if
interrupted
{
log
.
Println
(
"Interrupted, not going to start any more builds."
)
break
}
}
wg
.
Wait
()
}()
// Wait for both the builds to complete and the interrupt handler,
// if it is interrupted.
...
...
@@ -226,7 +218,6 @@ func (c Command) Run(env packer.Environment, args []string) int {
log
.
Printf
(
"Builds completed. Waiting on interrupt barrier..."
)
interruptWg
.
Wait
()
log
.
Printf
(
"Interrupt barrier passed."
)
if
interrupted
{
env
.
Ui
()
.
Say
(
"Cleanly cancelled builds after being interrupted."
)
...
...
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