Skip to content

Commit

Permalink
uses cmdutil from skycoin/dmsg#83
Browse files Browse the repository at this point in the history
  • Loading branch information
alexadhy committed May 29, 2021
1 parent 895d4a8 commit 7f1d35d
Show file tree
Hide file tree
Showing 6 changed files with 4 additions and 87 deletions.
3 changes: 2 additions & 1 deletion cmd/setup-node/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bufio"
"context"
"encoding/json"
"github.com/skycoin/dmsg/cmdutil"
"io"
"io/ioutil"
"os"
Expand Down Expand Up @@ -91,7 +92,7 @@ var rootCmd = &cobra.Command{

m := prepareMetrics(log)

ctx, cancel := signalContext(context.Background(), log)
ctx, cancel := cmdutil.SignalContext(context.Background(), log)
defer cancel()

log.Fatal(sn.Serve(ctx, m))
Expand Down
14 changes: 0 additions & 14 deletions cmd/setup-node/commands/subprocess_unix.go

This file was deleted.

36 changes: 0 additions & 36 deletions cmd/setup-node/commands/subprocess_windows.go

This file was deleted.

3 changes: 2 additions & 1 deletion cmd/skywire-visor/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"embed"
"fmt"
"github.com/skycoin/dmsg/cmdutil"
"io"
"io/fs"
"io/ioutil"
Expand Down Expand Up @@ -97,7 +98,7 @@ var rootCmd = &cobra.Command{
runBrowser(conf, log)
}

ctx, cancel := signalContext(context.Background(), log)
ctx, cancel := cmdutil.SignalContext(context.Background(), log)
defer cancel()

// Wait.
Expand Down
7 changes: 0 additions & 7 deletions cmd/skywire-visor/commands/subprocess_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@
package commands

import (
"context"
"os/exec"
"syscall"
"time"

"github.com/sirupsen/logrus"
"github.com/skycoin/dmsg/cmdutil"

"github.com/skycoin/skywire/pkg/restart"
)

Expand Down Expand Up @@ -45,7 +42,3 @@ func detachProcess(delayDuration time.Duration, log logrus.FieldLogger) {
}

}

func signalContext(ctx context.Context, log logrus.FieldLogger) (context.Context, context.CancelFunc) {
return cmdutil.SignalContext(ctx, log)
}
28 changes: 0 additions & 28 deletions cmd/skywire-visor/commands/subprocess_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,10 @@
package commands

import (
"context"
"os"
"os/signal"
"time"

"github.com/sirupsen/logrus"
"golang.org/x/sys/windows"
)

func detachProcess(_ time.Duration, _ logrus.FieldLogger) {
}

// signalContext is just wrapper for cmdutil.SignalContext with its signal uses windows specific signals
func signalContext(ctx context.Context, log logrus.FieldLogger) (context.Context, context.CancelFunc) {
if log == nil {
log = logrus.New()
}

ctx, cancel := context.WithCancel(ctx)
ch := make(chan os.Signal)

signal.Notify(ch, []os.Signal{windows.SIGINT, windows.SIGTERM, windows.SIGQUIT}...)

go func() {
select {
case sig := <-ch:
log.WithField("signal", sig).
Info("Closing with received signal.")
case <-ctx.Done():
}
cancel()
}()

return ctx, cancel
}

0 comments on commit 7f1d35d

Please sign in to comment.