Skip to content

Commit fcbf8cf

Browse files
committed
tt: ignore SIGINT at Start command
Closes #325
1 parent 7f9c9aa commit fcbf8cf

File tree

2 files changed

+5
-13
lines changed

2 files changed

+5
-13
lines changed

cli/running/running.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,7 @@ func Start(cmdCtx *cmdcontext.CmdCtx, run *InstanceCtx) error {
540540
case <-sigCtx.Done():
541541
return nil
542542
default:
543+
signal.Ignore(syscall.SIGINT, syscall.SIGTERM)
543544
wd.Start()
544545
}
545546
return nil

cli/running/watchdog.go

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ type Watchdog struct {
3737
restartTimeout time.Duration
3838
// stopped indicates whether Watchdog was stopped.
3939
stopped bool
40-
// stopMutex used to avoid a race condition under stopped field.
41-
stopMutex sync.Mutex
4240
// done channel used to inform the signal handle goroutine
4341
// about termination of the Instance.
4442
done chan bool
@@ -73,16 +71,11 @@ func (wd *Watchdog) Start() {
7371
}
7472
wd.logger = wd.Instance.logger
7573
// Start the Instance and forwarding signals (except SIGINT and SIGTERM)
76-
wd.startSignalHandling()
77-
wd.stopMutex.Lock()
78-
if !wd.stopped {
79-
if err := wd.Instance.Start(); err != nil {
80-
wd.logger.Printf(`Watchdog(ERROR): "%v".`, err)
81-
wd.stopMutex.Unlock()
82-
break
83-
}
74+
if err := wd.Instance.Start(); err != nil {
75+
wd.logger.Printf(`Watchdog(ERROR): "%v".`, err)
76+
break
8477
}
85-
wd.stopMutex.Unlock()
78+
wd.startSignalHandling()
8679

8780
// Wait while the Instance will be terminated.
8881
if err := wd.Instance.Wait(); err != nil {
@@ -136,12 +129,10 @@ func (wd *Watchdog) startSignalHandling() {
136129
case sig := <-sigChan:
137130
switch sig {
138131
case syscall.SIGINT, syscall.SIGTERM:
139-
wd.stopMutex.Lock()
140132
wd.Instance.Stop(30 * time.Second)
141133
// If we receive one of the "stop" signals, the
142134
// program should be terminated.
143135
wd.stopped = true
144-
wd.stopMutex.Unlock()
145136
case syscall.SIGHUP:
146137
// Rotate the log files.
147138
wd.logger.Rotate()

0 commit comments

Comments
 (0)