summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Mistewicz <a.mistewicz@samsung.com>2017-10-03 14:03:18 +0200
committerMaciej Wereski <m.wereski@partner.samsung.com>2018-03-05 18:28:52 +0100
commit30d0762fdc936d91e9adebc17c2b6b9587eace46 (patch)
tree2ad59c4122ca3fad30908bc260c21afddf8b661f
parentaad36ca3b6e3941c72c909d1a97cdc7a80283911 (diff)
downloadboruta-30d0762fdc936d91e9adebc17c2b6b9587eace46.tar.gz
boruta-30d0762fdc936d91e9adebc17c2b6b9587eace46.tar.bz2
boruta-30d0762fdc936d91e9adebc17c2b6b9587eace46.zip
Add dryad executable
Compiled dryad exposes Dryad interface with Go RPC. Currently the only flag is path to configuration file. It will be generated if it is not found. Change-Id: I07809bea9991228b32f9bb24fae9c99dc1fad0c0 Signed-off-by: Aleksander Mistewicz <a.mistewicz@samsung.com> Reviewed-on: https://mcdsrvbld02.digital.local/review/49536 Reviewed-by: Maciej Wereski <m.wereski@partner.samsung.com> Tested-by: Maciej Wereski <m.wereski@partner.samsung.com>
-rw-r--r--cmd/dryad/dryad.go93
1 files changed, 93 insertions, 0 deletions
diff --git a/cmd/dryad/dryad.go b/cmd/dryad/dryad.go
new file mode 100644
index 0000000..4339a5a
--- /dev/null
+++ b/cmd/dryad/dryad.go
@@ -0,0 +1,93 @@
+/*
+ * Copyright (c) 2017-2018 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+package main
+
+import (
+ "flag"
+ "log"
+ "net"
+ "net/rpc"
+ "os"
+ "os/signal"
+
+ "git.tizen.org/tools/boruta/dryad"
+ "git.tizen.org/tools/boruta/dryad/conf"
+ dryad_rpc "git.tizen.org/tools/boruta/rpc/dryad"
+)
+
+var (
+ confPath string
+ configuration *conf.General
+)
+
+func init() {
+ configuration = conf.NewConf()
+
+ flag.StringVar(&confPath, "conf", "/etc/boruta/dryad.conf", "path to the configuration file")
+}
+
+func exitOnErr(ctx string, err error) {
+ if err != nil {
+ log.Fatal(ctx, err)
+ }
+}
+
+func generateConfFile() {
+ f, err := os.Create(confPath)
+ exitOnErr("can't create configuration file:", err)
+ defer f.Close()
+ exitOnErr("can't generate new configuration:", configuration.Marshal(f))
+}
+
+func readConfFile() {
+ f, err := os.Open(confPath)
+ exitOnErr("can't open configuration file:", err)
+ defer f.Close()
+ exitOnErr("can't parse configuration:", configuration.Unmarshal(f))
+}
+
+func main() {
+ flag.Parse()
+
+ // Read configuration.
+ _, err := os.Stat(confPath)
+ if err != nil {
+ if os.IsNotExist(err) {
+ generateConfFile()
+ log.Fatal("configuration file generated. Please edit it first")
+ }
+ log.Fatal("can't access file:", err)
+ }
+ readConfFile()
+
+ rusalka := dryad.NewRusalka(configuration.User.Name, configuration.User.Groups)
+
+ l, err := net.Listen("tcp", configuration.Address)
+ exitOnErr("can't listen on port:", err)
+ defer l.Close()
+
+ srv := rpc.NewServer()
+ err = dryad_rpc.RegisterDryadService(srv, rusalka)
+ exitOnErr("can't start RPC service:", err)
+
+ go srv.Accept(l)
+
+ // Wait for interrupt.
+ c := make(chan os.Signal, 1)
+ signal.Notify(c, os.Interrupt)
+ <-c
+}