mirror of
https://github.com/tnb-labs/panel.git
synced 2026-10-13 16:58:05 +08:00
fix(openlitespeed): lsphp 改为 OLS 子进程,重载 OLS 即可重启
外部应用 runOnStartUp 默认 3 是 detached 模式,lsphp 脱离 OLS 独立存活,重载、停止 OLS 都不会动它,之前只能手动删 socket 再杀父进程。改成 1 后 lsphp 是 OLS 的子进程,重载 OLS 就会同步外部应用参数并重启 lsphp,移除 RestartPHP Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -172,11 +172,6 @@ func (s *App) SetPHP(w http.ResponseWriter, r *http.Request) {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
// 旧的 lsphp 不随 OLS 重载退出,关闭 LSAPI 后会一直残留
|
||||
if err = openlitespeed.RestartPHP(req.Version); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
service.Success(w, nil)
|
||||
}
|
||||
|
||||
@@ -1087,7 +1087,7 @@ func (s *EnvironmentPHPService) probeSocket(version uint) (string, bool) {
|
||||
return s.phpFPMSocket(version), false
|
||||
}
|
||||
|
||||
// applyLSAPI LSAPI 下 lsphp 由 OLS 托管,改了配置要重载 OLS 同步外部应用参数,再重启 lsphp 才会生效
|
||||
// applyLSAPI LSAPI 下 lsphp 是 OLS 的子进程,重载 OLS 会同步外部应用参数并重启 lsphp
|
||||
func (s *EnvironmentPHPService) applyLSAPI(ctx context.Context, version uint) error {
|
||||
if !openlitespeed.LSAPIEnabled(version) {
|
||||
return nil
|
||||
@@ -1096,9 +1096,6 @@ func (s *EnvironmentPHPService) applyLSAPI(ctx context.Context, version uint) er
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err = d.Reload(context.WithoutCancel(ctx)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return openlitespeed.RestartPHP(version)
|
||||
return d.Reload(context.WithoutCancel(ctx))
|
||||
}
|
||||
|
||||
@@ -9,9 +9,6 @@ import (
|
||||
"regexp"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/shirou/gopsutil/v4/process"
|
||||
|
||||
"github.com/acepanel/panel/v3/pkg/systemctl"
|
||||
"github.com/acepanel/panel/v3/pkg/webserver/conf"
|
||||
@@ -98,6 +95,8 @@ func syncPHP() error {
|
||||
ext.Add("persistConn", "1")
|
||||
ext.Add("respBuffer", "0")
|
||||
ext.Add("autoStart", "1")
|
||||
// 默认 3 是 detached 模式,lsphp 脱离 OLS 独立存活,重载、停止 OLS 都不会动它
|
||||
ext.Add("runOnStartUp", "1")
|
||||
ext.Add("path", LSPHPPath(version))
|
||||
ext.Add("backlog", "100")
|
||||
ext.Add("instances", "1")
|
||||
@@ -127,38 +126,6 @@ func LSAPISocket(version uint) string {
|
||||
return fmt.Sprintf("/tmp/lshttpd/php%d.sock", version)
|
||||
}
|
||||
|
||||
// RestartPHP 重启 lsphp 让 php.ini 与外部应用参数生效,OLS 以 detached 模式托管 lsphp,重载 OLS 不会重启它。
|
||||
// 照 OLS 自己的重启流程:先删 socket 让新请求连不到旧进程,再只给父进程发 SIGTERM,
|
||||
// 子进程处理完当前请求后退出,OLS 收到下个请求时拉起新进程
|
||||
func RestartPHP(version uint) error {
|
||||
if err := os.Remove(LSAPISocket(version)); err != nil && !os.IsNotExist(err) {
|
||||
return err
|
||||
}
|
||||
|
||||
procs, err := process.Processes()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
exe := LSPHPPath(version)
|
||||
for _, p := range procs {
|
||||
if name, _ := p.Name(); name != "lsphp" {
|
||||
continue
|
||||
}
|
||||
// 二进制被替换后 exe 会带 " (deleted)" 后缀
|
||||
if path, _ := p.Exe(); !strings.HasPrefix(path, exe) {
|
||||
continue
|
||||
}
|
||||
if parent, err := p.Parent(); err == nil {
|
||||
if name, _ := parent.Name(); name == "lsphp" {
|
||||
continue
|
||||
}
|
||||
}
|
||||
_ = p.Terminate()
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// SyncFPM 按 LSAPI 的启用情况开停 php-fpm
|
||||
func SyncFPM(ctx context.Context, active bool) error {
|
||||
var errs []error
|
||||
|
||||
Reference in New Issue
Block a user