Browse Source

fix multi server launch

main
ghost 10 months ago
parent
commit
6e1211fc22
  1. 4
      README.md
  2. 110
      src/server.php

4
README.md

@ -38,8 +38,8 @@ KevaChat is distributed chat platform for open, uncensored and privacy respectab @@ -38,8 +38,8 @@ KevaChat is distributed chat platform for open, uncensored and privacy respectab
## Start
* `php src/server.php`
* `php src/server.php 127.0.0.1`
## See also
* [web implementation](https://github.com/kevachat/webapp)
* [KevaChat Web Application](https://github.com/kevachat/webapp)

110
src/server.php

@ -3,75 +3,72 @@ @@ -3,75 +3,72 @@
// Load dependencies
require_once __DIR__ . '/../vendor/autoload.php';
// Scan host
foreach ((array) scandir(__DIR__ . '/../host') as $host)
// Check arguments
if (empty($argv[1]))
{
// Skip meta
if ($host == '.' || $host == '..' || is_file($host))
{
continue;
}
// Check host configured
if (!file_exists(__DIR__ . '/../host/' . $host . '/config.json'))
{
echo sprintf(
_('Host "%s" not configured!') . PHP_EOL,
$host
);
continue;
}
exit(_('Configured hostname required as argument!') . PHP_EOL);
}
// Check cert exists
if (!file_exists(__DIR__ . '/../host/' . $host . '/cert.pem'))
{
echo sprintf(
// Check cert exists
if (!file_exists(__DIR__ . '/../host/' . $argv[1] . '/cert.pem'))
{
exit(
sprintf(
_('Certificate for host "%s" not found!') . PHP_EOL,
$host
$argv[1]
)
);
}
continue;
}
// Check key exists
if (!file_exists(__DIR__ . '/../host/' . $host . '/key.rsa'))
{
echo sprintf(
// Check key exists
if (!file_exists(__DIR__ . '/../host/' . $argv[1] . '/key.rsa'))
{
exit(
sprintf(
_('Key for host "%s" not found!') . PHP_EOL,
$host
$argv[1]
)
);
}
continue;
}
// Check host configured
if (!file_exists(__DIR__ . '/../host/' . $argv[1] . '/config.json'))
{
exit(
sprintf(
_('Host "%s" not configured!') . PHP_EOL,
$argv[1]
)
);
}
// Init config
$config = json_decode(
// Init config
$config = json_decode(
file_get_contents(
__DIR__ . '/../host/' . $host . '/config.json'
__DIR__ . '/../host/' . $argv[1] . '/config.json'
)
);
);
// Init memory
$memory = new \Yggverse\Cache\Memory(
// Init memory
$memory = new \Yggverse\Cache\Memory(
$config->memcached->server->host,
$config->memcached->server->port,
$config->memcached->server->namespace,
$config->memcached->server->timeout
);
);
// Init server
$server = new \Yggverse\TitanII\Server();
// Init server
$server = new \Yggverse\TitanII\Server();
$server->setCert(
__DIR__ . '/../host/' . $host . '/cert.pem'
);
$server->setCert(
__DIR__ . '/../host/' . $argv[1] . '/cert.pem'
);
$server->setKey(
__DIR__ . '/../host/' . $host . '/key.rsa'
);
$server->setKey(
__DIR__ . '/../host/' . $argv[1] . '/key.rsa'
);
$server->setHandler(
$server->setHandler(
function (\Yggverse\TitanII\Request $request): \Yggverse\TitanII\Response
{
global $memory;
@ -271,18 +268,17 @@ foreach ((array) scandir(__DIR__ . '/../host') as $host) @@ -271,18 +268,17 @@ foreach ((array) scandir(__DIR__ . '/../host') as $host)
return $response;
}
);
);
// Start server
echo sprintf(
// Start server
echo sprintf(
_('Server "%s" started on %s:%d') . PHP_EOL,
$host,
$argv[1],
$config->gemini->server->host,
$config->gemini->server->port
);
);
$server->start(
$server->start(
$config->gemini->server->host,
$config->gemini->server->port
);
}
);
Loading…
Cancel
Save