Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
189 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
|
||
namespace App\Listener; | ||
|
||
use Swoft\Bean\Annotation\Listener; | ||
use Swoft\Event\EventHandlerInterface; | ||
use Swoft\Event\EventInterface; | ||
use Swoft\Task\Event\TaskEvent; | ||
use Swoft\Event\AppEvent; | ||
|
||
use App\Tars\Manage; | ||
use Swoft\Memory\Table; | ||
|
||
|
||
/** | ||
* Task finish handler | ||
* | ||
* @Listener(AppEvent::APPLICATION_LOADER) | ||
*/ | ||
class APPStart implements EventHandlerInterface | ||
{ | ||
public static $num = 0; | ||
/** | ||
* @param \Swoft\Event\EventInterface $event | ||
*/ | ||
public function handle(EventInterface $event) | ||
{ | ||
//服务启动 只上报一次 TODO | ||
|
||
$manage = new Manage(); | ||
$manage->keepAlive(); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
|
||
|
||
namespace App\Tars; | ||
|
||
use \Tars\report\ServerFSync; | ||
use \Tars\report\ServerFAsync; | ||
use \Tars\report\ServerInfo; | ||
use \Tars\Utils; | ||
|
||
/** | ||
* | ||
*/ | ||
class Manage | ||
{ | ||
|
||
public function getNodeInfo(){ | ||
$conf = $this->getTarsConf(); | ||
if( !empty($conf) ){ | ||
$node = $conf['tars']['application']['server']['node']; | ||
$nodeInfo = Utils::parseNodeInfo($node); | ||
return $nodeInfo; | ||
}else{ | ||
return []; | ||
} | ||
} | ||
|
||
public function getTarsConf(){ | ||
$tars_conf = dirname(BASE_PATH,2).'/conf/'.env('PNAME').'.config.conf'; | ||
|
||
if( is_file($tars_conf) ){ | ||
$conf = Utils::parseFile($tars_conf); | ||
return $conf; | ||
}else{ | ||
var_dump('get tars_conf file error : '.$tars_conf); | ||
return []; | ||
} | ||
} | ||
|
||
public function keepAlive() | ||
{ | ||
$pname = env('PNAME'); | ||
$pname = explode('.',$pname); | ||
|
||
$adapter = $pname.'.objAdapter'; | ||
$application = $pname[0]; | ||
$serverName = $pname[1]; | ||
$masterPid = getmypid(); | ||
|
||
$nodeInfo = $this->getNodeInfo(); | ||
if( empty($nodeInfo) ){ | ||
var_dump('keepAlive getNodeInfo fail'); | ||
return null; | ||
} | ||
$host = $nodeInfo['host']; | ||
$port = $nodeInfo['port']; | ||
$objName = $nodeInfo['objName']; | ||
|
||
$serverInfo = new ServerInfo(); | ||
$serverInfo->adapter = $adapter; | ||
$serverInfo->application = $application; | ||
$serverInfo->serverName = $serverName; | ||
$serverInfo->pid = $masterPid; | ||
|
||
$serverF = new ServerFSync($host, $port, $objName); | ||
$serverF->keepAlive($serverInfo); | ||
|
||
$adminServerInfo = new ServerInfo(); | ||
$adminServerInfo->adapter = 'AdminAdapter'; | ||
$adminServerInfo->application = $application; | ||
$adminServerInfo->serverName = $serverName; | ||
$adminServerInfo->pid = $masterPid; | ||
$serverF->keepAlive($adminServerInfo); | ||
|
||
var_dump(' keepalive '); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
namespace App\Tasks; | ||
use App\Lib\DemoInterface; | ||
use App\Models\Entity\User; | ||
use Swoft\App; | ||
use Swoft\Bean\Annotation\Inject; | ||
use Swoft\HttpClient\Client; | ||
use Swoft\Redis\Redis; | ||
use Swoft\Rpc\Client\Bean\Annotation\Reference; | ||
use Swoft\Task\Bean\Annotation\Scheduled; | ||
use Swoft\Task\Bean\Annotation\Task; | ||
|
||
use App\Tars\Manage; | ||
|
||
/** | ||
* TarsKeepAlive task | ||
* | ||
* @Task("tarsKeepAlive") | ||
*/ | ||
class TarsKeepAliveTask | ||
{ | ||
|
||
/** | ||
* | ||
* @Scheduled(cron="*\/30 * * * * *") | ||
*/ | ||
public function cronkeepAliveTask() | ||
{ | ||
|
||
$manage = new Manage(); | ||
$manage->keepAlive(); | ||
return 'cron'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
// tars 平台然后文件 | ||
|
||
//读取tars conf配置 | ||
|
||
//处理合成 env文件 | ||
|
||
$args = $_SERVER['argv']; | ||
|
||
|
||
$swoft_bin = dirname(__FILE__).'/bin/swoft '; | ||
$arg_cmd = $args[2]=='start' ? 'start -d' : $args[2] ; | ||
|
||
$cmd = "/data/env/runtime/php-7.1.7/bin/php " . $swoft_bin . $arg_cmd; | ||
|
||
exec($cmd, $output, $r); | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|