mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-04-17 21:15:50 +00:00
Compare commits
7 commits
b621dd94d0
...
a9ddc11888
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a9ddc11888 | ||
|
|
c3603b9fd8 | ||
|
|
252c24d7fd | ||
|
|
af39f42b7e | ||
|
|
159b85f979 | ||
|
|
3ec5b3589f | ||
|
|
2b1d3e7347 |
10 changed files with 73 additions and 11 deletions
9
main.go
9
main.go
|
|
@ -16,6 +16,7 @@ import (
|
|||
"github.com/mhsanaei/3x-ui/v2/logger"
|
||||
"github.com/mhsanaei/3x-ui/v2/sub"
|
||||
"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/global"
|
||||
"github.com/mhsanaei/3x-ui/v2/web/service"
|
||||
|
|
@ -70,7 +71,7 @@ func runWebServer() {
|
|||
|
||||
sigCh := make(chan os.Signal, 1)
|
||||
// Trap shutdown signals
|
||||
signal.Notify(sigCh, syscall.SIGHUP, syscall.SIGTERM)
|
||||
signal.Notify(sigCh, syscall.SIGHUP, syscall.SIGTERM, sys.SIGUSR1)
|
||||
for {
|
||||
sig := <-sigCh
|
||||
|
||||
|
|
@ -108,6 +109,12 @@ func runWebServer() {
|
|||
return
|
||||
}
|
||||
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:
|
||||
// --- FIX FOR TELEGRAM BOT CONFLICT (409) on full shutdown ---
|
||||
|
|
|
|||
|
|
@ -7,11 +7,14 @@ import (
|
|||
"encoding/binary"
|
||||
"fmt"
|
||||
"sync"
|
||||
"syscall"
|
||||
|
||||
"github.com/shirou/gopsutil/v4/net"
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
var SIGUSR1 = syscall.SIGUSR1
|
||||
|
||||
func GetTCPCount() (int, error) {
|
||||
stats, err := net.Connections("tcp")
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -12,8 +12,11 @@ import (
|
|||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
var SIGUSR1 = syscall.SIGUSR1
|
||||
|
||||
func getLinesNum(filename string) (int, error) {
|
||||
file, err := os.Open(filename)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@ import (
|
|||
"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").
|
||||
func GetConnectionCount(proto string) (int, error) {
|
||||
if proto != "tcp" && proto != "udp" {
|
||||
|
|
|
|||
|
|
@ -490,3 +490,7 @@ func (s *Server) GetCron() *cron.Cron {
|
|||
func (s *Server) GetWSHub() any {
|
||||
return s.wsHub
|
||||
}
|
||||
|
||||
func (s *Server) RestartXray() error {
|
||||
return s.xrayService.RestartXray(true)
|
||||
}
|
||||
|
|
|
|||
5
x-ui.rc
5
x-ui.rc
|
|
@ -10,4 +10,9 @@ depend() {
|
|||
}
|
||||
start_pre(){
|
||||
cd /usr/local/x-ui
|
||||
}
|
||||
reload() {
|
||||
ebegin "Reloading ${RC_SVCNAME}"
|
||||
kill -USR1 $pidfile
|
||||
eend $?
|
||||
}
|
||||
|
|
@ -9,6 +9,7 @@ Environment="XRAY_VMESS_AEAD_FORCED=false"
|
|||
Type=simple
|
||||
WorkingDirectory=/usr/lib/x-ui/
|
||||
ExecStart=/usr/lib/x-ui/x-ui
|
||||
ExecReload=kill -USR1 $MAINPID
|
||||
Restart=on-failure
|
||||
RestartSec=5s
|
||||
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ Environment="XRAY_VMESS_AEAD_FORCED=false"
|
|||
Type=simple
|
||||
WorkingDirectory=/usr/local/x-ui/
|
||||
ExecStart=/usr/local/x-ui/x-ui
|
||||
ExecReload=kill -USR1 $MAINPID
|
||||
Restart=on-failure
|
||||
RestartSec=5s
|
||||
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ Environment="XRAY_VMESS_AEAD_FORCED=false"
|
|||
Type=simple
|
||||
WorkingDirectory=/usr/local/x-ui/
|
||||
ExecStart=/usr/local/x-ui/x-ui
|
||||
ExecReload=kill -USR1 $MAINPID
|
||||
Restart=on-failure
|
||||
RestartSec=5s
|
||||
|
||||
|
|
|
|||
55
x-ui.sh
55
x-ui.sh
|
|
@ -1673,15 +1673,29 @@ run_speedtest() {
|
|||
|
||||
run_librespeed() {
|
||||
|
||||
if command -v librespeed-cli &>/dev/null; then
|
||||
librespeed-cli
|
||||
else
|
||||
#Intalling LibreSpeed
|
||||
echo -e "${yellow} Installing LibreSpeed..."
|
||||
echo -e "${yellow}What do you want to do?\n1) Use\n2) Install/Update\n3) Delete"
|
||||
read -p ": " action
|
||||
|
||||
if [ "$action" = 1 ]; then
|
||||
if command -v librespeed-cli &>/dev/null; then
|
||||
librespeed-cli
|
||||
else
|
||||
echo -e "${red}LibreSpeed is not installed!"
|
||||
fi
|
||||
|
||||
elif [ "$action" = 2 ]; then
|
||||
echo -e "${yellow} Installing\Updating LibreSpeed..."
|
||||
#Uninstall old version, or actual version
|
||||
rm -f librespeed-cli_*_linux_amd64.tar.gz && rm -rf /usr/bin/librespeed-cli
|
||||
VERSION=$(curl -s "https://api.github.com/repos/librespeed/speedtest-cli/releases/latest"| grep '"tag_name":' | sed -E 's/.*"v?([^"]+)".*/\1/')
|
||||
wget https://github.com/librespeed/speedtest-cli/releases/download/v${VERSION}/librespeed-cli_${VERSION}_linux_amd64.tar.gz
|
||||
tar -xzvf librespeed-cli_${VERSION}_linux_amd64.tar.gz && mv librespeed-cli /usr/bin
|
||||
echo -e "${green}Starting libreSpeed... (Delete old archive)"
|
||||
librespeed-cli
|
||||
elif [ "$action" = 3 ]; then
|
||||
#Uninstall LibreSpeed
|
||||
rm -f librespeed-cli_*_linux_amd64.tar.gz && rm -rf /usr/bin/librespeed-cli
|
||||
echo -e "${green}LibreSpeed was deleted!"
|
||||
fi
|
||||
}
|
||||
|
||||
|
|
@ -1891,14 +1905,31 @@ EOF
|
|||
}
|
||||
|
||||
change_dns() {
|
||||
echo -e "${yellow}${plain}Changing DNS resolver"
|
||||
echo -e "${plain}Enter resolver (default: 9.9.9.9): "
|
||||
echo -e "${yellow}Changing DNS resolver"
|
||||
echo -e "${plain}Enter resolver (default: quad9): "
|
||||
read resolver
|
||||
|
||||
if [ -n "$resolver" ]; then
|
||||
echo "nameserver $resolver" > /etc/resolv.conf
|
||||
IPv6_on=$(cat /proc/sys/net/ipv6/conf/all/disable_ipv6)
|
||||
echo $IPv6_on
|
||||
|
||||
if [ "$IPv6_on" = 0 ]; then
|
||||
echo -e "${green}Your server using IPv6!"
|
||||
echo -e "${plain}Enter server for IPv6"
|
||||
read -p ": " resolver_ipv6
|
||||
if [ -n "$resolver" ] && [ -n "$resolver_ipv6" ]; then
|
||||
echo "nameserver $resolver" > /etc/resolv.conf
|
||||
echo "nameserver $resolver_ipv6" > /etc/resolv.conf
|
||||
else
|
||||
echo "nameserver 9.9.9.9" > /etc/resolv.conf
|
||||
echo "nameserver 2620:fe::fe" > /etc/resolv.conf
|
||||
fi
|
||||
else
|
||||
echo "nameserver 9.9.9.9" > /etc/resolv.conf
|
||||
echo -e "${green}IPv6 is disabled!"
|
||||
if [ -n "$resolver" ]; then
|
||||
echo "nameserver $resolver" > /etc/resolv.conf
|
||||
else
|
||||
echo "nameserver 9.9.9.9" > /etc/resolv.conf
|
||||
fi
|
||||
fi
|
||||
echo -e "${green}${plain}Done!"
|
||||
}
|
||||
|
|
@ -2394,6 +2425,7 @@ show_usage() {
|
|||
│ ${blue}x-ui start${plain} - Start │
|
||||
│ ${blue}x-ui stop${plain} - Stop │
|
||||
│ ${blue}x-ui restart${plain} - Restart │
|
||||
| ${blue}x-ui restart-xray${plain} - Restart Xray │
|
||||
│ ${blue}x-ui status${plain} - Current Status │
|
||||
│ ${blue}x-ui settings${plain} - Current Settings │
|
||||
│ ${blue}x-ui enable${plain} - Enable Autostart on OS Startup │
|
||||
|
|
@ -2561,6 +2593,9 @@ if [[ $# > 0 ]]; then
|
|||
"restart")
|
||||
check_install 0 && restart 0
|
||||
;;
|
||||
"restart-xray")
|
||||
check_install 0 && restart_xray 0
|
||||
;;
|
||||
"status")
|
||||
check_install 0 && status 0
|
||||
;;
|
||||
|
|
|
|||
Loading…
Reference in a new issue