()
| 18 | ) |
| 19 | |
| 20 | func init() { |
| 21 | if !teaconst.IsMain { |
| 22 | return |
| 23 | } |
| 24 | |
| 25 | events.On(events.EventReload, func() { |
| 26 | // linux only |
| 27 | if runtime.GOOS != "linux" { |
| 28 | return |
| 29 | } |
| 30 | |
| 31 | nodeConfig, err := nodeconfigs.SharedNodeConfig() |
| 32 | if err != nil { |
| 33 | return |
| 34 | } |
| 35 | |
| 36 | if nodeConfig == nil || !nodeConfig.AutoInstallNftables { |
| 37 | return |
| 38 | } |
| 39 | |
| 40 | if os.Getgid() == 0 { // root user only |
| 41 | if len(NftExePath()) > 0 { |
| 42 | return |
| 43 | } |
| 44 | goman.New(func() { |
| 45 | err := NewInstaller().Install() |
| 46 | if err != nil { |
| 47 | // 不需要传到API节点 |
| 48 | logs.Println("[NFTABLES]install nftables failed: " + err.Error()) |
| 49 | } |
| 50 | }) |
| 51 | } |
| 52 | }) |
| 53 | } |
| 54 | |
| 55 | // NftExePath 查找nftables可执行文件路径 |
| 56 | func NftExePath() string { |
nothing calls this directly
no test coverage detected