From: Aleksander Mistewicz Date: Tue, 3 Oct 2017 12:03:18 +0000 (+0200) Subject: Add dryad executable X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=30d0762fdc936d91e9adebc17c2b6b9587eace46;p=tools%2Fboruta.git 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 Reviewed-on: https://mcdsrvbld02.digital.local/review/49536 Reviewed-by: Maciej Wereski Tested-by: Maciej Wereski --- 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 +}