Merge pull request #35 from pxgamer/feature/sanity-orphan
Update to use the sanity interval for the lock
This commit is contained in:
34
sanity.php
34
sanity.php
@@ -23,6 +23,9 @@ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|||||||
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
|
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
|
||||||
OR OTHER DEALINGS IN THE SOFTWARE.
|
OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
const SANITY_LOCK_PATH = __DIR__.'/tmp/sanity-lock';
|
||||||
|
|
||||||
set_time_limit(0);
|
set_time_limit(0);
|
||||||
error_reporting(0);
|
error_reporting(0);
|
||||||
|
|
||||||
@@ -31,8 +34,10 @@ if (php_sapi_name() !== 'cli') {
|
|||||||
die("This should only be run as cli");
|
die("This should only be run as cli");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
require_once __DIR__.'/include/init.inc.php';
|
||||||
|
|
||||||
// make sure there's only a single sanity process running at the same time
|
// make sure there's only a single sanity process running at the same time
|
||||||
if (file_exists("tmp/sanity-lock")) {
|
if (file_exists(SANITY_LOCK_PATH)) {
|
||||||
$ignore_lock = false;
|
$ignore_lock = false;
|
||||||
if ($argv[1] == "force") {
|
if ($argv[1] == "force") {
|
||||||
$res = intval(shell_exec("ps aux|grep sanity.php|grep -v grep|wc -l"));
|
$res = intval(shell_exec("ps aux|grep sanity.php|grep -v grep|wc -l"));
|
||||||
@@ -40,17 +45,20 @@ if (file_exists("tmp/sanity-lock")) {
|
|||||||
$ignore_lock = true;
|
$ignore_lock = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$pid_time = filemtime("tmp/sanity-lock");
|
$pid_time = filemtime(SANITY_LOCK_PATH);
|
||||||
// if the process died, restart after 1day
|
|
||||||
if (time() - $pid_time > 86400) {
|
// If the process died, restart after 3 times the sanity interval
|
||||||
@unlink("tmp/sanity-lock");
|
if (time() - $pid_time > ($_config['sanity_interval'] ?? 900 * 3)) {
|
||||||
|
@unlink(SANITY_LOCK_PATH);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$ignore_lock) {
|
if (!$ignore_lock) {
|
||||||
die("Sanity lock in place");
|
die("Sanity lock in place".PHP_EOL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// set the new sanity lock
|
// set the new sanity lock
|
||||||
$lock = fopen("tmp/sanity-lock", "w");
|
$lock = fopen(SANITY_LOCK_PATH, "w");
|
||||||
fclose($lock);
|
fclose($lock);
|
||||||
$arg = trim($argv[1]);
|
$arg = trim($argv[1]);
|
||||||
$arg2 = trim($argv[2]);
|
$arg2 = trim($argv[2]);
|
||||||
@@ -60,8 +68,6 @@ if ($arg != "microsanity") {
|
|||||||
sleep(3);
|
sleep(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
require_once __DIR__.'/include/init.inc.php';
|
|
||||||
|
|
||||||
if ($argv[1]=="dev") {
|
if ($argv[1]=="dev") {
|
||||||
error_reporting(E_ALL & ~E_DEPRECATED & ~E_STRICT & ~E_NOTICE);
|
error_reporting(E_ALL & ~E_DEPRECATED & ~E_STRICT & ~E_NOTICE);
|
||||||
ini_set("display_errors", "on");
|
ini_set("display_errors", "on");
|
||||||
@@ -70,7 +76,7 @@ if ($argv[1]=="dev") {
|
|||||||
// the sanity can't run without the schema being installed
|
// the sanity can't run without the schema being installed
|
||||||
if ($_config['dbversion'] < 2) {
|
if ($_config['dbversion'] < 2) {
|
||||||
die("DB schema not created");
|
die("DB schema not created");
|
||||||
@unlink("tmp/sanity-lock");
|
@unlink(SANITY_LOCK_PATH);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -233,7 +239,7 @@ if ($arg == "microsanity" && !empty($arg2)) {
|
|||||||
_log("Synced block from $host - $b[height] $b[difficulty]");
|
_log("Synced block from $host - $b[height] $b[difficulty]");
|
||||||
} while (0);
|
} while (0);
|
||||||
|
|
||||||
@unlink("tmp/sanity-lock");
|
@unlink(SANITY_LOCK_PATH);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -273,7 +279,7 @@ if ($total_peers == 0 && $_config['testnet'] == false) {
|
|||||||
try {
|
try {
|
||||||
$peers = $initialPeers->getAll();
|
$peers = $initialPeers->getAll();
|
||||||
} catch (\Arionum\Node\Exception $e) {
|
} catch (\Arionum\Node\Exception $e) {
|
||||||
@unlink('tmp/sanity-lock');
|
@unlink(SANITY_LOCK_PATH);
|
||||||
die($e->getMessage().PHP_EOL);
|
die($e->getMessage().PHP_EOL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -325,7 +331,7 @@ if ($total_peers == 0 && $_config['testnet'] == false) {
|
|||||||
$total_peers = count($r);
|
$total_peers = count($r);
|
||||||
if ($total_peers == 0) {
|
if ($total_peers == 0) {
|
||||||
// something went wrong, could not add any peers -> exit
|
// something went wrong, could not add any peers -> exit
|
||||||
@unlink("tmp/sanity-lock");
|
@unlink(SANITY_LOCK_PATH);
|
||||||
die("Could not peer to any peers! Please check internet connectivity!\n");
|
die("Could not peer to any peers! Please check internet connectivity!\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -798,4 +804,4 @@ if ($_config['sanity_recheck_blocks'] > 0 && $_config['testnet'] == false) {
|
|||||||
|
|
||||||
_log("Finishing sanity");
|
_log("Finishing sanity");
|
||||||
|
|
||||||
@unlink("tmp/sanity-lock");
|
@unlink(SANITY_LOCK_PATH);
|
||||||
|
|||||||
Reference in New Issue
Block a user