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]);
name('Server Manager.');
name($server->manager_pid);
}
-1
View File
@@ -20,7 +20,6 @@ class OnShutdown extends Callback
/**
* @param Server $server
* @throws ComponentException
* @throws Exception
*/
public function onHandler(Server $server)
+4 -4
View File
@@ -25,10 +25,10 @@ class OnStart extends Callback
public function onHandler(Server $server)
{
// Snowflake::setProcessId($server->master_pid);
// if (Snowflake::getPlatform()->isLinux()) {
// name(Config::get('id', false, 'system:') . ' master.');
// }
// fire(Event::SERVER_EVENT_START, [$server]);
if (Snowflake::getPlatform()->isLinux()) {
name($server->master_pid);
}
fire(Event::SERVER_EVENT_START, [$server]);
}
}
+2 -16
View File
@@ -35,7 +35,8 @@ class OnWorkerStart extends Callback
putenv('state=start');
putenv('worker=' . $worker_id);
$this->set_process_name($server, $worker_id);
name($server->worker_pid);
if ($worker_id >= $server->setting['worker_num']) {
$this->onTask($server, $worker_id);
} 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 array $_pids = [];
/**
* @throws Exception
*/
public function init()
{
exec('ps -eo pid', $this->_pids);
$this->taskDirectory = storage(null, 'pid/task');
$this->workerDirectory = storage(null, 'pid/worker');
$this->managerDirectory = storage(null, 'pid/manager');
@@ -94,9 +99,11 @@ class Shutdown extends Component
if (intval($content) < 1) {
return false;
}
$shell = 'ps -eo pid,state | grep %d | grep \'%s\' | grep -v grep';
exec(sprintf($shell, intval($content), Config::get('id')), $output, $code);
var_dump(sprintf($shell, intval($content), Config::get('id')));
$id = Config::get('id', false, 'system');
$shell = 'ps -eo pid,state | grep \'%s\' | grep -v grep';
exec(sprintf($shell, $id . '[' . intval($content) . ']'), $output, $code);
if (empty($output)) {
return false;
}
@@ -131,10 +138,9 @@ class Shutdown extends Component
public function close(string $value)
{
$content = file_get_contents($value);
var_dump($value, $content);
while ($this->pidIsExists($content)) {
// exec('kill -15 ' . $content);
exec('kill -15 ' . $content);
sleep(1);
}