Merge branch 'main' into main

This commit is contained in:
menschenfresser 2026-02-27 23:04:05 +07:00 committed by GitHub
commit 91aad724c2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 32 additions and 1 deletions

View file

@ -16,6 +16,7 @@ import (
"github.com/mhsanaei/3x-ui/v2/logger" "github.com/mhsanaei/3x-ui/v2/logger"
"github.com/mhsanaei/3x-ui/v2/sub" "github.com/mhsanaei/3x-ui/v2/sub"
"github.com/mhsanaei/3x-ui/v2/util/crypto" "github.com/mhsanaei/3x-ui/v2/util/crypto"
"github.com/mhsanaei/3x-ui/v2/util/sys"
"github.com/mhsanaei/3x-ui/v2/web" "github.com/mhsanaei/3x-ui/v2/web"
"github.com/mhsanaei/3x-ui/v2/web/global" "github.com/mhsanaei/3x-ui/v2/web/global"
"github.com/mhsanaei/3x-ui/v2/web/service" "github.com/mhsanaei/3x-ui/v2/web/service"
@ -70,7 +71,7 @@ func runWebServer() {
sigCh := make(chan os.Signal, 1) sigCh := make(chan os.Signal, 1)
// Trap shutdown signals // Trap shutdown signals
signal.Notify(sigCh, syscall.SIGHUP, syscall.SIGTERM) signal.Notify(sigCh, syscall.SIGHUP, syscall.SIGTERM, sys.SIGUSR1)
for { for {
sig := <-sigCh sig := <-sigCh
@ -108,6 +109,12 @@ func runWebServer() {
return return
} }
log.Println("Sub server restarted successfully.") log.Println("Sub server restarted successfully.")
case sys.SIGUSR1:
logger.Info("Received USR1 signal, restarting xray-core...")
err := server.RestartXray()
if err != nil {
logger.Error("Failed to restart xray-core:", err)
}
default: default:
// --- FIX FOR TELEGRAM BOT CONFLICT (409) on full shutdown --- // --- FIX FOR TELEGRAM BOT CONFLICT (409) on full shutdown ---

View file

@ -7,11 +7,14 @@ import (
"encoding/binary" "encoding/binary"
"fmt" "fmt"
"sync" "sync"
"syscall"
"github.com/shirou/gopsutil/v4/net" "github.com/shirou/gopsutil/v4/net"
"golang.org/x/sys/unix" "golang.org/x/sys/unix"
) )
var SIGUSR1 = syscall.SIGUSR1
func GetTCPCount() (int, error) { func GetTCPCount() (int, error) {
stats, err := net.Connections("tcp") stats, err := net.Connections("tcp")
if err != nil { if err != nil {

View file

@ -12,8 +12,11 @@ import (
"strconv" "strconv"
"strings" "strings"
"sync" "sync"
"syscall"
) )
var SIGUSR1 = syscall.SIGUSR1
func getLinesNum(filename string) (int, error) { func getLinesNum(filename string) (int, error) {
file, err := os.Open(filename) file, err := os.Open(filename)
if err != nil { if err != nil {

View file

@ -12,6 +12,8 @@ import (
"github.com/shirou/gopsutil/v4/net" "github.com/shirou/gopsutil/v4/net"
) )
var SIGUSR1 = syscall.Signal(0)
// GetConnectionCount returns the number of active connections for the specified protocol ("tcp" or "udp"). // GetConnectionCount returns the number of active connections for the specified protocol ("tcp" or "udp").
func GetConnectionCount(proto string) (int, error) { func GetConnectionCount(proto string) (int, error) {
if proto != "tcp" && proto != "udp" { if proto != "tcp" && proto != "udp" {

View file

@ -490,3 +490,7 @@ func (s *Server) GetCron() *cron.Cron {
func (s *Server) GetWSHub() any { func (s *Server) GetWSHub() any {
return s.wsHub return s.wsHub
} }
func (s *Server) RestartXray() error {
return s.xrayService.RestartXray(true)
}

View file

@ -11,3 +11,8 @@ depend() {
start_pre(){ start_pre(){
cd /usr/local/x-ui cd /usr/local/x-ui
} }
reload() {
ebegin "Reloading ${RC_SVCNAME}"
kill -USR1 $pidfile
eend $?
}

View file

@ -9,6 +9,7 @@ Environment="XRAY_VMESS_AEAD_FORCED=false"
Type=simple Type=simple
WorkingDirectory=/usr/lib/x-ui/ WorkingDirectory=/usr/lib/x-ui/
ExecStart=/usr/lib/x-ui/x-ui ExecStart=/usr/lib/x-ui/x-ui
ExecReload=kill -USR1 $MAINPID
Restart=on-failure Restart=on-failure
RestartSec=5s RestartSec=5s

View file

@ -9,6 +9,7 @@ Environment="XRAY_VMESS_AEAD_FORCED=false"
Type=simple Type=simple
WorkingDirectory=/usr/local/x-ui/ WorkingDirectory=/usr/local/x-ui/
ExecStart=/usr/local/x-ui/x-ui ExecStart=/usr/local/x-ui/x-ui
ExecReload=kill -USR1 $MAINPID
Restart=on-failure Restart=on-failure
RestartSec=5s RestartSec=5s

View file

@ -9,6 +9,7 @@ Environment="XRAY_VMESS_AEAD_FORCED=false"
Type=simple Type=simple
WorkingDirectory=/usr/local/x-ui/ WorkingDirectory=/usr/local/x-ui/
ExecStart=/usr/local/x-ui/x-ui ExecStart=/usr/local/x-ui/x-ui
ExecReload=kill -USR1 $MAINPID
Restart=on-failure Restart=on-failure
RestartSec=5s RestartSec=5s

View file

@ -2394,6 +2394,7 @@ show_usage() {
${blue}x-ui start${plain} - Start │ ${blue}x-ui start${plain} - Start │
${blue}x-ui stop${plain} - Stop │ ${blue}x-ui stop${plain} - Stop │
${blue}x-ui restart${plain} - Restart │ ${blue}x-ui restart${plain} - Restart │
| ${blue}x-ui restart-xray${plain} - Restart Xray │
${blue}x-ui status${plain} - Current Status │ ${blue}x-ui status${plain} - Current Status │
${blue}x-ui settings${plain} - Current Settings │ ${blue}x-ui settings${plain} - Current Settings │
${blue}x-ui enable${plain} - Enable Autostart on OS Startup │ ${blue}x-ui enable${plain} - Enable Autostart on OS Startup │
@ -2561,6 +2562,9 @@ if [[ $# > 0 ]]; then
"restart") "restart")
check_install 0 && restart 0 check_install 0 && restart 0
;; ;;
"restart-xray")
check_install 0 && restart_xray 0
;;
"status") "status")
check_install 0 && status 0 check_install 0 && status 0
;; ;;