mirror of https://github.com/hashicorp/packer
https://github.com/dominikh/go-tools/tree/master/cmd/unusedpull/4731/head
parent
230079f73a
commit
d1b20b3d9c
@ -1,43 +0,0 @@
|
||||
package qemu
|
||||
|
||||
import (
|
||||
"github.com/mitchellh/multistep"
|
||||
"github.com/mitchellh/packer/packer"
|
||||
"time"
|
||||
)
|
||||
|
||||
// stepWaitForShutdown waits for the shutdown of the currently running
|
||||
// qemu VM.
|
||||
type stepWaitForShutdown struct {
|
||||
Message string
|
||||
}
|
||||
|
||||
func (s *stepWaitForShutdown) Run(state multistep.StateBag) multistep.StepAction {
|
||||
driver := state.Get("driver").(Driver)
|
||||
ui := state.Get("ui").(packer.Ui)
|
||||
|
||||
stopCh := make(chan struct{})
|
||||
defer close(stopCh)
|
||||
|
||||
cancelCh := make(chan struct{})
|
||||
go func() {
|
||||
for {
|
||||
if _, ok := state.GetOk(multistep.StateCancelled); ok {
|
||||
close(cancelCh)
|
||||
return
|
||||
}
|
||||
|
||||
select {
|
||||
case <-stopCh:
|
||||
return
|
||||
case <-time.After(100 * time.Millisecond):
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
ui.Say(s.Message)
|
||||
driver.WaitForShutdown(cancelCh)
|
||||
return multistep.ActionContinue
|
||||
}
|
||||
|
||||
func (s *stepWaitForShutdown) Cleanup(state multistep.StateBag) {}
|
||||
@ -1,33 +0,0 @@
|
||||
package rpc
|
||||
|
||||
import (
|
||||
"net"
|
||||
"net/rpc"
|
||||
)
|
||||
|
||||
// rpcDial makes a TCP connection to a remote RPC server and returns
|
||||
// the client. This will set the connection up properly so that keep-alives
|
||||
// are set and so on and should be used to make all RPC connections within
|
||||
// this package.
|
||||
func rpcDial(address string) (*rpc.Client, error) {
|
||||
tcpConn, err := tcpDial(address)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Create an RPC client around our connection
|
||||
return rpc.NewClient(tcpConn), nil
|
||||
}
|
||||
|
||||
// tcpDial connects via TCP to the designated address.
|
||||
func tcpDial(address string) (*net.TCPConn, error) {
|
||||
conn, err := net.Dial("tcp", address)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Set a keep-alive so that the connection stays alive even when idle
|
||||
tcpConn := conn.(*net.TCPConn)
|
||||
tcpConn.SetKeepAlive(true)
|
||||
return tcpConn, nil
|
||||
}
|
||||
@ -1,39 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
|
||||
"github.com/mitchellh/packer/packer"
|
||||
"github.com/mitchellh/packer/packer/plugin"
|
||||
)
|
||||
|
||||
// Prepares the signal handlers so that we handle interrupts properly.
|
||||
// The signal handler exists in a goroutine.
|
||||
func setupSignalHandlers(ui packer.Ui) {
|
||||
ch := make(chan os.Signal, 1)
|
||||
signal.Notify(ch, os.Interrupt)
|
||||
signal.Notify(ch, syscall.SIGTERM)
|
||||
|
||||
go func() {
|
||||
// First interrupt. We mostly ignore this because it allows the
|
||||
// plugins time to cleanup.
|
||||
<-ch
|
||||
log.Println("First interrupt. Ignoring to allow plugins to clean up.")
|
||||
|
||||
ui.Error("Interrupt signal received. Cleaning up...")
|
||||
|
||||
// Second interrupt. Go down hard.
|
||||
<-ch
|
||||
log.Println("Second interrupt. Exiting now.")
|
||||
|
||||
ui.Error("Interrupt signal received twice. Forcefully exiting now.")
|
||||
|
||||
// Force kill all the plugins, but mark that we're killing them
|
||||
// first so that we don't get panics everywhere.
|
||||
plugin.CleanupClients()
|
||||
os.Exit(1)
|
||||
}()
|
||||
}
|
||||
Loading…
Reference in new issue