Browse Source

修复守护进程bind失败,即解决端口重用问题(1年的bug解决)

docker-svn
witersen 3 years ago
parent
commit
381c314d61
  1. 17
      01.web/src/views/advance/index.vue
  2. 4
      02.php/api.php
  3. 8
      02.php/app/service/Svn.php
  4. 10
      02.php/app/service/base/Base.php
  5. 21
      02.php/server/svnadmind.php

17
01.web/src/views/advance/index.vue

@ -12,18 +12,13 @@
</Col> </Col>
<Col span="1"> </Col> <Col span="1"> </Col>
<Col span="6"> <Col span="6">
<Button <Tooltip
type="error" :transfer="true"
v-if="formSvn.installed == 1 || formSvn.installed == 2" max-width="360"
@click="UnInstall" content="可以使用系统提供的 install.php 文件在命令行模式下进行Subversion安装和初始化等操作"
>卸载</Button
>
<Button
type="primary"
v-if="formSvn.installed == 0"
@click="Install"
>安装</Button
> >
<Button type="info">tips</Button>
</Tooltip>
</Col> </Col>
<Col span="6"> </Col> <Col span="6"> </Col>
</Row> </Row>

4
02.php/api.php

@ -3,7 +3,7 @@
* @Author: witersen * @Author: witersen
* @Date: 2022-04-24 23:37:06 * @Date: 2022-04-24 23:37:06
* @LastEditors: witersen * @LastEditors: witersen
* @LastEditTime: 2022-05-09 17:35:57 * @LastEditTime: 2022-05-09 21:11:05
* @Description: QQ:1801168257 * @Description: QQ:1801168257
*/ */
@ -99,7 +99,7 @@ $state = FunDetectState();
if ($state == 0) { if ($state == 0) {
json1(401, 0, '守护进程响应超时'); json1(401, 0, '守护进程响应超时');
} else if ($state == 2) { } else if ($state == 2) {
json1(401, 0, '守护进程未启动'); json1(401, 0, '后台程序未启动');
} }
/** /**

8
02.php/app/service/Svn.php

@ -3,7 +3,7 @@
* @Author: witersen * @Author: witersen
* @Date: 2022-04-24 23:37:05 * @Date: 2022-04-24 23:37:05
* @LastEditors: witersen * @LastEditors: witersen
* @LastEditTime: 2022-05-09 17:04:19 * @LastEditTime: 2022-05-09 20:52:21
* @Description: QQ:1801168257 * @Description: QQ:1801168257
*/ */
@ -25,7 +25,7 @@ class Svn extends Base
$result = $result['result']; $result = $result['result'];
if ($result == '') { if ($result == '') {
return message(200, 0, 'svnserve服务未在运行,SVN用户将无法使用仓库浏览功能'); return message(200, 0, 'svnserve服务未在运行,SVN用户将无法使用系统的仓库在线内容浏览功能');
} else { } else {
return message(); return message();
} }
@ -75,7 +75,7 @@ class Svn extends Base
//运行中+已加入环境变量 //运行中+已加入环境变量
if ($isRun && $isInstall) { if ($isRun && $isInstall) {
return 1; return 2;
} }
//未运行+未加入环境变量 //未运行+未加入环境变量
@ -85,7 +85,7 @@ class Svn extends Base
//未运行+已加入环境变量 //未运行+已加入环境变量
if (!$isRun && $isInstall) { if (!$isRun && $isInstall) {
return 2; return 1;
} }
} }

10
02.php/app/service/base/Base.php

@ -3,7 +3,7 @@
* @Author: witersen * @Author: witersen
* @Date: 2022-05-06 18:42:00 * @Date: 2022-05-06 18:42:00
* @LastEditors: witersen * @LastEditors: witersen
* @LastEditTime: 2022-05-09 16:38:22 * @LastEditTime: 2022-05-09 21:10:15
* @Description: QQ:1801168257 * @Description: QQ:1801168257
*/ */
@ -203,7 +203,7 @@ class Base
return [ return [
'code' => 401, 'code' => 401,
'status' => 0, 'status' => 0,
'message' => '非法请求', 'message' => 'token为空',
'data' => [] 'data' => []
]; ];
} }
@ -213,7 +213,7 @@ class Base
return [ return [
'code' => 401, 'code' => 401,
'status' => 0, 'status' => 0,
'message' => '非法请求', 'message' => 'token格式错误',
'data' => [] 'data' => []
]; ];
} }
@ -226,7 +226,7 @@ class Base
return [ return [
'code' => 401, 'code' => 401,
'status' => 0, 'status' => 0,
'message' => '非法请求', 'message' => 'token格式错误',
'data' => [] 'data' => []
]; ];
} }
@ -239,7 +239,7 @@ class Base
return [ return [
'code' => 401, 'code' => 401,
'status' => 0, 'status' => 0,
'message' => '非法请求', 'message' => 'token校验失败',
'data' => [] 'data' => []
]; ];
} }

21
02.php/server/svnadmind.php

@ -3,7 +3,7 @@
* @Author: witersen * @Author: witersen
* @Date: 2022-04-24 23:37:06 * @Date: 2022-04-24 23:37:06
* @LastEditors: witersen * @LastEditors: witersen
* @LastEditTime: 2022-05-09 00:00:19 * @LastEditTime: 2022-05-09 22:30:20
* @Description: QQ:1801168257 * @Description: QQ:1801168257
*/ */
@ -85,13 +85,21 @@ class Daemon
private function InitSocket() private function InitSocket()
{ {
//创建套接字 //创建套接字
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP) or exit('启动失败:socket_create 错误' . PHP_EOL); $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP) or exit('启动失败:socket_create 错误:' . socket_strerror(socket_last_error()) . PHP_EOL);
//设置可重复使用端口号
if (!socket_set_option($socket, SOL_SOCKET, SO_REUSEADDR, 1)) {
exit('启动失败:设置套接字选项错误:' . socket_strerror(socket_last_error()) . PHP_EOL);
}
//绑定地址和端口 //绑定地址和端口
socket_bind($socket, $this->config_daemon['IPC_ADDRESS'], $this->config_daemon['IPC_PORT']) or exit('启动失败:socket_bind 错误,可能是由于频繁启动,端口未释放,请稍后重试或检查端口冲突' . PHP_EOL); socket_bind($socket, $this->config_daemon['IPC_ADDRESS'], $this->config_daemon['IPC_PORT']) or exit('启动失败:socket_bind 错误,可能是由于频繁启动,端口未释放,请稍后重试或检查端口冲突' . PHP_EOL);
//设置可重复使用端口号 $rval = socket_get_option($socket, SOL_SOCKET, SO_REUSEADDR);
socket_set_option($socket, SOL_SOCKET, SO_REUSEADDR, 1);
if ($rval === false) {
exit('启动失败:无法获取套接字选项:' . socket_strerror(socket_last_error()) . PHP_EOL);
}
//监听 设置并发队列的最大长度 //监听 设置并发队列的最大长度
socket_listen($socket, $this->config_daemon['SOCKET_LISTEN_BACKLOG']); socket_listen($socket, $this->config_daemon['SOCKET_LISTEN_BACKLOG']);
@ -241,6 +249,8 @@ class Daemon
exit('程序正在运行中' . PHP_EOL); exit('程序正在运行中' . PHP_EOL);
} }
} }
$this->UpdateSign();
echo '已在启动时自动更改系统的加密密钥,正在登录的用户会退出登录' . PHP_EOL;
$this->InitDeamon(); $this->InitDeamon();
} }
@ -265,7 +275,7 @@ class Daemon
$pid = file_get_contents($this->pidFile); $pid = file_get_contents($this->pidFile);
$result = trim(shell_exec("ps -ax | awk '{ print $1 }' | grep -e \"^$pid$\"")); $result = trim(shell_exec("ps -ax | awk '{ print $1 }' | grep -e \"^$pid$\""));
if (strstr($result, $pid)) { if (strstr($result, $pid)) {
exit('程序正在运行中,请先停止' . PHP_EOL); exit('无法进入调试模式,请先停止后台程序' . PHP_EOL);
} }
} }
$this->InitSocket(); $this->InitSocket();
@ -286,7 +296,6 @@ class Daemon
$this->CheckPhpVersion(); $this->CheckPhpVersion();
$this->CheckDisabledFun(); $this->CheckDisabledFun();
if ($this->workMode == 'start') { if ($this->workMode == 'start') {
$this->UpdateSign();
$this->StartDaemon(); $this->StartDaemon();
} else if ($this->workMode == 'console') { } else if ($this->workMode == 'console') {
$this->StartConsole(); $this->StartConsole();

Loading…
Cancel
Save