@@ -19,9 +19,11 @@ import (
1919 "fmt"
2020 "os"
2121 "os/exec"
22+ "os/signal"
2223 "path"
2324 "strings"
2425 "sync"
26+ "syscall"
2527 "time"
2628
2729 "gopkg.in/yaml.v3"
@@ -39,6 +41,7 @@ type Deployer struct {
3941 am * ArtifactManager
4042 wg sync.WaitGroup
4143 bm * component.BareMetalCluster
44+ ctx context.Context
4245
4346 createNoDirs bool
4447 workingDirs component.WorkingDirs
@@ -54,9 +57,12 @@ var _ Interface = &Deployer{}
5457type Option func (* Deployer )
5558
5659func NewDeployer (l logger.Logger , clusterName string , opts ... Option ) (Interface , error ) {
60+ ctx , _ := signal .NotifyContext (context .Background (), syscall .SIGINT , syscall .SIGTERM )
61+
5762 d := & Deployer {
5863 logger : l ,
5964 config : config .DefaultConfig (),
65+ ctx : ctx ,
6066 }
6167
6268 for _ , opt := range opts {
@@ -258,15 +264,15 @@ func (d *Deployer) CreateGreptimeDBCluster(ctx context.Context, clusterName stri
258264 return err
259265 }
260266
261- if err := d .bm .MetaSrv .Start (ctx , binary ); err != nil {
267+ if err := d .bm .MetaSrv .Start (d . ctx , binary ); err != nil {
262268 return err
263269 }
264270
265- if err := d .bm .Datanode .Start (ctx , binary ); err != nil {
271+ if err := d .bm .Datanode .Start (d . ctx , binary ); err != nil {
266272 return err
267273 }
268274
269- if err := d .bm .Frontend .Start (ctx , binary ); err != nil {
275+ if err := d .bm .Frontend .Start (d . ctx , binary ); err != nil {
270276 return err
271277 }
272278
@@ -318,7 +324,7 @@ func (d *Deployer) CreateEtcdCluster(ctx context.Context, clusterName string, op
318324 return err
319325 }
320326
321- if err = d .bm .Etcd .Start (ctx , bin ); err != nil {
327+ if err = d .bm .Etcd .Start (d . ctx , bin ); err != nil {
322328 return err
323329 }
324330
@@ -392,7 +398,7 @@ func (d *Deployer) Wait(ctx context.Context, option component.DeleteOptions) err
392398
393399 d .logger .V (3 ).Info ("Cluster shutting down. Cleaning allocated resources." )
394400
395- <- ctx .Done ()
401+ <- d . ctx .Done ()
396402 // Delete cluster after closing, which can only happens in the foreground.
397403 if err := d .deleteGreptimeDBClusterForeground (ctx , option ); err != nil {
398404 return err
0 commit comments