diff --git a/kms.php b/kms.php index 8d11187..c9e266e 100755 --- a/kms.php +++ b/kms.php @@ -40,6 +40,10 @@ pcntl_signal(SIGINT, function() { // receive SIGINT signal subExit($nginx['pidFile'], $phpFpm['pidFile'], $vlmcsd['pidFile']); }); +if (in_array('--debug', $argv)) { // enter debug mode + logging::$logLevel = logging::DEBUG; +} + $KMS_PORT = 1688; // kms expose port -> only in message output if (sizeof(getopt('', ['port:'])) == 1) { // port option $KMS_PORT = getopt('', ['port:'])['port']; @@ -47,11 +51,10 @@ if (sizeof(getopt('', ['port:'])) == 1) { // port option $KMS_PORT = end($KMS_PORT); } } - - -if (in_array('--debug', $argv)) { // enter debug mode - logging::$logLevel = logging::DEBUG; -} +logging::debug('KMS Server Port -> ' . $KMS_PORT); +$php_env_file = fopen('/etc/nginx/kms_params', 'w'); +fwrite($php_env_file, 'fastcgi_param KMS_PORT "' . $KMS_PORT . '";' . PHP_EOL); +fclose($php_env_file); logging::info('Loading kms-server (' . $VERSION . ')'); new Process($nginx['command']); diff --git a/nginx/kms.conf b/nginx/kms.conf index 7558a2d..a6cb4a0 100644 --- a/nginx/kms.conf +++ b/nginx/kms.conf @@ -16,6 +16,7 @@ server { if ($http_user_agent ~* (curl|wget)) { set $query_param $query_param&cli=true; } + include kms_params; include fastcgi_params; fastcgi_pass 127.0.0.1:9000; fastcgi_param QUERY_STRING $query_param; diff --git a/src/Basis.php b/src/Basis.php index b01e58b..d590724 100644 --- a/src/Basis.php +++ b/src/Basis.php @@ -65,11 +65,10 @@ function getHost(): string { } function getPort(): int { - // TODO: check env - - echo 'KMS_PORT -> ' . getenv("KMS_PORT"); - - return 1688; + if (getenv("KMS_PORT") == null) { + return 1688; // default server port + } + return intval(getenv("KMS_PORT")); } function officeInfo(): array { // office dir and kms key for different version