This commit is contained in:
2021-03-29 11:32:01 +08:00
parent b70f705450
commit fe6c754857
6 changed files with 565 additions and 572 deletions
+1 -1
View File
@@ -30,7 +30,7 @@ class OnManagerStart extends Callback
fire(Event::SERVER_MANAGER_START, [$server]); fire(Event::SERVER_MANAGER_START, [$server]);
name('Server Manager.'); name($server->manager_pid);
} }
-1
View File
@@ -20,7 +20,6 @@ class OnShutdown extends Callback
/** /**
* @param Server $server * @param Server $server
* @throws ComponentException
* @throws Exception * @throws Exception
*/ */
public function onHandler(Server $server) public function onHandler(Server $server)
+4 -4
View File
@@ -25,10 +25,10 @@ class OnStart extends Callback
public function onHandler(Server $server) public function onHandler(Server $server)
{ {
// Snowflake::setProcessId($server->master_pid); // Snowflake::setProcessId($server->master_pid);
// if (Snowflake::getPlatform()->isLinux()) { if (Snowflake::getPlatform()->isLinux()) {
// name(Config::get('id', false, 'system:') . ' master.'); name($server->master_pid);
// } }
// fire(Event::SERVER_EVENT_START, [$server]); fire(Event::SERVER_EVENT_START, [$server]);
} }
} }
+2 -16
View File
@@ -35,7 +35,8 @@ class OnWorkerStart extends Callback
putenv('state=start'); putenv('state=start');
putenv('worker=' . $worker_id); putenv('worker=' . $worker_id);
$this->set_process_name($server, $worker_id); name($server->worker_pid);
if ($worker_id >= $server->setting['worker_num']) { if ($worker_id >= $server->setting['worker_num']) {
$this->onTask($server, $worker_id); $this->onTask($server, $worker_id);
} else { } else {
@@ -78,19 +79,4 @@ class OnWorkerStart extends Callback
} }
/**
* @param $socket
* @param $worker_id
* @throws Exception
*/
private function set_process_name($socket, $worker_id): void
{
if ($worker_id >= $socket->setting['worker_num']) {
name('Task: No.' . $worker_id);
} else {
name('Worker: No.' . $worker_id);
}
}
} }
+11 -5
View File
@@ -24,11 +24,16 @@ class Shutdown extends Component
private string $processDirectory; private string $processDirectory;
private array $_pids = [];
/** /**
* @throws Exception * @throws Exception
*/ */
public function init() public function init()
{ {
exec('ps -eo pid', $this->_pids);
$this->taskDirectory = storage(null, 'pid/task'); $this->taskDirectory = storage(null, 'pid/task');
$this->workerDirectory = storage(null, 'pid/worker'); $this->workerDirectory = storage(null, 'pid/worker');
$this->managerDirectory = storage(null, 'pid/manager'); $this->managerDirectory = storage(null, 'pid/manager');
@@ -94,9 +99,11 @@ class Shutdown extends Component
if (intval($content) < 1) { if (intval($content) < 1) {
return false; return false;
} }
$shell = 'ps -eo pid,state | grep %d | grep \'%s\' | grep -v grep';
exec(sprintf($shell, intval($content), Config::get('id')), $output, $code); $id = Config::get('id', false, 'system');
var_dump(sprintf($shell, intval($content), Config::get('id')));
$shell = 'ps -eo pid,state | grep \'%s\' | grep -v grep';
exec(sprintf($shell, $id . '[' . intval($content) . ']'), $output, $code);
if (empty($output)) { if (empty($output)) {
return false; return false;
} }
@@ -131,10 +138,9 @@ class Shutdown extends Component
public function close(string $value) public function close(string $value)
{ {
$content = file_get_contents($value); $content = file_get_contents($value);
var_dump($value, $content);
while ($this->pidIsExists($content)) { while ($this->pidIsExists($content)) {
// exec('kill -15 ' . $content); exec('kill -15 ' . $content);
sleep(1); sleep(1);
} }
+547 -545
View File
File diff suppressed because it is too large Load Diff