Browse Source

fix multi server launch

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