summaryrefslogtreecommitdiff
path: root/src/main.go
diff options
context:
space:
mode:
authorxengineering <mail2xengineering@protonmail.com>2021-06-19 11:08:57 +0200
committerxengineering <mail2xengineering@protonmail.com>2021-06-20 13:57:58 +0200
commit963b86e49fad07a3722646b9d7f4b1c09d199eb1 (patch)
tree5ccb6b66bf9ce1c53e3e97fa7057e44b66512295 /src/main.go
parent198023be0f62ef6bb35cdd5ae78f90ab0a6f187e (diff)
downloadbirdscan-963b86e49fad07a3722646b9d7f4b1c09d199eb1.tar
birdscan-963b86e49fad07a3722646b9d7f4b1c09d199eb1.tar.zst
birdscan-963b86e49fad07a3722646b9d7f4b1c09d199eb1.zip
Implement continuous Python Daemon
Diffstat (limited to 'src/main.go')
-rw-r--r--src/main.go38
1 files changed, 30 insertions, 8 deletions
diff --git a/src/main.go b/src/main.go
index 3218df9..dcb201e 100644
--- a/src/main.go
+++ b/src/main.go
@@ -4,11 +4,19 @@ package main
import (
"log"
+ "os"
+ "os/signal"
+ "syscall"
)
var (
config RuntimeConfig
camera Camera
+ ipc IpcServer
+)
+
+const (
+ IPC_SOCKET = "/tmp/birdscan.sock" // FIXME
)
func main() {
@@ -19,13 +27,27 @@ func main() {
// parse flags and read config
config = GetRuntimeConfig()
- // create camera
- camera = NewCamera()
-
- // start goroutines
- server := NewWebServer()
- go server.run() // http server / user interface
-
- // run camera
+ // create services
+ camera = NewCamera() // main service
+ ipc = NewIpcServer() // inter process communication
+ web := NewWebServer() // web frontend
+
+ // allow graceful exit
+ var listener = make(chan os.Signal)
+ signal.Notify(listener, syscall.SIGTERM)
+ signal.Notify(listener, syscall.SIGINT)
+ go func() {
+ signal := <-listener
+ log.Printf("Got signal '%+v'", signal)
+ ipc.Cleanup()
+ os.Exit(0)
+ }()
+
+ // start secondary services
+ go ipc.Run(IPC_SOCKET)
+ go PicameraSubprocess(IPC_SOCKET) // subprocess to use Python picamera
+ go web.run()
+
+ // start main service
camera.run()
}