summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2015-12-18 16:26:52 (GMT)
committerChristian Pointner <equinox@helsinki.at>2015-12-18 16:26:52 (GMT)
commita8483937bc06458979d01d0aa60721c081aede10 (patch)
tree92c763b380a611541119e1a6e2568cc25fa193b9
parentd98dee68ba2ce1e0fe663fe06b469fca25205842 (diff)
added telnet control interface
-rw-r--r--src/helsinki.at/rhimportd/ctrlTelnet.go33
-rw-r--r--src/helsinki.at/rhimportd/ctrlWeb.go2
-rw-r--r--src/helsinki.at/rhimportd/main.go104
-rwxr-xr-xtest/test-simple.sh4
4 files changed, 74 insertions, 69 deletions
diff --git a/src/helsinki.at/rhimportd/ctrlTelnet.go b/src/helsinki.at/rhimportd/ctrlTelnet.go
new file mode 100644
index 0000000..003c666
--- /dev/null
+++ b/src/helsinki.at/rhimportd/ctrlTelnet.go
@@ -0,0 +1,33 @@
+//
+// rhimportd
+//
+// The Radio Helsinki Rivendell Import Daemon
+//
+//
+// Copyright (C) 2015 Christian Pointner <equinox@helsinki.at>
+//
+// This file is part of rhimportd.
+//
+// rhimportd is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// any later version.
+//
+// rhimportd is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with rhimportd. If not, see <http://www.gnu.org/licenses/>.
+//
+
+package main
+
+import (
+ "helsinki.at/rhimport"
+)
+
+func StartControlTelnet(addr_s string, conf *rhimport.Config, rddb *rhimport.RdDb) {
+ rhl.Println("telnet-ctrl: listening on", addr_s)
+}
diff --git a/src/helsinki.at/rhimportd/ctrlWeb.go b/src/helsinki.at/rhimportd/ctrlWeb.go
index 0341a95..8aff492 100644
--- a/src/helsinki.at/rhimportd/ctrlWeb.go
+++ b/src/helsinki.at/rhimportd/ctrlWeb.go
@@ -45,6 +45,6 @@ func StartControlWeb(addr_s string, conf *rhimport.Config, rddb *rhimport.RdDb)
http.Handle("/public/simple", webHandler{conf, rddb, false, webSimpleHandler})
http.Handle("/trusted/simple", webHandler{conf, rddb, true, webSimpleHandler})
- rhl.Println("listening on", addr_s)
+ rhl.Println("web-ctrl: listening on", addr_s)
http.ListenAndServe(addr_s, nil) // TODO: reader.Timeout, writer.Timeout???
}
diff --git a/src/helsinki.at/rhimportd/main.go b/src/helsinki.at/rhimportd/main.go
index 8f1c65d..b38129a 100644
--- a/src/helsinki.at/rhimportd/main.go
+++ b/src/helsinki.at/rhimportd/main.go
@@ -28,11 +28,11 @@ import (
"flag"
"log"
"os"
- // "os/signal"
- // "sync"
+ "os/signal"
+ "sync"
"helsinki.at/rhimport"
- // "io/ioutil"
+ // "io/ioutil"
)
var (
@@ -42,7 +42,8 @@ var (
)
func main() {
- // web_addr_s := flag.String("web-addr", ":4000", "addr:port to listen on")
+ web_addr_s := flag.String("web-addr", ":4080", "addr:port to listen on")
+ telnet_addr_s := flag.String("telnet-addr", ":4021", "addr:port to listen on")
rdconf_s := flag.String("rdconf", "/etc/rd.conf", "path to the Rivendell config file")
rdxport_url_s := flag.String("rdxport-url", "http://localhost/rd-bin/rdxport.cgi", "the url to the Rivendell web-api")
temp_dir_s := flag.String("tmp-dir", os.TempDir(), "path to temporary files")
@@ -75,67 +76,38 @@ func main() {
}
defer sessions.Cleanup()
- ctx := rhimport.ImportContext{UserName: "hugo"}
- var id string
- if id, err = sessions.NewSession(ctx); err != nil {
- rhl.Println("NewSession:", err)
- }
-
- pchan := make(chan rhimport.ProgressData)
- if err = sessions.AddProgressHandler(ctx.UserName, id, "mydata", pchan); err != nil {
- rhl.Println("AddProgressHanlder:", err)
- }
-
- dchan := make(chan rhimport.ImportResult)
- if err = sessions.AddDoneHandler(ctx.UserName, id, "mydata", dchan); err != nil {
- rhl.Println("AddDoneHanlder:", err)
- }
-
- if err = sessions.Run(ctx.UserName, id); err != nil {
- rhl.Println("Run:", err)
- }
-
- var id2 string
- if id2, err = sessions.NewSession(ctx); err != nil {
- rhl.Println("NewSession:", err)
- }
-
- if err = sessions.Remove(ctx.UserName, id); err != nil {
- rhl.Println("Remove:", err)
- }
-
- if err = sessions.Remove(ctx.UserName, id); err != nil {
- rhl.Println("Remove:", err)
- }
-
- if err = sessions.Remove(ctx.UserName, id2); err != nil {
- rhl.Println("Remove:", err)
+ var wg sync.WaitGroup
+
+ wg.Add(1)
+ go func() {
+ defer wg.Done()
+ rhl.Println("starting web-ctrl")
+ StartControlWeb(*web_addr_s, conf, rddb)
+ rhl.Println("web-ctrl finished")
+ }()
+
+ wg.Add(1)
+ go func() {
+ defer wg.Done()
+ rhl.Println("starting telnet-ctrl")
+ StartControlTelnet(*telnet_addr_s, conf, rddb)
+ rhl.Println("telnet-ctrl finished")
+ }()
+
+ alldone := make(chan bool)
+ go func() {
+ defer func() { alldone <- true }()
+ wg.Wait()
+ }()
+
+ c := make(chan os.Signal, 1)
+ signal.Notify(c, os.Interrupt)
+
+ select {
+ case <-c:
+ rhl.Println("received interrupt, shutdown")
+ return
+ case <-alldone:
+ return
}
-
- // var wg sync.WaitGroup
-
- // wg.Add(1)
- // go func() {
- // defer wg.Done()
- // rhl.Println("start web-ctrl")
- // StartControlWeb(*web_addr_s, conf, rddb)
- // rhl.Println("web-ctrl finished")
- // }()
-
- // alldone := make(chan bool)
- // go func() {
- // defer func() { alldone <- true }()
- // wg.Wait()
- // }()
-
- // c := make(chan os.Signal, 1)
- // signal.Notify(c, os.Interrupt)
-
- // select {
- // case <-c:
- // rhl.Println("received interrupt, shutdown")
- // return
- // case <-alldone:
- // return
- // }
}
diff --git a/test/test-simple.sh b/test/test-simple.sh
index bc1ab60..233d411 100755
--- a/test/test-simple.sh
+++ b/test/test-simple.sh
@@ -5,7 +5,7 @@ if [ -z "$1" ]; then
exit 1
fi
-#curl -XPOST 'http://localhost:4000/public/simple' -d @$1
-curl -H "X-Forwarded-User: heslinki" -XPOST 'http://localhost:4000/trusted/simple' -d @$1
+#curl -XPOST 'http://localhost:4080/public/simple' -d @$1
+curl -H "X-Forwarded-User: heslinki" -XPOST 'http://localhost:4080/trusted/simple' -d @$1
exit 0