mirror of
https://github.com/dragonheim/gagent.git
synced 2025-04-25 11:08:59 -07:00
fix: was using struct member for two different things.
This commit is contained in:
parent
7a9225ce86
commit
db351f3892
5 changed files with 18 additions and 24 deletions
|
@ -1,5 +1,5 @@
|
||||||
FROM nikatjef/golang:1.20 as builder
|
FROM dragonheim/golang:1.20 as builder
|
||||||
ARG SEMVER=${SEMVER:-0.0.8}
|
ARG SEMVER=${SEMVER:-0.0.9}
|
||||||
|
|
||||||
WORKDIR /gagent
|
WORKDIR /gagent
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
|
@ -4,7 +4,6 @@ import (
|
||||||
log "log"
|
log "log"
|
||||||
http "net/http"
|
http "net/http"
|
||||||
os "os"
|
os "os"
|
||||||
strconv "strconv"
|
|
||||||
sync "sync"
|
sync "sync"
|
||||||
|
|
||||||
autorestart "github.com/slayer/autorestart"
|
autorestart "github.com/slayer/autorestart"
|
||||||
|
@ -56,7 +55,7 @@ var environment struct {
|
||||||
* This is the application version number. It can be overridden at build time
|
* This is the application version number. It can be overridden at build time
|
||||||
* using the -ldflags "-X main.semVER=0.0.1" option.
|
* using the -ldflags "-X main.semVER=0.0.1" option.
|
||||||
*/
|
*/
|
||||||
var semVER = "0.0.8"
|
var semVER = "0.0.9"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This is the application configuration. It is populated from the configuration
|
* This is the application configuration. It is populated from the configuration
|
||||||
|
@ -131,8 +130,6 @@ func main() {
|
||||||
* reads the environment variables. It also sets up the logging.
|
* reads the environment variables. It also sets up the logging.
|
||||||
*/
|
*/
|
||||||
func init() {
|
func init() {
|
||||||
autorestart.StartWatcher()
|
|
||||||
|
|
||||||
cfg := environment
|
cfg := environment
|
||||||
if err := env.Parse(&cfg); err != nil {
|
if err := env.Parse(&cfg); err != nil {
|
||||||
log.Printf("%+v\n", err)
|
log.Printf("%+v\n", err)
|
||||||
|
@ -261,7 +258,7 @@ func init() {
|
||||||
log.Printf("[ERROR] Agent file not specified")
|
log.Printf("[ERROR] Agent file not specified")
|
||||||
os.Exit(8)
|
os.Exit(8)
|
||||||
} else {
|
} else {
|
||||||
config.File = opts["--agent"].(string)
|
config.Agent = opts["--agent"].(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
if opts["pull"] == true {
|
if opts["pull"] == true {
|
||||||
|
@ -287,10 +284,13 @@ func init() {
|
||||||
/*
|
/*
|
||||||
* Start Prometheus metrics exporter
|
* Start Prometheus metrics exporter
|
||||||
*/
|
*/
|
||||||
if config.MonitorPort != 0 {
|
// if config.MonitorPort != 0 {
|
||||||
go func() {
|
// go func() {
|
||||||
log.Printf("[INFO] Starting Prometheus metrics exporter on port %d\n", config.MonitorPort)
|
// log.Printf("[INFO] Starting Prometheus metrics exporter on port %d\n", config.MonitorPort)
|
||||||
log.Fatal(http.ListenAndServe(string(config.ListenAddr)+":"+strconv.Itoa(config.MonitorPort), nil))
|
// log.Fatal(http.ListenAndServe(string(config.ListenAddr)+":"+strconv.Itoa(config.MonitorPort), nil))
|
||||||
}()
|
// }()
|
||||||
}
|
// }
|
||||||
|
autorestart.WatchFilename = config.File
|
||||||
|
autorestart.StartWatcher()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
log "log"
|
log "log"
|
||||||
os "os"
|
os "os"
|
||||||
regexp "regexp"
|
regexp "regexp"
|
||||||
|
strconv "strconv"
|
||||||
strings "strings"
|
strings "strings"
|
||||||
sync "sync"
|
sync "sync"
|
||||||
time "time"
|
time "time"
|
||||||
|
@ -33,9 +34,9 @@ func Main(wg *sync.WaitGroup, config gstructs.GagentConfig) {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
if config.CMode {
|
if config.CMode {
|
||||||
agent.ScriptCode, err = ioutil.ReadFile(config.File)
|
agent.ScriptCode, err = ioutil.ReadFile(config.Agent)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("[ERROR] No such file or directory: %s", config.File)
|
log.Printf("[ERROR] No such file or directory: %s", config.Agent)
|
||||||
os.Exit(4)
|
os.Exit(4)
|
||||||
}
|
}
|
||||||
log.Printf("[DEBUG] Agent file contents: \n----- -----\n%s\n----- -----\n", agent.ScriptCode)
|
log.Printf("[DEBUG] Agent file contents: \n----- -----\n%s\n----- -----\n", agent.ScriptCode)
|
||||||
|
@ -56,7 +57,7 @@ func Main(wg *sync.WaitGroup, config gstructs.GagentConfig) {
|
||||||
if config.Routers[key].ClientPort != 0 {
|
if config.Routers[key].ClientPort != 0 {
|
||||||
rport = config.Routers[key].ClientPort
|
rport = config.Routers[key].ClientPort
|
||||||
}
|
}
|
||||||
connectString := fmt.Sprintf("tcp://%s:%d", config.Routers[key].RouterAddr, rport)
|
connectString := "tcp://" + config.Routers[key].RouterAddr + ":" + strconv.Itoa(rport)
|
||||||
|
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go sendAgent(wg, config.UUID, connectString, agent)
|
go sendAgent(wg, config.UUID, connectString, agent)
|
||||||
|
|
|
@ -18,6 +18,7 @@ type GagentConfig struct {
|
||||||
Workers []*WorkerDetails `hcl:"worker,block"`
|
Workers []*WorkerDetails `hcl:"worker,block"`
|
||||||
Version string
|
Version string
|
||||||
File string
|
File string
|
||||||
|
Agent string
|
||||||
CMode bool
|
CMode bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,17 +10,10 @@ import (
|
||||||
gcdb "github.com/dragonheim/gagent/internal/chaindb"
|
gcdb "github.com/dragonheim/gagent/internal/chaindb"
|
||||||
gstructs "github.com/dragonheim/gagent/internal/gstructs"
|
gstructs "github.com/dragonheim/gagent/internal/gstructs"
|
||||||
|
|
||||||
prometheus "github.com/prometheus/client_golang/prometheus"
|
|
||||||
promauto "github.com/prometheus/client_golang/prometheus/promauto"
|
|
||||||
|
|
||||||
zmq "github.com/pebbe/zmq4"
|
zmq "github.com/pebbe/zmq4"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
opsProcessed = promauto.NewCounter(prometheus.CounterOpts{
|
|
||||||
Name: "client_requests_received",
|
|
||||||
})
|
|
||||||
|
|
||||||
db gcdb.GagentDb
|
db gcdb.GagentDb
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -144,7 +137,6 @@ func unwrap(msg []string) (head string, tail []string) {
|
||||||
|
|
||||||
func answerClient(w http.ResponseWriter, r *http.Request) {
|
func answerClient(w http.ResponseWriter, r *http.Request) {
|
||||||
if r.URL.Path != "/" {
|
if r.URL.Path != "/" {
|
||||||
opsProcessed.Inc()
|
|
||||||
/*
|
/*
|
||||||
* fmt.Fprintf(w, "%v\n", r)
|
* fmt.Fprintf(w, "%v\n", r)
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue