新节点默认无在线;提供 debug 配置项以控制是否启用保存配置记录
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
package actions
|
||||
|
||||
import (
|
||||
"zzman/model"
|
||||
"jhman/model"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
@@ -2,7 +2,7 @@ package actions
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"zzman/model"
|
||||
"jhman/model"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
@@ -2,8 +2,8 @@ package actions
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"zzman/clients/jd"
|
||||
"zzman/model"
|
||||
"jhman/clients/jd"
|
||||
"jhman/model"
|
||||
)
|
||||
|
||||
func Clear() error {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package actions
|
||||
|
||||
import (
|
||||
"zzman/model"
|
||||
"jhman/model"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
@@ -2,7 +2,7 @@ package actions
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"zzman/model"
|
||||
"jhman/model"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
@@ -2,8 +2,8 @@ package actions
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"jhman/model"
|
||||
"math"
|
||||
"zzman/model"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
@@ -2,10 +2,10 @@ package actions
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"jhman/model"
|
||||
"strconv"
|
||||
"zzman/model"
|
||||
|
||||
u "zzman/util"
|
||||
u "jhman/util"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
@@ -3,9 +3,9 @@ package actions
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"jhman/clients/jd"
|
||||
"jhman/model"
|
||||
"time"
|
||||
"zzman/clients/jd"
|
||||
"zzman/model"
|
||||
)
|
||||
|
||||
func RecordSubmit(time time.Time, gatewat model.Gateway, edges []jd.EdgeInfo) error {
|
||||
|
||||
@@ -2,9 +2,9 @@ package actions
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"jhman/clients/jd"
|
||||
"jhman/model"
|
||||
"log/slog"
|
||||
"zzman/clients/jd"
|
||||
"zzman/model"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
@@ -2,11 +2,12 @@ package actions
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"jhman/clients/jd"
|
||||
"jhman/model"
|
||||
u "jhman/util"
|
||||
"log/slog"
|
||||
"os"
|
||||
"time"
|
||||
"zzman/clients/jd"
|
||||
"zzman/model"
|
||||
u "zzman/util"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
@@ -140,7 +141,7 @@ func update(tx *gorm.DB, arg UpdateArgs) error {
|
||||
Id: config.Id,
|
||||
EdgeMac: u.P(edge.Macaddr),
|
||||
IsChange: u.P(0),
|
||||
IsOnline: u.P(1),
|
||||
IsOnline: u.P(0),
|
||||
},
|
||||
}
|
||||
changesCreate = append(changesCreate, model.Change{
|
||||
@@ -166,9 +167,11 @@ func update(tx *gorm.DB, arg UpdateArgs) error {
|
||||
step = time.Now()
|
||||
|
||||
// 记录节点变更
|
||||
err = RecordChanges(tx, changesCreate)
|
||||
if err != nil {
|
||||
return fmt.Errorf("记录节点变更失败:%w", err)
|
||||
if os.Getenv("DEBUG") == "true" {
|
||||
err = RecordChanges(tx, changesCreate)
|
||||
if err != nil {
|
||||
return fmt.Errorf("记录节点变更失败:%w", err)
|
||||
}
|
||||
}
|
||||
|
||||
println(fmt.Sprintf("记录节点变更:%v", time.Since(step)))
|
||||
@@ -203,9 +206,11 @@ func update(tx *gorm.DB, arg UpdateArgs) error {
|
||||
}
|
||||
|
||||
// 记录提交配置
|
||||
err = RecordSubmit(now, gateway, edges)
|
||||
if err != nil {
|
||||
return fmt.Errorf("记录网关 %s 提交配置失败:%w", gateway.Macaddr, err)
|
||||
if os.Getenv("DEBUG") == "true" {
|
||||
err = RecordSubmit(now, gateway, edges)
|
||||
if err != nil {
|
||||
return fmt.Errorf("记录网关 %s 提交配置失败:%w", gateway.Macaddr, err)
|
||||
}
|
||||
}
|
||||
|
||||
// 提交配置到云端:配置版本 gateway.ConfigVersion
|
||||
|
||||
@@ -6,11 +6,12 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/redis/go-redis/v9"
|
||||
"io"
|
||||
"jhman/clients"
|
||||
"net/http"
|
||||
"time"
|
||||
"zzman/clients"
|
||||
|
||||
"github.com/redis/go-redis/v9"
|
||||
)
|
||||
|
||||
const base = "https://smart.jdbox.xyz:58001"
|
||||
|
||||
6
main.go
6
main.go
@@ -2,14 +2,14 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"jhman/actions"
|
||||
"jhman/clients"
|
||||
"jhman/model"
|
||||
"log/slog"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"strings"
|
||||
"zzman/actions"
|
||||
"zzman/clients"
|
||||
"zzman/model"
|
||||
|
||||
"github.com/joho/godotenv"
|
||||
slogjournal "github.com/systemd/slog-journal"
|
||||
|
||||
12
rollback.sh
Normal file
12
rollback.sh
Normal file
@@ -0,0 +1,12 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# 此脚本应当运行在服务端,与 deploy.ps1 脚本上传到的位置配合,自动切换回退
|
||||
|
||||
cp cli cli.new
|
||||
chmod -x cli.new
|
||||
|
||||
chmod +x cli.bak
|
||||
mv cli.bak cli
|
||||
|
||||
echo 'done~'
|
||||
Reference in New Issue
Block a user