From 749a690b6cb05523017d5dd4111536d001907046 Mon Sep 17 00:00:00 2001 From: asandikci Date: Mon, 21 Aug 2023 16:45:11 +0300 Subject: [PATCH] =?UTF-8?q?neden=20=C3=A7al=C4=B1=C5=9Fm=C4=B1yon...?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 5 +- Makefile | 49 +++++++++++++++++++ .../ahenkd-go.go => ahenk-go/main.go} | 2 +- cmd/ahenk-go/plugin-manager.go | 33 +++++++++++++ cmd/ahenk-go/plugin-opener.go | 25 ++++++++++ cmd/ahenkd-go/plugin-manager.go | 30 ------------ debian/changelog | 5 ++ debian/control | 27 ++++++++++ debian/copyright | 13 +++++ debian/rules | 10 ++++ {pkg/plugins => plugins}/resources/main.go | 17 ++++++- scripts/install.sh | 5 ++ 12 files changed, 186 insertions(+), 35 deletions(-) create mode 100644 Makefile rename cmd/{ahenkd-go/ahenkd-go.go => ahenk-go/main.go} (97%) create mode 100644 cmd/ahenk-go/plugin-manager.go create mode 100644 cmd/ahenk-go/plugin-opener.go delete mode 100644 cmd/ahenkd-go/plugin-manager.go create mode 100644 debian/changelog create mode 100644 debian/control create mode 100644 debian/copyright create mode 100644 debian/rules rename {pkg/plugins => plugins}/resources/main.go (91%) diff --git a/Dockerfile b/Dockerfile index 2599724..78b3cc2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,14 +13,15 @@ RUN apt-get update RUN apt-get upgrade -y ### INSTALL USEFUL UTILITIES ### -RUN apt-get install curl wget tree nano -y +RUN apt-get install curl wget tree nano procps -y ### INSTALL BUILD DEPENDENCIES ### -RUN apt-get install dh-golang -y +RUN apt-get install dh-golang dh-make -y RUN apt-get install dh-make-golang -y RUN apt-get install golang-github-sevlyar-go-daemon-dev -y RUN apt-get install golang-golang-x-exp-dev -y + ### CONFIGURATIONS ### # Enable UTF8 Encoding RUN echo "LC_ALL=en_US.UTF-8" >> /etc/environment diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..b9f4c7a --- /dev/null +++ b/Makefile @@ -0,0 +1,49 @@ +REPO_NAME="ahenk-go" +REPO_LINK="https://git.aliberksandikci.com.tr/liderahenk/${REPO_NAME}" + +DAEMON_NAME="ahenk-go" +OLD_DAEMON_NAME="ahenkd-go" +PYTHON_DAEMON_NAME="ahenkd" + +CONF_DIR="/etc/ahenk-go/" +TEMP_DIR="$(mktemp -d)" +MAIN_DIR="${TEMP_DIR}/${REPO_NAME}/" + +info: + @echo "Made by Aliberk Sandıkçı - 2023" + @echo "preclean: for cleaning old files, configurations" + @echo "TODO test: Test go files" + @echo "install: Build and install ahenk-go" + @echo "TODO uninstall: Uninstall ahenk-go" + @echo "TODO clean: for postclean" + +preclean: + sudo rm -rf /usr/bin/$(DAEMON_NAME) + sudo rm -rf /usr/bin/${OLD_DAEMON_NAME} + sudo rm -rf /usr/bin/${PYTHON_DAEMON_NAME} + + @# TODO systemd control for both three process for docker + @# REVIEW are both killall and systemctl commands running? + @pgrep -x ${DAEMON_NAME} && (sudo killall "${DAEMON_NAME}" || sudo systemctl disable "${DAEMON_NAME}" || sudo systemctl stop "${DAEMON_NAME}") || echo "no ${DAEMON_NAME} found" + @pgrep -x ${OLD_DAEMON_NAME} && (sudo killall "${OLD_DAEMON_NAME}" || sudo systemctl disable "${OLD_DAEMON_NAME}" || sudo systemctl stop "${OLD_DAEMON_NAME}") || echo "no ${OLD_DAEMON_NAME} found" + + @# TODO + @# echo -e "Do you want to remove python implementation of ahenk if installed in system?" + # read -rp "(Y/N) " input + + @pgrep -x ${PYTHON_DAEMON_NAME} && (sudo killall "${PYTHON_DAEMON_NAME}" || sudo systemctl disable "${PYTHON_DAEMON_NAME}" || sudo systemctl stop "${PYTHON_DAEMON_NAME}") || echo "no ${PYTHON_DAEMON_NAME} found" + + sudo systemctl daemon-reload + sudo rm -rf ${CONF_DIR} + @echo -e "PRE-CLENING DONE\n" +test: + +install: + go build -o ${DESTDIR}/usr/bin/${REPO_NAME} ./cmd/ahenk-go/ + @sudo mkdir -p "${CONF_DIR}" + +uninstall: + + +clean: #postclean: + diff --git a/cmd/ahenkd-go/ahenkd-go.go b/cmd/ahenk-go/main.go similarity index 97% rename from cmd/ahenkd-go/ahenkd-go.go rename to cmd/ahenk-go/main.go index 76793d3..b729c50 100644 --- a/cmd/ahenkd-go/ahenkd-go.go +++ b/cmd/ahenk-go/main.go @@ -71,7 +71,7 @@ func main() { log.Print("STARTED AS NO-DAEMON") } } else { - log.Print("Please enter a valid option !") + panic("Please enter a valid option !") } PluginManager() log.Print("Plugin Manager Started Succesfully") diff --git a/cmd/ahenk-go/plugin-manager.go b/cmd/ahenk-go/plugin-manager.go new file mode 100644 index 0000000..14309f4 --- /dev/null +++ b/cmd/ahenk-go/plugin-manager.go @@ -0,0 +1,33 @@ +package main + +import "log" + +// type Greeter interface { +// Greet() +// } + +func PluginManager() { + // LoadPlugin("resources") + + // // 4. use the module + // greeter.Greet() + + // greeter.Myvar() + // // for { + // // logPlugin(greeter.AgentInfo()) + // // time.Sleep(30 * time.Second) + // // } + log.Print("plugin manager started succesfully") +} + +// func logPlugin(mp map[string]interface{}) { +// fmt.Printf("\nOs Info:\n") +// for i, v := range mp { +// fmt.Printf("%v: %v\n", i, v) +// } +// } + +// // TODO response to Lider +// // func createResponse() { + +// // } diff --git a/cmd/ahenk-go/plugin-opener.go b/cmd/ahenk-go/plugin-opener.go new file mode 100644 index 0000000..dd5c001 --- /dev/null +++ b/cmd/ahenk-go/plugin-opener.go @@ -0,0 +1,25 @@ +package main + +// // Load Plugin with plugin name and function name +// func LoadPlugin(plugName, funcName string) { +// plug, err := plugin.Open("../../plugins/resources/main.so") +// if err != nil { +// fmt.Println(err) +// os.Exit(1) +// } + +// symGreeter, err := plug.Lookup("Greeter") +// if err != nil { +// fmt.Println(err) +// os.Exit(1) +// } + +// var greeter Greeter +// greeter, ok := symGreeter.(Greeter) +// if !ok { +// fmt.Println("unexpected type from module symbol") +// os.Exit(1) +// } +// } + +// // NEXT move plugin-manager.go main here ! diff --git a/cmd/ahenkd-go/plugin-manager.go b/cmd/ahenkd-go/plugin-manager.go deleted file mode 100644 index 2b6a3d5..0000000 --- a/cmd/ahenkd-go/plugin-manager.go +++ /dev/null @@ -1,30 +0,0 @@ -package main - -import ( - "ahenk-go/pkg/plugins/resources" - "fmt" - "log" - "time" -) - -func PluginManager() { - log.Print("Plugin Manager Started") - - for { - logPlugin(resources.AgentInfo()) - time.Sleep(30 * time.Second) - } - -} - -func logPlugin(mp map[string]interface{}) { - fmt.Printf("\nOs Info:\n") - for i, v := range mp { - fmt.Printf("%v: %v\n", i, v) - } -} - -// TODO response to Lider -// func createResponse() { - -// } diff --git a/debian/changelog b/debian/changelog new file mode 100644 index 0000000..7900dfa --- /dev/null +++ b/debian/changelog @@ -0,0 +1,5 @@ +ahenk-go (0.0.1-1) UNRELEASED; urgency=low + + * Initial release + + -- Aliberk Sandıkçı Mon, 21 Aug 2023 13:05:24 +0000 \ No newline at end of file diff --git a/debian/control b/debian/control new file mode 100644 index 0000000..4dd4456 --- /dev/null +++ b/debian/control @@ -0,0 +1,27 @@ +Source: ahenk-go +Maintainer: Aliberk Sandıkçı +Uploaders: Aliberk Sandıkçı +Section: utils +Testsuite: autopkgtest-pkg-go +Priority: optional +Build-Depends: debhelper-compat (= 13), + dh-golang, + golang-any, + golang-github-sevlyar-go-daemon-dev, + golang-golang-x-exp-dev +Standards-Version: 4.6.0 +Vcs-Browser: https://git.aliberksandikci.com.tr/Liderahenk/go-ahenk +Vcs-Git: https://git.aliberksandikci.com.tr/Liderahenk/go-ahenk.git +Homepage: https://liderahenk.org +Rules-Requires-Root: no +XS-Go-Import-Path: git.aliberksandikci.com.tr/Liderahenk/ahenk-go + +Package: ahenk-go +Architecture: any +Depends: ${misc:Depends}, + ${shlibs:Depends} +Built-Using: ${misc:Built-Using} +Description: The client side of the Lider Ahenk Project + Lider Ahenk is an open source project which provides solutions + to manage, monitor and audit unlimited number of different + systems and users on a network. diff --git a/debian/copyright b/debian/copyright new file mode 100644 index 0000000..6fc10e9 --- /dev/null +++ b/debian/copyright @@ -0,0 +1,13 @@ +Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ +Upstream-Name: ahenk-go +Upstream-Contact: Aliberk Sandıkçı +Source: https://git.aliberksandikci.com.tr/Liderahenk/ahenk-go + +Files: * +Copyright: 2023 Aliberk Sandıkçı +License: LGPL-3.0+ + +Files: debian/* +Copyright: 2023 Aliberk Sandıkçı +License: LGPL-3.0+ +Comment: Debian packaging is licensed under the same terms as upstream diff --git a/debian/rules b/debian/rules new file mode 100644 index 0000000..954662b --- /dev/null +++ b/debian/rules @@ -0,0 +1,10 @@ +#!/usr/bin/make -f + +%: + dh $@ --builddirectory=_build --buildsystem=golang --with=golang + +override_dh_auto_install: + dh_auto_install -- --no-source + # dh_systemd_enable || true + # dh_systemd_start || true + dh_installsystemd diff --git a/pkg/plugins/resources/main.go b/plugins/resources/main.go similarity index 91% rename from pkg/plugins/resources/main.go rename to plugins/resources/main.go index c7cd9b6..491c766 100644 --- a/pkg/plugins/resources/main.go +++ b/plugins/resources/main.go @@ -1,10 +1,13 @@ -package resources +package main import ( "ahenk-go/pkg/osinfo" + "fmt" "runtime" ) +type greeting string + // return instant resource usage information func ResourceUsage() map[string]string { data := map[string]string{ @@ -27,7 +30,7 @@ func ResourceUsage() map[string]string { } // return general Agent information (that changes rarely) -func AgentInfo() map[string]interface{} { +func (g greeting) AgentInfo() map[string]interface{} { data := map[string]interface{}{ "System": runtime.GOOS, "Release": osinfo.GetKernelInfo()["Release"], // TODO 'agentVersion': self.get_agent_version(), @@ -67,3 +70,13 @@ func Info() map[string]string { // inf["machine_oriented"] = "false" return inf } + +func (g greeting) Greet() { + fmt.Println("Hello Universe") +} +func (g greeting) Myvar() { + fmt.Println("I am here") +} + +// this is exported +var Greeter greeting diff --git a/scripts/install.sh b/scripts/install.sh index 7051e3a..9bd5670 100644 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -1,6 +1,11 @@ #!/bin/bash ### Ahenk Agent Local Installation Script +### IMPORTANT NOTICE ! +# Consider to use makefile for building or .deb file for installing package, +# using this scripts is not suggested anymore ! + +### --------------------- ### ### --> Prerequisites # git