first commit

This commit is contained in:
Pavel Shevaev 2022-05-17 14:13:43 +03:00
commit 844b39628b
2 changed files with 55 additions and 0 deletions

11
composer.json Normal file
View File

@ -0,0 +1,11 @@
{
"name": "bit/taskman_lock",
"description": "taskman gamectl lock utils",
"homepage": "https://git.bit5.ru/composer/taskman_lock",
"require": {
"php": ">=7.4"
},
"autoload": {
"classmap": ["lock.inc.php"]
}
}

44
lock.inc.php Normal file
View File

@ -0,0 +1,44 @@
<?php
namespace taskman;
function gamectl_check_lock()
{
global $GAME_ROOT;
if(getenv("GAMECTL_IN_LOCK"))
return;
//don't bother with windows
if(DIRECTORY_SEPARATOR != '/')
return;
$lock = $GAME_ROOT . '/gamectl.lock';
while(file_exists($lock))
{
echo "gamectl is locked. Waiting...\n";
$pid = file_get_contents($lock);
if(!trim(exec("lsof -p $pid")))
{
echo "Seems gamectl process is gone but lock still exists, proceeding..\n";
break;
}
sleep(1);
}
register_shutdown_function('taskman\\gamectl_unlock');
putenv("GAMECTL_IN_LOCK=1");
file_put_contents($lock, getmypid());
}
function gamectl_unlock()
{
global $GAME_ROOT;
$lock = $GAME_ROOT . '/gamectl.lock';
if(file_exists($lock))
unlink($lock);
}