delete old codes
This commit is contained in:
+1
-4
@@ -48,10 +48,7 @@ func (a *APP) Init() error {
|
|||||||
a.subServer = sub.NewServer()
|
a.subServer = sub.NewServer()
|
||||||
|
|
||||||
a.configService = service.NewConfigService(a.core)
|
a.configService = service.NewConfigService(a.core)
|
||||||
err = a.configService.InitConfig()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,9 +14,6 @@ var version string
|
|||||||
//go:embed name
|
//go:embed name
|
||||||
var name string
|
var name string
|
||||||
|
|
||||||
//go:embed config.json
|
|
||||||
var defaultConfig string
|
|
||||||
|
|
||||||
type LogLevel string
|
type LogLevel string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -72,24 +69,3 @@ func GetDBFolderPath() string {
|
|||||||
func GetDBPath() string {
|
func GetDBPath() string {
|
||||||
return fmt.Sprintf("%s/%s.db", GetDBFolderPath(), GetName())
|
return fmt.Sprintf("%s/%s.db", GetDBFolderPath(), GetName())
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetDefaultConfig() string {
|
|
||||||
apiEnv := GetEnvApi()
|
|
||||||
if len(apiEnv) > 0 {
|
|
||||||
return strings.Replace(defaultConfig, "127.0.0.1:1080", apiEnv, 1)
|
|
||||||
}
|
|
||||||
return defaultConfig
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetEnvApi() string {
|
|
||||||
return os.Getenv("SINGBOX_API")
|
|
||||||
}
|
|
||||||
|
|
||||||
func IsSystemd() bool {
|
|
||||||
pid := os.Getppid()
|
|
||||||
cmdline, err := os.ReadFile(fmt.Sprintf("/proc/%d/comm", pid))
|
|
||||||
if err != nil {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return string(cmdline) == "systemd\n"
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,29 +0,0 @@
|
|||||||
{
|
|
||||||
"log": {
|
|
||||||
"level": "info"
|
|
||||||
},
|
|
||||||
"dns": {},
|
|
||||||
"inbounds": [],
|
|
||||||
"outbounds": [
|
|
||||||
{
|
|
||||||
"tag": "direct",
|
|
||||||
"type": "direct"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "dns",
|
|
||||||
"tag": "dns-out"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"route": {
|
|
||||||
"rules": [
|
|
||||||
{
|
|
||||||
"protocol": [
|
|
||||||
"dns"
|
|
||||||
],
|
|
||||||
"outbound": "dns-out",
|
|
||||||
"action": "route"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"experimental": {}
|
|
||||||
}
|
|
||||||
@@ -3,7 +3,6 @@ package logger
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"s-ui/config"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/op/go-logging"
|
"github.com/op/go-logging"
|
||||||
@@ -29,7 +28,7 @@ func InitLogger(level logging.Level) {
|
|||||||
fmt.Println("Unable to use syslog: " + err.Error())
|
fmt.Println("Unable to use syslog: " + err.Error())
|
||||||
backend = logging.NewLogBackend(os.Stderr, "", 0)
|
backend = logging.NewLogBackend(os.Stderr, "", 0)
|
||||||
}
|
}
|
||||||
if config.IsSystemd() && err != nil {
|
if err != nil {
|
||||||
format = logging.MustStringFormatter(`%{time:2006/01/02 15:04:05} %{level} - %{message}`)
|
format = logging.MustStringFormatter(`%{time:2006/01/02 15:04:05} %{level} - %{message}`)
|
||||||
} else {
|
} else {
|
||||||
format = logging.MustStringFormatter(`%{level} - %{message}`)
|
format = logging.MustStringFormatter(`%{level} - %{message}`)
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package service
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"s-ui/config"
|
|
||||||
"s-ui/core"
|
"s-ui/core"
|
||||||
"s-ui/database"
|
"s-ui/database"
|
||||||
"s-ui/database/model"
|
"s-ui/database/model"
|
||||||
@@ -14,7 +13,6 @@ import (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
LastUpdate int64
|
LastUpdate int64
|
||||||
IsSystemd bool
|
|
||||||
corePtr *core.Core
|
corePtr *core.Core
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -43,11 +41,6 @@ func NewConfigService(core *core.Core) *ConfigService {
|
|||||||
return &ConfigService{}
|
return &ConfigService{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *ConfigService) InitConfig() error {
|
|
||||||
IsSystemd = config.IsSystemd()
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *ConfigService) GetConfig(data string) (*SingBoxConfig, error) {
|
func (s *ConfigService) GetConfig(data string) (*SingBoxConfig, error) {
|
||||||
var err error
|
var err error
|
||||||
if len(data) == 0 {
|
if len(data) == 0 {
|
||||||
|
|||||||
@@ -1,17 +0,0 @@
|
|||||||
[Unit]
|
|
||||||
Description=sing-box service
|
|
||||||
Documentation=https://sing-box.sagernet.org
|
|
||||||
After=network.target nss-lookup.target network-online.target
|
|
||||||
|
|
||||||
[Service]
|
|
||||||
CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE CAP_SYS_PTRACE CAP_DAC_READ_SEARCH
|
|
||||||
AmbientCapabilities=CAP_NET_ADMIN CAP_NET_BIND_SERVICE CAP_SYS_PTRACE CAP_DAC_READ_SEARCH
|
|
||||||
WorkingDirectory=/usr/local/s-ui/bin/
|
|
||||||
ExecStart=/usr/local/s-ui/bin/runSingbox.sh
|
|
||||||
ExecReload=/bin/kill -HUP $MAINPID
|
|
||||||
Restart=on-failure
|
|
||||||
RestartSec=10s
|
|
||||||
LimitNOFILE=infinity
|
|
||||||
|
|
||||||
[Install]
|
|
||||||
WantedBy=multi-user.target
|
|
||||||
Reference in New Issue
Block a user