2021-05-31 21:04:49 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* do clean in cli
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
require "bittorrent.php";
|
2022-03-09 12:08:14 +08:00
|
|
|
require 'cleanup.php';
|
2021-05-31 21:04:49 +08:00
|
|
|
|
|
|
|
|
$fd = fopen(sprintf('%s/nexus_cleanup_cli.lock', sys_get_temp_dir()), 'w+');
|
|
|
|
|
if (!flock($fd, LOCK_EX|LOCK_NB)) {
|
|
|
|
|
do_log("can not get lock, skip!");
|
2022-02-19 23:19:09 +08:00
|
|
|
exit();
|
2021-05-31 21:04:49 +08:00
|
|
|
}
|
|
|
|
|
register_shutdown_function(function () use ($fd) {
|
2022-02-19 23:19:09 +08:00
|
|
|
flock($fd, LOCK_UN);
|
2021-05-31 21:04:49 +08:00
|
|
|
fclose($fd);
|
|
|
|
|
});
|
|
|
|
|
|
2021-06-15 02:02:09 +08:00
|
|
|
$force = 0;
|
|
|
|
|
if (isset($_SERVER['argv'][1])) {
|
|
|
|
|
$force = $_SERVER['argv'][1] ? 1 : 0;
|
|
|
|
|
}
|
2022-03-09 12:08:14 +08:00
|
|
|
$logPrefix = "[CLEANUP_CLI]";
|
2021-05-31 21:04:49 +08:00
|
|
|
try {
|
2021-06-15 02:18:00 +08:00
|
|
|
if ($force) {
|
2021-06-15 10:05:33 +08:00
|
|
|
$result = docleanup(1, true);
|
2021-06-15 02:18:00 +08:00
|
|
|
} else {
|
2022-03-09 12:08:14 +08:00
|
|
|
$result = autoclean(true);
|
2021-06-15 02:18:00 +08:00
|
|
|
}
|
2022-03-09 12:08:14 +08:00
|
|
|
$log = "$logPrefix, DONE: $result";
|
2021-06-15 19:05:38 +08:00
|
|
|
do_log($log);
|
|
|
|
|
printProgress($log);
|
2021-05-31 21:04:49 +08:00
|
|
|
} catch (\Exception $exception) {
|
2022-03-09 12:08:14 +08:00
|
|
|
$log = "$logPrefix, ERROR: " . $exception->getMessage();
|
2021-06-15 19:05:38 +08:00
|
|
|
do_log($log);
|
|
|
|
|
printProgress($log);
|
2021-05-31 21:04:49 +08:00
|
|
|
throw new \RuntimeException($exception->getMessage());
|
|
|
|
|
}
|
|
|
|
|
|