Skip to content

Commit

Permalink
Stop rpc server on quit (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
sikmir committed Jan 19, 2024
1 parent ab5ee33 commit 117278d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ endif

GO_ENV := GO111MODULE=on $(GO_ENV)

GO_FLAGS=-ldflags "-w"
GO ?= go
GO_FLAGS = -ldflags "-w -X main.version=`git describe --tags --always --dirty`"

all: clean wb-rules

Expand All @@ -36,7 +37,7 @@ test:
CC=x86_64-linux-gnu-gcc go test -v -trimpath -ldflags="-s -w" ./wbrules

wb-rules: main.go wbrules/*.go
$(GO_ENV) go build -trimpath -ldflags "-w -X main.version=`git describe --tags --always --dirty`"
$(GO_ENV) $(GO) build -trimpath $(GO_FLAGS)

install:
mkdir -p $(DESTDIR)/etc/init.d/
Expand Down
6 changes: 6 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
wb-rules (2.18.10) stable; urgency=medium

* Stop rpc server on quit

-- Nikolay Korotkiy <nikolay.korotkiy@wirenboard.com> Wed, 17 Jan 2023 10:34:00 +0400

wb-rules (2.18.9) stable; urgency=medium

* Add arm64 build, no functional changes
Expand Down
8 changes: 4 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ func main() {
wbgong.Info.Println("wait for driver to become ready")
driver.WaitForReady()
wbgong.Info.Println("driver is ready")
defer driver.Close()
defer driver.StopLoop()

engineOptions := wbrules.NewESEngineOptions()
engineOptions.SetPersistentDBFile(*persistentDbFile)
Expand All @@ -163,6 +165,7 @@ func main() {
wbgong.Error.Fatalf("error creating engine: %s", err)
}
engine.Start()
defer engine.Stop()

gotSome := false
watcher := wbgong.NewDirWatcher("\\.js(\\"+wbrules.FILE_DISABLED_SUFFIX+")?$", engine)
Expand All @@ -185,12 +188,9 @@ func main() {
rpc := wbgong.NewMQTTRPCServer("wbrules", engineMqttClient)
rpc.Register(wbrules.NewEditor(engine))
rpc.Start()
defer rpc.Stop()
}

// wait for quit signal
<-exitCh

engine.Stop()
driver.StopLoop()
driver.Close()
}

0 comments on commit 117278d

Please sign in to comment.