diff --git a/openvidu-server/src/main/java/io/openvidu/server/recording/service/RecordingManager.java b/openvidu-server/src/main/java/io/openvidu/server/recording/service/RecordingManager.java index 283b9a87..91d333e7 100644 --- a/openvidu-server/src/main/java/io/openvidu/server/recording/service/RecordingManager.java +++ b/openvidu-server/src/main/java/io/openvidu/server/recording/service/RecordingManager.java @@ -526,80 +526,83 @@ public class RecordingManager { private void initRecordingPath() throws OpenViduException { log.info("Initializing recording path"); + + final String recPath = this.openviduConfig.getOpenViduRecordingPath(); + final String testFolderPath = recPath + "/TEST_RECORDING_PATH_" + System.currentTimeMillis(); + final String testFilePath = testFolderPath + "/TEST_RECORDING_PATH.webm"; + + Path path = null; try { - final String recPath = this.openviduConfig.getOpenViduRecordingPath(); - final String testFolderPath = recPath + "/TEST_RECORDING_PATH_" + System.currentTimeMillis(); - final String testFilePath = testFolderPath + "/TEST_RECORDING_PATH.webm"; - Path path = Files.createDirectories(Paths.get(recPath)); - - // Check OpenVidu Server write permissions in recording path - if (!Files.isWritable(path)) { - String errorMessage = "The recording path \"" + recPath - + "\" is not valid. Reason: OpenVidu Server needs write permissions. Try running command \"sudo chmod 777 " - + recPath + "\""; - log.error(errorMessage); - throw new OpenViduException(Code.RECORDING_PATH_NOT_VALID, errorMessage); - } else { - log.info("OpenVidu Server has write permissions on recording path: {}", recPath); - } - - // Check Kurento Media Server write permissions in recording path - KurentoClientSessionInfo kcSessionInfo = new OpenViduKurentoClientSessionInfo("TEST_RECORDING_PATH", - "TEST_RECORDING_PATH"); - MediaPipeline pipeline = this.kcProvider.getKurentoClient(kcSessionInfo).createMediaPipeline(); - RecorderEndpoint recorder = new RecorderEndpoint.Builder(pipeline, "file://" + testFilePath).build(); - - recorder.addErrorListener(new EventListener() { - @Override - public void onEvent(ErrorEvent event) { - if (event.getErrorCode() == 6) { - // KMS write permissions error - log.error("The recording path \"" + recPath - + "\" is not valid. Reason: Kurento Media Server needs write permissions. Try running command \"sudo chmod 777 " - + recPath + "\""); - log.error( - "Error initializing recording path \"{}\" set with system property \"openvidu.recording.path\". Shutting down OpenVidu Server", - recPath); - System.exit(1); - } - } - }); - - recorder.record(); - - try { - Thread.sleep(250); - } catch (InterruptedException e1) { - e1.printStackTrace(); - } - - recorder.release(); - pipeline.release(); - - log.info("Kurento Media Server has write permissions on recording path: {}", recPath); - - try { - new CustomFileManager().deleteFolder(testFolderPath); - log.info("OpenVidu Server has write permissions over files created by Kurento Media Server"); - } catch (IOException e) { - String errorMessage = "The recording path \"" + recPath - + "\" is not valid. Reason: OpenVidu Server does not have write permissions over files created by Kurento Media Server. " - + "Try running Kurento Media Server as user \"" + System.getProperty("user.name") - + "\" or run OpenVidu Server as superuser"; - log.error(errorMessage); - log.error( - "Be aware that a folder \"{}\" was created and should be manually deleted (\"sudo rm -rf {}\")", - testFolderPath, testFolderPath); - throw new OpenViduException(Code.RECORDING_PATH_NOT_VALID, errorMessage); - } - - log.info("Recording path successfully initialized at {}", this.openviduConfig.getOpenViduRecordingPath()); - + path = Files.createDirectories(Paths.get(recPath)); } catch (IOException e) { - throw new OpenViduException(Code.RECORDING_PATH_NOT_VALID, - "The recording path '" + this.openviduConfig.getOpenViduRecordingPath() + "' is not valid. Reason: " - + e.getClass().getName()); + String errorMessage = "The recording path \"" + recPath + + "\" is not valid. Reason: OpenVidu Server cannot find path \"" + recPath + + "\" and doesn't have permissions to create it"; + log.error(errorMessage); + throw new OpenViduException(Code.RECORDING_PATH_NOT_VALID, errorMessage); } + + // Check OpenVidu Server write permissions in recording path + if (!Files.isWritable(path)) { + String errorMessage = "The recording path \"" + recPath + + "\" is not valid. Reason: OpenVidu Server needs write permissions. Try running command \"sudo chmod 777 " + + recPath + "\""; + log.error(errorMessage); + throw new OpenViduException(Code.RECORDING_PATH_NOT_VALID, errorMessage); + } else { + log.info("OpenVidu Server has write permissions on recording path: {}", recPath); + } + + // Check Kurento Media Server write permissions in recording path + KurentoClientSessionInfo kcSessionInfo = new OpenViduKurentoClientSessionInfo("TEST_RECORDING_PATH", + "TEST_RECORDING_PATH"); + MediaPipeline pipeline = this.kcProvider.getKurentoClient(kcSessionInfo).createMediaPipeline(); + RecorderEndpoint recorder = new RecorderEndpoint.Builder(pipeline, "file://" + testFilePath).build(); + + recorder.addErrorListener(new EventListener() { + @Override + public void onEvent(ErrorEvent event) { + if (event.getErrorCode() == 6) { + // KMS write permissions error + log.error("The recording path \"" + recPath + + "\" is not valid. Reason: Kurento Media Server needs write permissions. Try running command \"sudo chmod 777 " + + recPath + "\""); + log.error( + "Error initializing recording path \"{}\" set with system property \"openvidu.recording.path\". Shutting down OpenVidu Server", + recPath); + System.exit(1); + } + } + }); + + recorder.record(); + + try { + Thread.sleep(250); + } catch (InterruptedException e1) { + e1.printStackTrace(); + } + + recorder.release(); + pipeline.release(); + + log.info("Kurento Media Server has write permissions on recording path: {}", recPath); + + try { + new CustomFileManager().deleteFolder(testFolderPath); + log.info("OpenVidu Server has write permissions over files created by Kurento Media Server"); + } catch (IOException e) { + String errorMessage = "The recording path \"" + recPath + + "\" is not valid. Reason: OpenVidu Server does not have write permissions over files created by Kurento Media Server. " + + "Try running Kurento Media Server as user \"" + System.getProperty("user.name") + + "\" or run OpenVidu Server as superuser"; + log.error(errorMessage); + log.error("Be aware that a folder \"{}\" was created and should be manually deleted (\"sudo rm -rf {}\")", + testFolderPath, testFolderPath); + throw new OpenViduException(Code.RECORDING_PATH_NOT_VALID, errorMessage); + } + + log.info("Recording path successfully initialized at {}", this.openviduConfig.getOpenViduRecordingPath()); } public static String finalReason(String reason) {