Skip to content

Commit 583d6d3

Browse files
author
Shlomi Noach
committed
accepting SIGHUP. Reloads configuration and marks as point of interest
1 parent e723909 commit 583d6d3

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22
#
33
#
4-
RELEASE_VERSION="0.7.17"
4+
RELEASE_VERSION="0.8.1"
55

66
buildpath=/tmp/gh-ost
77
target=gh-ost

go/cmd/gh-ost/main.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
"flag"
1010
"fmt"
1111
"os"
12+
"os/signal"
13+
"syscall"
1214

1315
"github.com/github/gh-ost/go/base"
1416
"github.com/github/gh-ost/go/logic"
@@ -17,6 +19,26 @@ import (
1719

1820
var AppVersion string
1921

22+
// acceptSignals registers for OS signals
23+
func acceptSignals(migrationContext *base.MigrationContext) {
24+
c := make(chan os.Signal, 1)
25+
26+
signal.Notify(c, syscall.SIGHUP)
27+
go func() {
28+
for sig := range c {
29+
switch sig {
30+
case syscall.SIGHUP:
31+
log.Infof("Received SIGHUP. Reloading configuration")
32+
if err := migrationContext.ReadConfigFile(); err != nil {
33+
log.Errore(err)
34+
} else {
35+
migrationContext.MarkPointOfInterest()
36+
}
37+
}
38+
}
39+
}()
40+
}
41+
2042
// main is the application's entry point. It will either spawn a CLI or HTTP itnerfaces.
2143
func main() {
2244
migrationContext := base.GetMigrationContext()
@@ -122,6 +144,7 @@ func main() {
122144
migrationContext.ApplyCredentials()
123145

124146
log.Infof("starting gh-ost %+v", AppVersion)
147+
acceptSignals(migrationContext)
125148

126149
migrator := logic.NewMigrator()
127150
err := migrator.Migrate()

go/logic/migrator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ func (this *Migrator) printStatus() {
606606
shouldPrintStatus = (elapsedSeconds%5 == 0)
607607
} else if elapsedSeconds <= 180 {
608608
shouldPrintStatus = (elapsedSeconds%5 == 0)
609-
} else if this.migrationContext.TimeSincePointOfInterest() <= 60 {
609+
} else if this.migrationContext.TimeSincePointOfInterest().Seconds() <= 60 {
610610
shouldPrintStatus = (elapsedSeconds%5 == 0)
611611
} else {
612612
shouldPrintStatus = (elapsedSeconds%30 == 0)

go/logic/streamer.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ func (this *EventsStreamer) StreamEvents(canStopStreaming func() bool) error {
189189
for {
190190
if err := this.binlogReader.StreamEvents(canStopStreaming, this.eventsChannel); err != nil {
191191
log.Infof("StreamEvents encountered unexpected error: %+v", err)
192+
this.migrationContext.MarkPointOfInterest()
192193
time.Sleep(ReconnectStreamerSleepSeconds * time.Second)
193194

194195
// Reposition at same binlog file. Single attempt (TODO: make multiple attempts?)

0 commit comments

Comments
 (0)