summaryrefslogtreecommitdiff
path: root/src/helsinki.at/rhimportd/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/helsinki.at/rhimportd/main.go')
-rw-r--r--src/helsinki.at/rhimportd/main.go104
1 files changed, 38 insertions, 66 deletions
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
- // }
}