Skip to content

Commit

Permalink
#4 graceful kill when catch sigterm
Browse files Browse the repository at this point in the history
  • Loading branch information
unknwon committed Sep 11, 2015
1 parent 8c13dfa commit acb4029
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 42 deletions.
10 changes: 0 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,12 @@ Bra(Brilliant Ridiculous Assistant) is a command line utility tool.
## Usage

```
NAME:
Bra - Brilliant Ridiculous Assistant is a command line utility tool.
USAGE:
Bra [global options] command [command options] [arguments...]
VERSION:
0.3.3.0903
AUTHOR:
Author - <unknown@email>
COMMANDS:
init initialize config template file
run start monitoring and notifying
sync keep syncing two end points
help, h Shows a list of commands or help for one command
GLOBAL OPTIONS:
Expand Down
3 changes: 1 addition & 2 deletions bra.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"github.com/Unknwon/bra/cmd"
)

const APP_VER = "0.3.3.0903"
const APP_VER = "0.3.4.0911"

func init() {
runtime.GOMAXPROCS(runtime.NumCPU())
Expand All @@ -40,7 +40,6 @@ func main() {
cmd.CmdInit,
cmd.CmdRun,
cmd.CmdSync,
// cmd.CmdHttp,
}
app.Flags = append(app.Flags, []cli.Flag{}...)
app.Run(os.Args)
Expand Down
30 changes: 0 additions & 30 deletions cmd/http.go

This file was deleted.

14 changes: 14 additions & 0 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ import (
"fmt"
"os"
"os/exec"
"os/signal"
"path"
"runtime"
"strings"
"sync"
"syscall"
"time"

"github.com/Unknwon/com"
Expand Down Expand Up @@ -126,9 +128,21 @@ func gracefulKill() {
runningCmd.Process.Kill()
}

func catchSignals() {
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGTERM)
<-sigs

if runningCmd != nil {
shutdown <- true
}
os.Exit(0)
}

func runRun(ctx *cli.Context) {
setup(ctx)

go catchSignals()
go notify(setting.Cfg.Run.InitCmds)

watchPathes := append([]string{setting.WorkDir}, setting.Cfg.Run.WatchDirs...)
Expand Down

0 comments on commit acb4029

Please sign in to comment.