Spaces:
Running
Running
package app | |
import ( | |
"context" | |
"kpl/internal/conf" | |
"kpl/pkg/logx" | |
"kpl/pkg/tools" | |
"os" | |
"time" | |
) | |
func Run(ctx context.Context) { | |
cleanUp := tools.Stack{} | |
ctx = logx.TagContext(ctx, "initial") | |
logx.Init(ctx) | |
// config | |
conf.Init(ctx) | |
// http | |
cleanUp.Push(Start(ctx)) | |
// 提示 保活列表 | |
for i, url := range conf.CONF.HgUrls { | |
logx.WithContext(ctx).Info("HG_URL", i, ": ", url) | |
} | |
for i, serv00 := range conf.CONF.Serv00s { | |
logx.WithContext(ctx).Info("Serv00", i, ": ", serv00.Username, "@", serv00.Host, ":", serv00.Port) | |
} | |
AsyncTimingTask(time.Duration(conf.CONF.HgIntervalSec)*time.Second, func() { | |
for _, url := range conf.CONF.HgUrls { | |
go DoGetRequest(ctx, url, conf.CONF.Proxy) | |
} | |
}) | |
AsyncTimingTask(time.Duration(conf.CONF.Serv00IntervalSec)*time.Second, func() { | |
for _, serv00 := range conf.CONF.Serv00s { | |
go KplServ00(ctx, serv00.Username, serv00.Password, serv00.Host, serv00.Port, serv00.Cmd) | |
} | |
}) | |
// Handle signals | |
{ | |
exitCode := 1 | |
exitCode = tools.HandleSignals(exitCode) | |
ctx = logx.TagContext(ctx, "cleanup") | |
for cleanUp.Next() { | |
cleanUp.Pop()(ctx) | |
} | |
time.Sleep(time.Second) | |
os.Exit(exitCode) | |
} | |
} | |