Small update for more stability

This commit is contained in:
Collin 2024-03-05 15:02:45 +00:00
parent 6cb356d3ef
commit 5463e173a5
5 changed files with 48 additions and 57 deletions

View File

@ -1 +1 @@
cd build/release ; printf "test\n" | php -dextension=openswoole.so -dphar.readonly=0 LonaDB-4.3.0-stable.phar cd build/release ; printf "test\n" | php -dextension=openswoole.so -dphar.readonly=0 LonaDB-4.3.1-stable.phar

View File

@ -1,6 +1,6 @@
{ {
"filename": "LonaDB", "filename": "LonaDB",
"version": "4.3.0-stable", "version": "4.3.1-stable",
"path": "build", "path": "build",
"debug": false "debug": false
} }

View File

@ -14,7 +14,7 @@ use LonaDB\Plugins\PluginManager;
class LonaDB { class LonaDB {
public array $config; public array $config;
private bool $Running = true; public bool $Running = false;
public string $EncryptionKey; public string $EncryptionKey;
public Logger $Logger; public Logger $Logger;
@ -27,6 +27,7 @@ class LonaDB {
public function __construct(string $key) { public function __construct(string $key) {
$this->EncryptionKey = $key; $this->EncryptionKey = $key;
$this->Logger = new Logger($this); $this->Logger = new Logger($this);
$run = false;
try{ try{
echo chr(27).chr(91).'H'.chr(27).chr(91).'J'; echo chr(27).chr(91).'H'.chr(27).chr(91).'J';
@ -42,60 +43,36 @@ class LonaDB {
$decrypted = openssl_decrypt($parts[0], AES_256_CBC, $this->EncryptionKey, 0, base64_decode($parts[1])); $decrypted = openssl_decrypt($parts[0], AES_256_CBC, $this->EncryptionKey, 0, base64_decode($parts[1]));
if(!json_decode($decrypted, true)) { if(!json_decode($decrypted, true)) {
echo "Encryption Key does not match the existing Configuration file. Exiting.\n"; echo "Encryption Key does not match the existing Configuration file. Exiting.\n";
exit; }else $run = true;
}
if($run){
$this->Logger->InfoCache("Loading config.");
$parts = explode(':', file_get_contents("./configuration.lona"));
$decrypted = openssl_decrypt($parts[0], AES_256_CBC, $this->EncryptionKey, 0, base64_decode($parts[1]));
$this->config = json_decode($decrypted, true);
$this->Logger->InfoCache("Checking config.");
if(!$this->config["port"] || !$this->config["address"] || !$this->config["encryptionKey"] || !$this->config["root"]) {
$this->setup();
} }
}
$this->Logger->InfoCache("Loading config."); $this->Logger->LoadLogger();
$parts = explode(':', file_get_contents("./configuration.lona")); $this->Logger->DropCache();
$decrypted = openssl_decrypt($parts[0], AES_256_CBC, $this->EncryptionKey, 0, base64_decode($parts[1]));
$this->config = json_decode($decrypted, true);
$this->Logger->InfoCache("Checking config."); $this->Logger->Info("Loading TableManager class.");
if(!$this->config["port"] || !$this->config["address"] || !$this->config["encryptionKey"] || !$this->config["root"]) { $this->TableManager = new TableManager($this);
$this->setup(); $this->Logger->Info("Loading UserManager class.");
} $this->UserManager = new UserManager($this);
$this->Logger->Info("Loading FunctionManager class.");
$this->Logger->LoadLogger(); $this->FunctionManager = new FunctionManager($this);
$this->Logger->DropCache(); $this->Logger->Info("Loading PluginManager class.");
$this->PluginManager = new PluginManager($this);
$this->Logger->Info("Loading TableManager class.");
$this->TableManager = new TableManager($this);
$this->Logger->Info("Loading UserManager class.");
$this->UserManager = new UserManager($this);
$this->Logger->Info("Loading FunctionManager class.");
$this->FunctionManager = new FunctionManager($this);
$this->Logger->Info("Loading PluginManager class.");
$this->PluginManager = new PluginManager($this);
$pid = @ pcntl_fork();
if( $pid == -1 ) {
throw new Exception( $this->getError( Thread::COULD_NOT_FORK ), Thread::COULD_NOT_FORK );
}
if( $pid ) {
// parent
$this->pid = $pid;
}
else {
$this->PluginManager->LoadPlugins();
}
$serverpid = @ pcntl_fork();
if( $serverpid == -1 ) {
throw new Exception( $this->getError( Thread::COULD_NOT_FORK ), Thread::COULD_NOT_FORK );
}
if( $serverpid ) {
// parent
$this->serverpid = $serverpid;
}
else {
$this->Logger->Info("Loading Server class.");
$this->Server = new Server($this);
}
while($this->Running){
if(!$this->Running){
$this->Logger->Info("Loading Server class.");
$this->Server = new Server($this);
}
} }
} }
catch (\Exception $e){ catch (\Exception $e){
@ -103,15 +80,19 @@ class LonaDB {
} }
} }
private function Load() : void { public function LoadPlugins() : void {
if($this->PluginManager->Loaded) return;
$pid = @ pcntl_fork(); $pid = @ pcntl_fork();
if( $pid == -1 ) { if( $pid == -1 ) {
throw new Exception( $this->getError( Thread::COULD_NOT_FORK ), Thread::COULD_NOT_FORK ); throw new Exception( $this->getError( Thread::COULD_NOT_FORK ), Thread::COULD_NOT_FORK );
} }
if( $pid ) { if( $pid ) {
// parent
$this->pid = $pid; $this->pid = $pid;
} }
else { else {
$this->PluginManager->LoadPlugins();
} }
} }
@ -160,9 +141,12 @@ class LonaDB {
} }
public function Stop() : void { public function Stop() : void {
echo chr(27).chr(91).'H'.chr(27).chr(91).'J';
echo "[Shutdown]\n";
echo "Killing threads...\n";
posix_kill( $this->pid, SIGKILL ); posix_kill( $this->pid, SIGKILL );
posix_kill( $this->serverpid, SIGKILL ); $this->Server->Stop();
$this->Running = false; echo "Done!\n";
} }
} }

View File

@ -9,6 +9,7 @@ class PluginManager{
private LonaDB $LonaDB; private LonaDB $LonaDB;
private array $Plugins; private array $Plugins;
private array $EnabledPlugins; private array $EnabledPlugins;
public bool $Loaded = false;
public function __construct(LonaDB $lonaDB) { public function __construct(LonaDB $lonaDB) {
$this->LonaDB = $lonaDB; $this->LonaDB = $lonaDB;
@ -16,6 +17,7 @@ class PluginManager{
} }
public function LoadPlugins () : void { public function LoadPlugins () : void {
$this->Loaded = true;
if(!is_dir("plugins/")) mkdir("plugins/"); if(!is_dir("plugins/")) mkdir("plugins/");
$results = scandir("plugins/"); $results = scandir("plugins/");

View File

@ -18,6 +18,10 @@ class Server {
public function __construct(LonaDB $lonaDB) { public function __construct(LonaDB $lonaDB) {
$this->LonaDB = $lonaDB; $this->LonaDB = $lonaDB;
if($this->LonaDB->Running) return;
$this->LonaDB->Running = true;
$this->config = $lonaDB->config; $this->config = $lonaDB->config;
$this->address = $this->config["address"]; $this->address = $this->config["address"];
@ -51,6 +55,7 @@ class Server {
}); });
try{ try{
$this->LonaDB->LoadPlugins();
$this->server->start(); $this->server->start();
} }
catch(e){ catch(e){