优化make的时候判断日志文件是否存在,不存在则创建

Signed-off-by: hitsword <admin@hitsword.com>
master
hitsword 2020-01-09 20:39:09 +08:00
parent c8c430d070
commit 36c875fde8
1 changed files with 16 additions and 6 deletions

View File

@ -114,12 +114,26 @@
hy_deldir(_HYCONF);//删除所有 hy_deldir(_HYCONF);//删除所有
} }
foreach ($list as $row) { foreach ($list as $row) {
$filebytes = false; //定义日志完整路径
$row['access_log_path'] = _HYLOGS . $row['server_name'] . '.access.log';
$row['error_log_path'] = _HYLOGS . $row['server_name'] . '.error.log';
//构建conf内容
$conf = hy_build_nginx_conf($row); $conf = hy_build_nginx_conf($row);
//文件操作
$filebytes = false;
if (!$row['status']=='start') { if (!$row['status']=='start') {
$filebytes = unlink(_HYCONF.$row['server_name'].'.conf');//删除 $filebytes = unlink(_HYCONF.$row['server_name'].'.conf');//删除
} elseif (!empty($conf)) { } elseif (!empty($conf)) {
$filebytes = file_put_contents(_HYCONF.$row['server_name'].'.conf', $conf); //写入内容 $filebytes = file_put_contents(_HYCONF.$row['server_name'].'.conf', $conf); //写入内容
//access_log_path不存在的话创建
if (file_exists(!$row['access_log_path'])) {
file_put_contents($row['access_log_path'], '');
}
//error_log_path不存在的话创建
if (file_exists(!$row['error_log_path'])) {
file_put_contents($row['error_log_path'], '');
}
} }
if ($filebytes) { if ($filebytes) {
@ -380,11 +394,7 @@
} }
$conf = false; $conf = false;
if (!empty($row)) { if (!empty($row['server_name'])) {
//定义日志完整路径
$row['access_log_path'] = _HYLOGS . $row['server_name'] . '.access.log';
$row['error_log_path'] = _HYLOGS . $row['server_name'] . '.error.log';
//判断使用哪个模板 //判断使用哪个模板
$template = false; $template = false;
if (!empty($row['proxy_cache']) && !empty($proxy_cache_template)) { if (!empty($row['proxy_cache']) && !empty($proxy_cache_template)) {