first commit
This commit is contained in:
commit
844b39628b
|
@ -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"]
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
Loading…
Reference in New Issue