From 084177a20c194767f227edb61acef236f99061f8 Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Tue, 31 Mar 2020 19:57:05 +0200 Subject: Avoid multiple run of expiry procedure on large sites --- Zotlabs/Daemon/Expire.php | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'Zotlabs') diff --git a/Zotlabs/Daemon/Expire.php b/Zotlabs/Daemon/Expire.php index 398425861..bce512b6d 100644 --- a/Zotlabs/Daemon/Expire.php +++ b/Zotlabs/Daemon/Expire.php @@ -9,6 +9,13 @@ class Expire { cli_startup(); + if ($pid = get_xconfig(0, 'expire', 'procid', false)) { + logger('Expire: procedure already run with PID ' . $pid); + return; + } + + set_xconfig(0, 'expire', 'procid', getmypid()); + // perform final cleanup on previously delete items $r = q("select id from item where item_deleted = 1 and item_pending_remove = 0 and changed < %s - INTERVAL %s", @@ -90,5 +97,7 @@ class Expire { logger('Expire: sys: done', LOGGER_DEBUG); } + + del_xconfig(0, 'expire', 'procid'); } } -- cgit v1.2.3 From 710448e73fe753c3bd1cac954ea7b5a750a416d1 Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Tue, 31 Mar 2020 19:58:08 +0200 Subject: Update Expire.php --- Zotlabs/Daemon/Expire.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Daemon/Expire.php b/Zotlabs/Daemon/Expire.php index bce512b6d..186e88fc9 100644 --- a/Zotlabs/Daemon/Expire.php +++ b/Zotlabs/Daemon/Expire.php @@ -8,11 +8,11 @@ class Expire { static public function run($argc,$argv){ cli_startup(); - - if ($pid = get_xconfig(0, 'expire', 'procid', false)) { - logger('Expire: procedure already run with PID ' . $pid); - return; - } + + if ($pid = get_xconfig(0, 'expire', 'procid', false)) { + logger('Expire: procedure already run with PID ' . $pid, LOGGER_DEBUG); + return; + } set_xconfig(0, 'expire', 'procid', getmypid()); -- cgit v1.2.3 From 632996f53e0ff364566a95536b94614387c2582a Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Tue, 31 Mar 2020 20:03:29 +0200 Subject: Add check if expire procedure is still running --- Zotlabs/Daemon/Expire.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Daemon/Expire.php b/Zotlabs/Daemon/Expire.php index 186e88fc9..c8fb72bb2 100644 --- a/Zotlabs/Daemon/Expire.php +++ b/Zotlabs/Daemon/Expire.php @@ -9,7 +9,7 @@ class Expire { cli_startup(); - if ($pid = get_xconfig(0, 'expire', 'procid', false)) { + if ($pid = get_xconfig(0, 'expire', 'procid', false) && posix_getpgid($pid)) { logger('Expire: procedure already run with PID ' . $pid, LOGGER_DEBUG); return; } -- cgit v1.2.3 From 6c02fa40f11b2d1bd6d058a569a31ac249975e7e Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Tue, 31 Mar 2020 20:15:09 +0200 Subject: Check if POSIX PHP module is available on PID check --- Zotlabs/Daemon/Expire.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Daemon/Expire.php b/Zotlabs/Daemon/Expire.php index c8fb72bb2..374f919e6 100644 --- a/Zotlabs/Daemon/Expire.php +++ b/Zotlabs/Daemon/Expire.php @@ -9,7 +9,7 @@ class Expire { cli_startup(); - if ($pid = get_xconfig(0, 'expire', 'procid', false) && posix_getpgid($pid)) { + if ($pid = get_xconfig(0, 'expire', 'procid', false) && (function_exists('posix_getpgid') ? posix_getpgid($pid) : true)) { logger('Expire: procedure already run with PID ' . $pid, LOGGER_DEBUG); return; } -- cgit v1.2.3 From 9773ab7aab3fd694e3ac9de2e88e606d6b04db90 Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Tue, 31 Mar 2020 20:45:15 +0200 Subject: Use POSIX kill 0 to check expire process status --- Zotlabs/Daemon/Expire.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Daemon/Expire.php b/Zotlabs/Daemon/Expire.php index 374f919e6..bc9e720e9 100644 --- a/Zotlabs/Daemon/Expire.php +++ b/Zotlabs/Daemon/Expire.php @@ -9,7 +9,7 @@ class Expire { cli_startup(); - if ($pid = get_xconfig(0, 'expire', 'procid', false) && (function_exists('posix_getpgid') ? posix_getpgid($pid) : true)) { + if ($pid = get_xconfig(0, 'expire', 'procid', false) && (function_exists('posix_kill') ? posix_kill($pid, 0) : true)) { logger('Expire: procedure already run with PID ' . $pid, LOGGER_DEBUG); return; } -- cgit v1.2.3 From 4a56b77f64f1483bc933a69a70be02df2f8f9187 Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Tue, 31 Mar 2020 21:00:21 +0200 Subject: Use pconfig --- Zotlabs/Daemon/Expire.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Daemon/Expire.php b/Zotlabs/Daemon/Expire.php index bc9e720e9..4bdf7ddeb 100644 --- a/Zotlabs/Daemon/Expire.php +++ b/Zotlabs/Daemon/Expire.php @@ -9,12 +9,12 @@ class Expire { cli_startup(); - if ($pid = get_xconfig(0, 'expire', 'procid', false) && (function_exists('posix_kill') ? posix_kill($pid, 0) : true)) { + if ($pid = get_pconfig(0, 'expire', 'procid', false) && (function_exists('posix_kill') ? posix_kill($pid, 0) : true)) { logger('Expire: procedure already run with PID ' . $pid, LOGGER_DEBUG); return; } - - set_xconfig(0, 'expire', 'procid', getmypid()); + + set_pconfig(0, 'expire', 'procid', getmypid()); // perform final cleanup on previously delete items @@ -98,6 +98,6 @@ class Expire { logger('Expire: sys: done', LOGGER_DEBUG); } - del_xconfig(0, 'expire', 'procid'); + del_pconfig(0, 'expire', 'procid'); } } -- cgit v1.2.3 From c136c142b8148abe75696ca0076a107f04e74d30 Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Wed, 1 Apr 2020 12:59:12 +0200 Subject: Use config instead pconfig --- Zotlabs/Daemon/Expire.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Daemon/Expire.php b/Zotlabs/Daemon/Expire.php index 4bdf7ddeb..f3f42df6f 100644 --- a/Zotlabs/Daemon/Expire.php +++ b/Zotlabs/Daemon/Expire.php @@ -9,12 +9,12 @@ class Expire { cli_startup(); - if ($pid = get_pconfig(0, 'expire', 'procid', false) && (function_exists('posix_kill') ? posix_kill($pid, 0) : true)) { + if ($pid = get_config('expire', 'procid', false) && (function_exists('posix_kill') ? posix_kill($pid, 0) : true)) { logger('Expire: procedure already run with PID ' . $pid, LOGGER_DEBUG); return; } - set_pconfig(0, 'expire', 'procid', getmypid()); + set_config('expire', 'procid', getmypid()); // perform final cleanup on previously delete items @@ -98,6 +98,6 @@ class Expire { logger('Expire: sys: done', LOGGER_DEBUG); } - del_pconfig(0, 'expire', 'procid'); + del_config('expire', 'procid'); } } -- cgit v1.2.3 From 3372fb0761353f646ae2b7bd168650eea5fd6211 Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Wed, 8 Apr 2020 11:31:17 +0200 Subject: Fix process id disclouse --- Zotlabs/Daemon/Expire.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Daemon/Expire.php b/Zotlabs/Daemon/Expire.php index f3f42df6f..a688d6f97 100644 --- a/Zotlabs/Daemon/Expire.php +++ b/Zotlabs/Daemon/Expire.php @@ -9,12 +9,14 @@ class Expire { cli_startup(); - if ($pid = get_config('expire', 'procid', false) && (function_exists('posix_kill') ? posix_kill($pid, 0) : true)) { - logger('Expire: procedure already run with PID ' . $pid, LOGGER_DEBUG); + $pid = get_config('expire', 'procid', false); + if ($pid && (function_exists('posix_kill') ? posix_kill($pid, 0) : true)) { + logger('Expire: procedure already run with pid ' . $pid, LOGGER_DEBUG); return; } - set_config('expire', 'procid', getmypid()); + $pid = getmypid(); + set_config('expire', 'procid', $pid); // perform final cleanup on previously delete items @@ -39,7 +41,7 @@ class Expire { if (intval(get_config('system', 'optimize_items'))) q("optimize table item"); - logger('expire: start', LOGGER_DEBUG); + logger('expire: start with pid ' . $pid, LOGGER_DEBUG); $site_expire = intval(get_config('system', 'default_expire_days')); $commented_days = intval(get_config('system','active_expire_days')); -- cgit v1.2.3