Author: Paolo Lulli <paolo@lulli.net>
Changes to startup
client/postMetric.sh | 2 +- script/service.sh | 13 +++++++++---- script/service.sh~ | 40 ++++++++++++++++++++++++++++++++++++++++ server/config/config.go | 1 + server/rest/rest-metric.go | 1 + server/yats.go | 19 +++++++++++++++++--
diff --git a/client/postMetric.sh b/client/postMetric.sh index b0edba9185b6ef58b05cf6efb19bdb83d075edd4..b9bed6fc5f5e835daca30805d920381afb5b8f5b 100755 --- a/client/postMetric.sh +++ b/client/postMetric.sh @@ -3,5 +3,5 @@ # curl \ -X POST\ --header "Content-Type: application/json"\ - -d '{"mtime":1713216483,"id_client":"test-cli","name":"test-measure","value":"vone"}'\ + -d '{"mtime":1713216484,"id_client":"test-cli","name":"test-measure","value":"vtwo"}'\ http://127.0.0.1:18081/metric diff --git a/script/service.sh b/script/service.sh index 6736fbb4f39405870a87c8c54a8097f5085bd11a..e3f6ee9f21ab6da61efd07c92f0c0976c80746c2 100755 --- a/script/service.sh +++ b/script/service.sh @@ -9,17 +9,22 @@ # Author: Paolo Lulli# Copyright: Paolo Lulli 2024 # - cd $(dirname $0) EXECUTABLE=../server/yats-server -if [ "$#" != "2" ]; then +instance="default" +if [ "$#" = "2" ]; then + instance=$1 + operation=$2 +else + operation=$1 +fi +if [ "$#" -lt "1" ]; then echo "Usage $0 <name> <start|stop>" exit 1 fi -instance=$1 -operation=$2 + PIDFILE=~/yats-${instance}.pid if [ "$operation" = "stop" ]; then PID2K=$(cat $PIDFILE) diff --git a/script/service.sh~ b/script/service.sh~ new file mode 100644 index 0000000000000000000000000000000000000000..f0c6d59ab989d4c530b4f987d9148ed9b541bebd --- /dev/null +++ b/script/service.sh~ @@ -0,0 +1,40 @@ +#! /bin/bash +# +# Yats - yats +# +# This file is licensed under the Affero General Public License version 3 or +# later. See the COPYING file. +# +# Author: Paolo Lulli <kevwe.com> +# Copyright: Paolo Lulli 2024 +# + + +cd $(dirname $0) + +EXECUTABLE=../server/yats-server + +instance="default" +if [ "$#" = "2" ]; then +operation=$2 +else +operation=$1 +fi +if [ "$#" < "1" ]; then + echo "Usage $0 <name> <start|stop>" + exit 1 +fi +instance=$1 +operation=$2 +PIDFILE=~/yats-${instance}.pid +if [ "$operation" = "stop" ]; then + PID2K=$(cat $PIDFILE) + kill -9 $PID2K && rm $PIDFILE + exit 0 +fi + +test -f $PIDFILE && echo PID file exist +test -f $PIDFILE && exit 1 + +export GIN_MODE=release +${EXECUTABLE} ${instance} & echo $! > $PIDFILE diff --git a/server/config/config.go b/server/config/config.go index fe89238c881204d679b7510280f89144a98dcceb..3889aab5e180501cd5060334507a933de66de724 100644 --- a/server/config/config.go +++ b/server/config/config.go @@ -46,6 +46,7 @@ REST_ADDRESS string `json:"restAddress"` ARCHIVE_FREQUENCY string `json:"archiveFrequency"` ARCHIVE_DIRECTORY string `json:"archiveDirectory"` + IS_ARCHIVE_NODE string `json:"archiveNode"` } func GetConfig(fileName string) Configuration { diff --git a/server/rest/rest-metric.go b/server/rest/rest-metric.go index 828efd1c36335b203d803117485d4eb75595372f..696ca69cb52e15c1795a929036e1613319f742ae 100644 --- a/server/rest/rest-metric.go +++ b/server/rest/rest-metric.go @@ -28,6 +28,7 @@ c.IndentedJSON(http.StatusAccepted, gin.H{"ret": "-1"}) return } + // header := c.Request.Header.Get("some-header") fmt.Printf("%s / %s / %s", metric.ID_client, metric.Name, metric.Value) db.SaveMetric(metric.ID_client, metric.Name, metric.Value) diff --git a/server/yats.go b/server/yats.go index 8c714096854092e98600ebc0d260131cd9e57c72..f900fc12f0e0b85849770719b48369544dcbfefc 100644 --- a/server/yats.go +++ b/server/yats.go @@ -11,16 +11,31 @@ package main import ( + "fmt" "os" "yats-server/config" "yats-server/db" ) +var configuration config.Configuration +var instanceName = "default" + func main() { - configuration := config.GetConfig(os.Getenv("HOME") + "/.yats.json") + args := os.Args + if len(args) < 2 { + fmt.Println("Loading default config") + configuration = config.GetConfig(os.Getenv("HOME") + "/.yats.json") + } else { + instanceName = args[1] + fmt.Printf("Loading instance: [%s] config", instanceName) + configuration = config.GetConfig(os.Getenv("HOME") + "/.yats/" + instanceName + ".json") + } + db.Session = db.InitializeDb(configuration) - go MaintenanceThread(configuration) + if configuration.IS_ARCHIVE_NODE == "true" { + go MaintenanceThread(configuration) + } RestService(configuration) }