diff --git a/openvidu-client/src/main/java/io/openvidu/client/OpenViduException.java b/openvidu-client/src/main/java/io/openvidu/client/OpenViduException.java index 91810aa9..f795bc30 100644 --- a/openvidu-client/src/main/java/io/openvidu/client/OpenViduException.java +++ b/openvidu-client/src/main/java/io/openvidu/client/OpenViduException.java @@ -23,7 +23,7 @@ public class OpenViduException extends JsonRpcErrorException { private static final long serialVersionUID = 1L; public static enum Code { - GENERIC_ERROR_CODE(999), + GENERIC_ERROR_CODE(999), WRONG_PATH_CODE(998), TRANSPORT_ERROR_CODE(803), TRANSPORT_RESPONSE_ERROR_CODE(802), TRANSPORT_REQUEST_ERROR_CODE(801), diff --git a/openvidu-server/src/main/java/io/openvidu/server/config/OpenviduConfig.java b/openvidu-server/src/main/java/io/openvidu/server/config/OpenviduConfig.java index d69739fa..47beba1b 100644 --- a/openvidu-server/src/main/java/io/openvidu/server/config/OpenviduConfig.java +++ b/openvidu-server/src/main/java/io/openvidu/server/config/OpenviduConfig.java @@ -17,10 +17,14 @@ package io.openvidu.server.config; +import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; +import java.nio.file.Files; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; +import java.util.Properties; import javax.annotation.PostConstruct; @@ -32,6 +36,8 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.info.BuildProperties; +import org.springframework.core.io.FileSystemResource; +import org.springframework.core.io.support.PropertiesLoaderUtils; import org.springframework.stereotype.Component; import com.google.gson.JsonArray; @@ -46,6 +52,9 @@ public class OpenviduConfig { private static final Logger log = LoggerFactory.getLogger(OpenviduConfig.class); + @Value("#{'${spring.config.additional-location:}'.length() > 0 ? '${spring.config.additional-location:}' : \"\"}") + private String springConfigLocation; + @Autowired BuildProperties buildProperties; @@ -134,9 +143,33 @@ public class OpenviduConfig { private List kmsUrisList; private List
webhookHeadersList; private List webhookEventsList; + private Properties externalizedProperties; @PostConstruct public void init() { + + if (!this.springConfigLocation.isEmpty()) { + // Properties file has been manually configured in certain path + FileSystemResource resource = new FileSystemResource(this.springConfigLocation); + try { + this.externalizedProperties = PropertiesLoaderUtils.loadProperties(resource); + log.info("Properties file found at \"{}\". Content: {}", this.springConfigLocation, + externalizedProperties); + } catch (IOException e) { + log.error("Error in 'spring.config.additional-location' system property: {}", e.getMessage()); + log.error("Shutting down OpenVidu Server"); + System.exit(1); + } + // Check OpenVidu Server write permissions in properties path + if (!Files.isWritable(Paths.get(this.springConfigLocation))) { + log.warn( + "The properties path '{}' set with property 'spring.config.additional-location' is not valid. Reason: OpenVidu Server needs write permissions. Try running command \"sudo chmod 777 {}\". If not, OpenVidu won't be able to overwrite preexisting properties on reboot", + this.springConfigLocation, this.springConfigLocation); + } else { + log.info("OpenVidu Server has write permissions on properties path: {}", this.springConfigLocation); + } + } + try { this.initiateKmsUris(); } catch (Exception e) { @@ -147,6 +180,12 @@ public class OpenviduConfig { if (this.isWebhookEnabled()) { log.info("OpenVidu Webhook service enabled"); try { + if (this.openviduWebhookEndpoint == null || this.openviduWebhookEndpoint.isEmpty()) { + log.error( + "If OpenVidu Webhook service is enabled property 'openvidu.webhook.endpoint' must be defined"); + log.error("Shutting down OpenVidu Server"); + System.exit(1); + } this.initiateOpenViduWebhookEndpoint(this.openviduWebhookEndpoint); } catch (Exception e) { log.error("Error in 'openvidu.webhook.endpoint' system property. " + e.getMessage()); @@ -332,6 +371,18 @@ public class OpenviduConfig { return this.buildProperties.getVersion(); } + public String getSpringConfigLocation() { + return this.springConfigLocation; + } + + public boolean hasExternalizedProperties() { + return !this.springConfigLocation.isEmpty(); + } + + public Properties getExternalizedProperties() { + return this.externalizedProperties; + } + private void initiateKmsUris() throws Exception { if (kmsUrisList == null) { this.kmsUris = this.kmsUris.replaceAll("\\s", ""); diff --git a/openvidu-server/src/main/java/io/openvidu/server/coturn/BashCoturnCredentialsService.java b/openvidu-server/src/main/java/io/openvidu/server/coturn/BashCoturnCredentialsService.java index 99b99eef..4314b4b2 100644 --- a/openvidu-server/src/main/java/io/openvidu/server/coturn/BashCoturnCredentialsService.java +++ b/openvidu-server/src/main/java/io/openvidu/server/coturn/BashCoturnCredentialsService.java @@ -40,10 +40,10 @@ public class BashCoturnCredentialsService extends CoturnCredentialsService { if (response.contains("turnadmin: not found")) { // No coturn installed in the host machine log.warn("No COTURN server is installed in the host machine. Response: " + response); - log.warn("No COTURN server will be automatically configured for clients"); + log.error("No COTURN server will be automatically configured for clients"); } else if (response.contains("Cannot initialize Redis DB connection")) { log.warn("Redis DB is not accesible with connection string " + this.coturnDatabaseString); - log.warn("No COTURN server will be automatically configured for clients"); + log.error("No COTURN server will be automatically configured for clients"); } else { log.info("COTURN Redis DB accessible with string " + this.coturnDatabaseString); log.info("Cleaning COTURN DB..."); diff --git a/openvidu-server/src/main/java/io/openvidu/server/utils/CustomFileManager.java b/openvidu-server/src/main/java/io/openvidu/server/utils/CustomFileManager.java index 2658fdb2..95706e47 100644 --- a/openvidu-server/src/main/java/io/openvidu/server/utils/CustomFileManager.java +++ b/openvidu-server/src/main/java/io/openvidu/server/utils/CustomFileManager.java @@ -18,9 +18,11 @@ package io.openvidu.server.utils; import java.io.File; +import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStreamWriter; +import java.util.Properties; import org.apache.commons.io.FileUtils; import org.slf4j.Logger; @@ -87,6 +89,18 @@ public class CustomFileManager { new File(path).delete(); } + public void overwriteProperties(Properties props, String filePath) throws FileNotFoundException, IOException { + FileOutputStream output = null; + try { + output = new FileOutputStream(filePath, false); + props.store(output, ""); + } finally { + if (output != null) { + output.close(); + } + } + } + private void writeAndCloseOnOutputStreamWriter(FileOutputStream fos, String text) throws IOException { OutputStreamWriter osw = null; try {