mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-09-30 06:16:37 +08:00
83a11ead2b
- Introduced OperationSetting component for managing agent configurations. - Updated settings page to include a new tab for operation settings. - Implemented functionality to fetch and update agent parameters such as heartbeat interval, sync interval, and auto-update settings. docs: enhance deployment documentation for agent installation - Added detailed instructions for agent installation using a script. - Included examples for using discovery and agent tokens. - Updated sections on global discovery tokens and agent auto-update features. docs: revise design and development guidelines for V3 - Updated design document to reflect the current state and goals for V3. - Clarified development guidelines to focus on operational experience improvements. ci: add GitHub Actions workflow for agent releases - Created a new workflow to automate the release of agent binaries on GitHub. - Configured the workflow to build binaries for multiple platforms and publish them as releases. feat: implement self-update mechanism for agent - Added updater module to handle checking for and applying updates from GitHub releases. - Implemented logic to restart the agent after a successful update. chore: create install script for agent deployment - Developed a bash script to facilitate the installation of the ATSFlare agent. - The script supports automatic configuration and systemd service creation.
74 lines
2.2 KiB
Go
74 lines
2.2 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"flag"
|
|
"log"
|
|
"os/signal"
|
|
"syscall"
|
|
|
|
"atsflare-agent/internal/agent"
|
|
"atsflare-agent/internal/config"
|
|
"atsflare-agent/internal/heartbeat"
|
|
"atsflare-agent/internal/httpclient"
|
|
"atsflare-agent/internal/nginx"
|
|
"atsflare-agent/internal/state"
|
|
syncservice "atsflare-agent/internal/sync"
|
|
"atsflare-agent/internal/updater"
|
|
)
|
|
|
|
func main() {
|
|
configPath := flag.String("config", "./agent.json", "agent config path")
|
|
flag.Parse()
|
|
|
|
cfg, err := config.Load(*configPath)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
cfg.NginxVersion = nginx.DetectVersion(
|
|
context.Background(),
|
|
nginx.ExecutorOptions{
|
|
NginxPath: cfg.NginxPath,
|
|
DockerBinary: cfg.DockerBinary,
|
|
ContainerName: cfg.NginxContainerName,
|
|
Image: cfg.NginxDockerImage,
|
|
RouteConfigPath: cfg.RouteConfigPath,
|
|
CertDir: cfg.CertDir,
|
|
NginxCertDir: cfg.NginxCertDir,
|
|
},
|
|
)
|
|
log.Printf("agent config loaded: server=%s node=%s ip=%s heartbeat_interval=%s sync_interval=%s route_config=%s cert_dir=%s", cfg.ServerURL, cfg.NodeName, cfg.NodeIP, cfg.HeartbeatInterval, cfg.SyncInterval, cfg.RouteConfigPath, cfg.CertDir)
|
|
|
|
client := httpclient.New(cfg.ServerURL, cfg.AgentToken, cfg.RequestTimeout.Duration())
|
|
stateStore := state.NewStore(cfg.StatePath)
|
|
runner := &agent.Runner{
|
|
Config: cfg,
|
|
StateStore: stateStore,
|
|
HeartbeatService: heartbeat.New(client),
|
|
SyncService: syncservice.New(client, &nginx.Manager{
|
|
RouteConfigPath: cfg.RouteConfigPath,
|
|
CertDir: cfg.CertDir,
|
|
NginxCertDir: cfg.NginxCertDir,
|
|
Executor: nginx.NewExecutor(nginx.ExecutorOptions{
|
|
NginxPath: cfg.NginxPath,
|
|
DockerBinary: cfg.DockerBinary,
|
|
ContainerName: cfg.NginxContainerName,
|
|
Image: cfg.NginxDockerImage,
|
|
RouteConfigPath: cfg.RouteConfigPath,
|
|
CertDir: cfg.CertDir,
|
|
NginxCertDir: cfg.NginxCertDir,
|
|
}),
|
|
}, stateStore),
|
|
Updater: updater.New(),
|
|
}
|
|
|
|
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
|
|
defer stop()
|
|
log.Printf("agent process started")
|
|
|
|
if err = runner.Run(ctx); err != nil && err != context.Canceled {
|
|
log.Fatal(err)
|
|
}
|
|
log.Printf("agent process stopped")
|
|
}
|