summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorxengineering <mail2xengineering@protonmail.com>2021-06-18 14:30:04 +0200
committerxengineering <mail2xengineering@protonmail.com>2021-06-18 14:30:04 +0200
commit7e08ae6ff7701632c8e3919b9dd3a7a13970835b (patch)
tree4b12cfc492d818a17793e2145425f95be08ced19 /src
parent7634ee33120e7ef601ba1e806c63fe61c53e46bb (diff)
downloadbirdscan-7e08ae6ff7701632c8e3919b9dd3a7a13970835b.tar
birdscan-7e08ae6ff7701632c8e3919b9dd3a7a13970835b.tar.zst
birdscan-7e08ae6ff7701632c8e3919b9dd3a7a13970835b.zip
Remove defective Transporter
Diffstat (limited to 'src')
-rw-r--r--src/camera.go2
-rw-r--r--src/main.go5
-rw-r--r--src/runtime_config.go6
-rw-r--r--src/transport.go125
4 files changed, 0 insertions, 138 deletions
diff --git a/src/camera.go b/src/camera.go
index e836cf3..4a2fc90 100644
--- a/src/camera.go
+++ b/src/camera.go
@@ -79,8 +79,6 @@ func singlePicture(m *Machine) {
// process result
m.SendEvent("single_picture_taken")
- log.Println("Picture taken. Sending transport_request ...")
- transporter.statemachine.SendEvent("transport_request")
}
func (cam *Camera) run() {
diff --git a/src/main.go b/src/main.go
index 572e5f9..e61dfb5 100644
--- a/src/main.go
+++ b/src/main.go
@@ -9,7 +9,6 @@ import (
var (
config RuntimeConfig
camera Camera
- transporter Transporter
)
func main() {
@@ -26,10 +25,6 @@ func main() {
// create camera
camera = NewCamera()
- // setup transporter
- transporter = NewTransporter()
- go transporter.Run() // daemon to copy files via rsync
-
// start goroutines
server := NewWebServer()
go server.run() // http server / user interface
diff --git a/src/runtime_config.go b/src/runtime_config.go
index 07e4a7c..8c484d0 100644
--- a/src/runtime_config.go
+++ b/src/runtime_config.go
@@ -13,7 +13,6 @@ import (
type RuntimeConfig struct {
Flag FlagConfig
Web WebConfig `json:"webserver"`
- Transport TransportConfig `json:"file_transport"`
}
func GetRuntimeConfig() RuntimeConfig {
@@ -42,11 +41,6 @@ func GetRuntimeConfig() RuntimeConfig {
log.Fatalf("Could not parse configuration file %s", retval.Flag.ConfigPath)
}
- // patch default config in case of debugging
- if retval.Flag.Debug {
- retval.Transport.Enabled = true
- }
-
return retval
}
diff --git a/src/transport.go b/src/transport.go
deleted file mode 100644
index 3e91355..0000000
--- a/src/transport.go
+++ /dev/null
@@ -1,125 +0,0 @@
-// vim: shiftwidth=4 tabstop=4 noexpandtab
-
-package main
-
-import (
- "time"
- "log"
- "os/exec"
- "fmt"
- "io"
-)
-
-type Transporter struct {
- statemachine Machine
-}
-
-type TransportConfig struct {
- Enabled bool `json:"enabled"`
- LocalPathToSshPrivateKey string `json:"local_path_to_ssh_private_key"`
- FileserverHostOrIp string `json:"fileserver_host_or_ip"`
- FileserverSshPort string `json:"fileserver_ssh_port"`
- RemoteUser string `json:"remote_user"`
- RemotePathToTargetDirectory string `json:"remote_path_to_target_directory"`
-}
-
-func NewTransporter() Transporter {
- return Transporter{
- statemachine: Machine{
- name: "transporter",
- initial: "idle",
- states: StateMap{
- "idle": MachineState{ // nothing to transport
- on: TransitionMap{
- "transport_request": MachineTransition{
- to: "transport",
- },
- },
- },
- "transport": MachineState{ // rsync process for transport is running
- on: TransitionMap{
- "transport_request": MachineTransition{
- to: "transport_queue",
- },
- "transport_finished": MachineTransition{
- to: "idle",
- },
- },
- },
- "transport_queue": MachineState{ // like transport but also a pending transport request
- on: TransitionMap{
- "transport_finished": MachineTransition{
- to: "transport",
- },
- },
- },
- },
- api: make(chan string),
- state_listeners: make([]*(chan string), 0),
- hook: runTransporterHooks,
- },
- }
-}
-
-func (transp *Transporter) Run() {
- transp.statemachine.Run()
-}
-
-func runTransporterHooks(last string, next string, m *Machine) {
- if last == "idle" && next == "transport" {
- go transportData(m)
- }
- if last == "transport_queue" && next == "transport" {
- go transportData(m)
- }
-}
-
-func transportData(m *Machine) {
- if config.Transport.Enabled {
- if !config.Flag.Debug {
-
- // generate command string from config
- cmdString := fmt.Sprintf(
- "\"rsync --remove-source-files -rltgoDv -e 'ssh -p %s -i %s' /var/lib/birdscan/ %s@%s:%s\"",
- config.Transport.FileserverSshPort,
- config.Transport.LocalPathToSshPrivateKey,
- config.Transport.RemoteUser,
- config.Transport.FileserverHostOrIp,
- config.Transport.RemotePathToTargetDirectory,
- )
-
- // create command
- cmd := exec.Command(
- "/bin/bash",
- "-c",
- cmdString,
- )
- log.Printf("Executing: '%s'", cmd.String())
-
- // get stderr
- stderr,err := cmd.StderrPipe()
- if err != nil {
- log.Print(err)
- }
- defer stderr.Close()
-
- // execute command and fetch stderr
- err = cmd.Start()
- if err != nil {
- log.Print(err)
- }
- stderrData,err := io.ReadAll(stderr)
- if err != nil {
- log.Print(err)
- }
- err = cmd.Wait()
- if err != nil {
- log.Print(err)
- log.Println(string(stderrData))
- }
- } else {
- time.Sleep(8 * time.Second)
- }
- }
- m.SendEvent("transport_finished")
-}