diff options
Diffstat (limited to 'src/main.go')
-rw-r--r-- | src/main.go | 38 |
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() } |