mirror of
https://github.com/kuaifan/dootask.git
synced 2025-12-15 13:22:49 +00:00
no message
This commit is contained in:
parent
959b30c788
commit
b9180a4426
@ -132,7 +132,7 @@ class AppsController extends AbstractController
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} api/apps/update_status 04. 更新应用状态
|
||||
* @api {post} api/apps/update/status 04. 更新应用状态
|
||||
*
|
||||
* @apiVersion 1.0.0
|
||||
* @apiGroup apps
|
||||
@ -145,7 +145,7 @@ class AppsController extends AbstractController
|
||||
* @apiSuccess {String} msg 返回信息(错误描述)
|
||||
* @apiSuccess {Object} data 更新结果
|
||||
*/
|
||||
public function updateStatus()
|
||||
public function update__status()
|
||||
{
|
||||
$appName = Request::input('app_name');
|
||||
$status = Request::input('status');
|
||||
@ -172,10 +172,8 @@ class AppsController extends AbstractController
|
||||
'status' => $status
|
||||
];
|
||||
|
||||
// 如果状态是安装成功,记录完成时间
|
||||
if ($status === 'installed') {
|
||||
// todo 安装完成要更新nginx配置
|
||||
}
|
||||
// 更新nginx配置
|
||||
Apps::nginxUpdate($appName);
|
||||
|
||||
// 保存配置
|
||||
if (Apps::saveAppLocalInfo($appName, $updateData)) {
|
||||
@ -184,7 +182,7 @@ class AppsController extends AbstractController
|
||||
return Base::retError('更新状态失败');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @api {get} api/apps/logs 05. 获取应用日志
|
||||
*
|
||||
@ -204,33 +202,33 @@ class AppsController extends AbstractController
|
||||
{
|
||||
$appName = Request::input('app_name');
|
||||
$lines = intval(Request::input('lines', 50));
|
||||
|
||||
|
||||
if (empty($appName)) {
|
||||
return Base::retError('应用名称不能为空');
|
||||
}
|
||||
|
||||
|
||||
// 限制获取行数
|
||||
if ($lines <= 0) {
|
||||
$lines = 50;
|
||||
} else if ($lines > 2000) {
|
||||
$lines = 2000;
|
||||
}
|
||||
|
||||
|
||||
// 日志文件路径
|
||||
$logFile = base_path('docker/logs/apps/' . $appName . '.log');
|
||||
|
||||
|
||||
if (!file_exists($logFile)) {
|
||||
return Base::retSuccess('日志返回成功', [
|
||||
'log' => ''
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
// 读取日志文件最后几行
|
||||
$output = [];
|
||||
$cmd = 'tail -n ' . $lines . ' ' . escapeshellarg($logFile);
|
||||
exec($cmd, $output);
|
||||
$logContent = implode("\n", $output);
|
||||
|
||||
|
||||
return Base::retSuccess('日志返回成功', [
|
||||
'log' => $logContent
|
||||
]);
|
||||
|
||||
@ -111,30 +111,12 @@ class Apps
|
||||
$result['generate'] = $res['data'];
|
||||
|
||||
// 执行docker-compose命令
|
||||
$res = self::curl("apps/{$command}/{$appName}");
|
||||
$res = self::curl("apps/{$command}/{$appName}?callback_url=" . urlencode('http://nginx/api/apps/update/status'));
|
||||
if (Base::isError($res)) {
|
||||
return $res;
|
||||
}
|
||||
$result['compose'] = $res['data'];
|
||||
|
||||
// nginx配置文件处理 // todo 要单独处理
|
||||
$nginxFile = $versionInfo['path'] . '/nginx.conf';
|
||||
$nginxTarget = base_path('docker/nginx/apps/' . $appName . '.conf');
|
||||
if (file_exists($nginxTarget)) {
|
||||
unlink($nginxTarget);
|
||||
}
|
||||
if (file_exists($nginxFile)) {
|
||||
if ($command === 'up') {
|
||||
copy($nginxFile, $nginxTarget);
|
||||
}
|
||||
// 重启nginx
|
||||
$res = self::curl("nginx/reload");
|
||||
if (Base::isError($res)) {
|
||||
return $res;
|
||||
}
|
||||
$result['nginx'] = $res['data'];
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
return Base::retSuccess("success", $result);
|
||||
}
|
||||
@ -150,6 +132,46 @@ class Apps
|
||||
return self::dockerComposeUp($appName, $version, 'down');
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新nginx配置
|
||||
* @param string $appName
|
||||
* @return array
|
||||
*/
|
||||
public static function nginxUpdate(string $appName): array
|
||||
{
|
||||
// 获取本地安装信息
|
||||
$localInfo = self::getAppLocalInfo($appName);
|
||||
|
||||
// nginx配置文件处理
|
||||
$nginxFile = base_path('docker/apps/' . $appName . '/' . $localInfo['installed_version'] . '/nginx.conf');
|
||||
$nginxTarget = base_path('docker/nginx/apps/' . $appName . '.conf');
|
||||
$needReload = false;
|
||||
if (file_exists($nginxTarget)) {
|
||||
unlink($nginxTarget);
|
||||
$needReload = true;
|
||||
}
|
||||
if (file_exists($nginxFile) && $localInfo['status'] === 'installed') {
|
||||
copy($nginxFile, $nginxTarget);
|
||||
$res = self::curl("nginx/test");
|
||||
if (Base::isError($res)) {
|
||||
unlink($nginxTarget);
|
||||
return $res;
|
||||
}
|
||||
$needReload = true;
|
||||
}
|
||||
|
||||
// 重启nginx
|
||||
if ($needReload) {
|
||||
$res = self::curl("nginx/reload");
|
||||
if (Base::isError($res)) {
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
return Base::retSuccess("success");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取应用信息
|
||||
* @param string $appName 应用名称
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user