优化日志和备份目录。卸载时直接删除日志目录

Signed-off-by: hitsword <admin@hitsword.com>
master
hitsword 2020-01-09 21:06:23 +08:00
parent 36c875fde8
commit 1d3e40923b
3 changed files with 27 additions and 15 deletions

View File

@ -278,9 +278,8 @@ function amh_module_uninstall()
{
if amh_module_status ; then
#clean proxys
php ${module_dir}hyproxy-cli.php --action='uninstall';
amh nginx reload;
#backup proxys
php ${module_dir}hyproxy-cli.php --action='backup';
#uninstall nginx modules
Cpunum=`cat /proc/cpuinfo |grep 'processor'|wc -l`;
@ -311,7 +310,7 @@ function amh_module_uninstall()
MysqlPass=`cat /home/wwwroot/index/web/Amysql/Config.php | awk '{ FS="\047Password\047] = \047"; RS="\047;" } { print $2}' | sed '/^$/d'`;
cd /usr/local/;
rm -rf ngx_cache_purge-2.3 ngx_cache_purge-2.3.tar.gz;
rm -rf /usr/local/nginx/conf/hyproxy /home/hyproxy_cache /home/hyproxy_cache_tmp;
rm -rf /usr/local/nginx/conf/hyproxy /home/hyproxy_cache /home/hyproxy_cache_tmp /home/hyproxy_logs;
rm -f /home/wwwroot/index/web/Controller/hyproxy.php /home/wwwroot/index/web/Model/hyproxys.php /home/wwwroot/index/web/View/{hyproxy_category.php,hyproxy_list.php,hyproxy_cache.php,hyproxy_cache_index.php,hyproxy_cache_del.php};
sed -i "/include hyproxy/d" /usr/local/nginx/conf/nginx.conf;
sed -i "/proxy_/d" /usr/local/nginx/conf/nginx.conf;

View File

@ -44,13 +44,13 @@ class hyproxys extends AmysqlModel
$proxy_pass = 'http://'.$proxy_pass;
}
$data = array(
'server_name' => $server_name,
'index' => 'index.php index.html index.htm',
'header_host' => '$host',
'proxy_pass' => $proxy_pass,
'proxy_cache' => 1,
'status' => 'start',
'time' => time()
'server_name' => $server_name,
'index' => 'index.php index.html index.htm',
'header_host' => '$host',
'proxy_pass' => $proxy_pass,
'proxy_cache' => 1,
'status' => 'start',
'time' => time()
);
$res = $this -> _insert('module_hyproxy', $data);
if ($res) {

View File

@ -10,12 +10,14 @@
header("status: 404 Not Found");
die();
}
define('DS', DIRECTORY_SEPARATOR); // 目录分隔符
define('AMH_ROOT', '/home/wwwroot/index/web' . DS); // AHM根目录
define('AMH_AMYSQL', AMH_ROOT . 'Amysql' . DS); // 系统目录
define('_HYPROXY', dirname(__FILE__) . DS); // HYProxy插件根目录
define('_HYCONF', '/usr/local/nginx/conf/hyproxy' . DS); // HYProxy Nginx conf目录
define('_HYLOGS', '/usr/local/nginx/logs' . DS); // HYProxy Nginx logs目录
define('_HYLOGS', '/home/hyproxy_logs' . DS); // HYProxy Nginx logs目录
define('_HYBAKS', '/home/hyproxy_backup' . DS); // HYProxy Backup目录
require_once(AMH_AMYSQL . 'Config.php'); //加载配置参数
require_once(_HYPROXY . 'Class/medoo.php'); //加载medoo数据库类库
@ -58,7 +60,8 @@
echo hyproxy_del($param['server_name']);
break;
case 'uninstall':
echo hyproxy_uninstall();
echo '';
// echo hyproxy_uninstall();
break;
case 'backup':
echo hyproxy_backup();
@ -125,6 +128,12 @@
if (!$row['status']=='start') {
$filebytes = unlink(_HYCONF.$row['server_name'].'.conf');//删除
} elseif (!empty($conf)) {
if (!is_dir(_HYCONF)) {
mkdir(_HYCONF, 0755);
}
if (!is_dir(_HYLOGS)) {
mkdir(_HYLOGS, 0755);
}
$filebytes = file_put_contents(_HYCONF.$row['server_name'].'.conf', $conf); //写入内容
//access_log_path不存在的话创建
if (file_exists(!$row['access_log_path'])) {
@ -276,6 +285,7 @@
}
/**
* 已作废
* 卸载插件时做的一些处理
* 谨慎使用
*/
@ -304,11 +314,14 @@
*/
function hyproxy_backup()
{
if (!is_dir(_HYBAKS)) {
mkdir(_HYBAKS, 0755);
}
global $medoo;
$table = 'module_hyproxy';
$list = $medoo->select($table, '*');
$filebytes = false;
$filename = _HYPROXY . 'baks' . DS . date("Y-m-d-H:i:s") . '.bak';
$filename = _HYBAKS . date("Y-m-d-H:i:s") . '.bak';
$filebytes = file_put_contents($filename, json_encode($list));//写入内容
if ($filebytes) {
$res="[OK] All proxy backup success.\n";
@ -325,7 +338,7 @@
*/
function hyproxy_restore($bak_name = null)
{
$backup_path = _HYPROXY . 'baks' . DS . $bak_name;
$backup_path = _HYBAKS. DS . $bak_name;
if (file_exists($backup_path)) {
$backup = file_get_contents($backup_path);
$list = json_decode($backup, true);