detecting and executing hooks
This commit is contained in:
parent
cdf393a30e
commit
6acbe7e3ae
@ -78,6 +78,7 @@ type MigrationContext struct {
|
|||||||
PostponeCutOverFlagFile string
|
PostponeCutOverFlagFile string
|
||||||
CutOverLockTimeoutSeconds int64
|
CutOverLockTimeoutSeconds int64
|
||||||
PanicFlagFile string
|
PanicFlagFile string
|
||||||
|
HooksPath string
|
||||||
|
|
||||||
DropServeSocket bool
|
DropServeSocket bool
|
||||||
ServeSocketFile string
|
ServeSocketFile string
|
||||||
|
@ -9,6 +9,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/github/gh-ost/go/base"
|
"github.com/github/gh-ost/go/base"
|
||||||
"github.com/openark/golib/log"
|
"github.com/openark/golib/log"
|
||||||
@ -24,7 +25,7 @@ func NewHooksExecutor() *HooksExecutor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *HooksExecutor) detectHooks() error {
|
func (this *HooksExecutor) initHooks() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,9 +40,9 @@ func (this *HooksExecutor) applyEnvironmentVairables() []string {
|
|||||||
return env
|
return env
|
||||||
}
|
}
|
||||||
|
|
||||||
// commandRun executes a command with arguments, and set relevant environment variables
|
// executeHook executes a command with arguments, and set relevant environment variables
|
||||||
func (this *HooksExecutor) commandRun(commandText string, arguments ...string) error {
|
func (this *HooksExecutor) executeHook(hook string, arguments ...string) error {
|
||||||
cmd := exec.Command(commandText, arguments...)
|
cmd := exec.Command(hook, arguments...)
|
||||||
cmd.Env = this.applyEnvironmentVairables()
|
cmd.Env = this.applyEnvironmentVairables()
|
||||||
|
|
||||||
if err := cmd.Run(); err != nil {
|
if err := cmd.Run(); err != nil {
|
||||||
@ -50,6 +51,28 @@ func (this *HooksExecutor) commandRun(commandText string, arguments ...string) e
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *HooksExecutor) detectHooks(baseName string) (hooks []string, err error) {
|
||||||
|
if this.migrationContext.HooksPath == "" {
|
||||||
|
return hooks, err
|
||||||
|
}
|
||||||
|
pattern := fmt.Sprintf("%s/%s*", this.migrationContext.HooksPath, baseName)
|
||||||
|
hooks, err = filepath.Glob(pattern)
|
||||||
|
return hooks, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *HooksExecutor) executeHooks(baseName string) error {
|
||||||
|
hooks, err := this.detectHooks(baseName)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, hook := range hooks {
|
||||||
|
if err := this.executeHook(hook); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (this *HooksExecutor) onStartup() error {
|
func (this *HooksExecutor) onStartup() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -114,7 +114,7 @@ func (this *Migrator) acceptSignals() {
|
|||||||
// initiateHooksExecutor
|
// initiateHooksExecutor
|
||||||
func (this *Migrator) initiateHooksExecutor() (err error) {
|
func (this *Migrator) initiateHooksExecutor() (err error) {
|
||||||
this.hooksExecutor = NewHooksExecutor()
|
this.hooksExecutor = NewHooksExecutor()
|
||||||
if err := this.hooksExecutor.detectHooks(); err != nil {
|
if err := this.hooksExecutor.initHooks(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
x
Reference in New Issue
Block a user