From ee87bf65b44c5844f2956538888b5d1acdf55bbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=80=97=E5=AD=90?= Date: Tue, 25 Jun 2024 18:42:00 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=B0=83=E6=95=B4=E9=83=A8=E5=88=86?= =?UTF-8?q?=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bootstrap/app.go | 2 +- pkg/tools/tools.go | 9 ++++++++- scripts/install_panel.sh | 21 +++++++++++++-------- scripts/panel.service | 21 +++++++++++++++++++++ 4 files changed, 43 insertions(+), 10 deletions(-) create mode 100644 scripts/panel.service diff --git a/bootstrap/app.go b/bootstrap/app.go index 7c0e126f..a6ddd209 100644 --- a/bootstrap/app.go +++ b/bootstrap/app.go @@ -11,7 +11,7 @@ import ( func Boot() { debug.SetGCPercent(10) - debug.SetMemoryLimit(512 << 20) + debug.SetMemoryLimit(64 << 20) zhcn.RegisterGlobal() diff --git a/pkg/tools/tools.go b/pkg/tools/tools.go index 3a336f30..9333adee 100644 --- a/pkg/tools/tools.go +++ b/pkg/tools/tools.go @@ -482,14 +482,21 @@ func UpdatePanel(panelInfo PanelInfo) error { _, _ = shell.Execf("chmod -R 700 /usr/bin/panel") color.Green().Printfln("设置完成") + color.Green().Printfln("运行升级后脚本...") if _, err = shell.Execf("bash /www/panel/scripts/update_panel.sh"); err != nil { - color.Red().Printfln("执行面板升级后脚本失败") + color.Red().Printfln("运行面板升级后脚本失败") return err } + if _, err = shell.Execf("cp -f /www/panel/scripts/panel.service /etc/systemd/system/panel.service"); err != nil { + color.Red().Printfln("写入面板服务文件失败") + return err + } + _, _ = shell.Execf("systemctl daemon-reload") if _, err = shell.Execf("panel writeSetting version " + panelInfo.Version); err != nil { color.Red().Printfln("写入面板版本号失败") return err } + color.Green().Printfln("升级完成") _, _ = shell.Execf("rm -rf /tmp/panel-storage.zip") _, _ = shell.Execf("rm -rf /tmp/panel.conf.bak") diff --git a/scripts/install_panel.sh b/scripts/install_panel.sh index 93aa9d9e..0526afaf 100644 --- a/scripts/install_panel.sh +++ b/scripts/install_panel.sh @@ -88,31 +88,31 @@ Prepare_System() { [ -s /etc/selinux/config ] && sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config setenforce 0 > /dev/null 2>&1 - ulimit -n 204800 - echo 6553560 > /proc/sys/fs/file-max + ulimit -n 1048576 + echo 2147483584 > /proc/sys/fs/file-max checkSoftNofile=$(cat /etc/security/limits.conf | grep '^* soft nofile .*$') checkHardNofile=$(cat /etc/security/limits.conf | grep '^* hard nofile .*$') checkSoftNproc=$(cat /etc/security/limits.conf | grep '^* soft nproc .*$') checkHardNproc=$(cat /etc/security/limits.conf | grep '^* hard nproc .*$') checkFsFileMax=$(cat /etc/sysctl.conf | grep '^fs.file-max.*$') if [ "${checkSoftNofile}" == "" ]; then - echo "* soft nofile 204800" >> /etc/security/limits.conf + echo "* soft nofile 1048576" >> /etc/security/limits.conf fi if [ "${checkHardNofile}" == "" ]; then - echo "* hard nofile 204800" >> /etc/security/limits.conf + echo "* hard nofile 1048576" >> /etc/security/limits.conf fi if [ "${checkSoftNproc}" == "" ]; then - echo "* soft nproc 204800" >> /etc/security/limits.conf + echo "* soft nproc 1048576" >> /etc/security/limits.conf fi if [ "${checkHardNproc}" == "" ]; then - echo "* hard nproc 204800 " >> /etc/security/limits.conf + echo "* hard nproc 1048576" >> /etc/security/limits.conf fi if [ "${checkFsFileMax}" == "" ]; then - echo fs.file-max = 6553560 >> /etc/sysctl.conf + echo fs.file-max = 2147483584 >> /etc/sysctl.conf fi # 自动开启 BBR - isBBRSupported=$(ls -l /lib/modules/*/kernel/net/ipv4/tcp_bbr.ko.xz | grep -c bbr) + isBBRSupported=$(ls -l /lib/modules/*/kernel/net/ipv4 | grep -c tcp_bbr) if [ "${isBBRSupported}" != "0" ]; then qdisc=$(sysctl net.core.default_qdisc | awk '{print $3}') echo "net.core.default_qdisc=${qdisc}" >> /etc/sysctl.conf @@ -323,6 +323,11 @@ ExecReload=kill -s HUP \$MAINPID ExecStop=kill -s QUIT \$MAINPID User=root Restart=always +RestartSec=5 +LimitNOFILE=1048576 +LimitNPROC=1048576 +LimitCORE=1048576 +Delegate=yes [Install] WantedBy=multi-user.target diff --git a/scripts/panel.service b/scripts/panel.service new file mode 100644 index 00000000..ba5b9e90 --- /dev/null +++ b/scripts/panel.service @@ -0,0 +1,21 @@ +[Unit] +Description=HaoZi Panel +After=syslog.target network.target +Wants=network.target + +[Service] +Type=simple +WorkingDirectory=/www/panel/ +ExecStart=/www/panel/panel --env="/www/panel/panel.conf" +ExecReload=kill -s HUP \$MAINPID +ExecStop=kill -s QUIT \$MAINPID +User=root +Restart=always +RestartSec=5 +LimitNOFILE=1048576 +LimitNPROC=1048576 +LimitCORE=1048576 +Delegate=yes + +[Install] +WantedBy=multi-user.target