remove monitors;

add command for restart/close server
This commit is contained in:
Yu Sun
2022-08-16 00:41:31 +08:00
parent 6f28d923d2
commit 0ed5eddd9a
5 changed files with 81 additions and 86 deletions

View File

@@ -7,8 +7,7 @@ use Workerman\Protocols\Http\Response;
require_once __DIR__ . '/vendor/autoload.php';
use EdgeManager\EDataCapture\{ EDataCapture, ENodeConfigure };
use EdgeManager\EController\EConfigure;
use EdgeManager\EMonitor\EStatusCapture;
use EdgeManager\EController\{ EConfigure, ECommand };
$options = getopt('h::', ['no_dup_code', 'server_name:', 'port::', 'user:', 'password:', 'help::']);
@@ -191,6 +190,19 @@ $worker -> onMessage = function(TcpConnection $connection, Request $request) {
'errmsg' => 'ROLLBACKed: Bad data received (structure and/or values)'
)));
}
} else if ($post -> action === 'exec') {
$task_connection = new AsyncTcpConnection('Text://127.0.0.1:1888');
$task_data = array(
'action' => 'exec',
'data' => $post,
);
$task_connection -> send(json_encode($task_data));
$task_connection -> onMessage = function(AsyncTcpConnection $task_connection, $task_result) use ($connection) {
$task_connection -> close();
$connection -> send($task_result);
};
// 执行异步连接
$task_connection->connect();
} else {
// 有action但是不知道是什么鬼动作
$response = new Response(200, [
@@ -311,20 +323,6 @@ $worker -> onMessage = function(TcpConnection $connection, Request $request) {
'code' => 0,
'data' => $devices
)));
} else if ($get['query'] === 'device_status') {
$e_status_capture = new EStatusCapture($dbconn, get: $get);
$device_status = $e_status_capture -> get_device_status();
$connection -> send(json_encode(array(
'code' => 0,
'data' => $device_status
)));
} else if ($get['query'] === 'all_status') {
$all_status = EStatusCapture::get_all_status($dbconn);
$connection -> send(json_encode(array(
'code' => 0,
'data' => $all_status
)));
} else {
$connection -> send(json_encode(array(
'code' => 1,
@@ -391,6 +389,14 @@ $consumer -> onMessage = function(TcpConnection $connection, $task_data) {
'msg' => '服务器内部逻辑错误,请联系开发者!'
)));
}
} else if ($task_data -> action === 'exec') {
$e_command = new ECommand($consumer_dbconn, $task_data -> data);
$e_command -> exec();
$connection -> send(json_encode(array(
'code' => 0,
'msg' => 'Success'
)));
}
};