mirror of https://github.com/OpenVidu/openvidu.git
openvidu-server: recording path initialization extended
parent
a3993ac3cf
commit
334a1d6b70
|
@ -526,80 +526,83 @@ public class RecordingManager {
|
||||||
|
|
||||||
private void initRecordingPath() throws OpenViduException {
|
private void initRecordingPath() throws OpenViduException {
|
||||||
log.info("Initializing recording path");
|
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 {
|
try {
|
||||||
final String recPath = this.openviduConfig.getOpenViduRecordingPath();
|
path = Files.createDirectories(Paths.get(recPath));
|
||||||
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<ErrorEvent>() {
|
|
||||||
@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());
|
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new OpenViduException(Code.RECORDING_PATH_NOT_VALID,
|
String errorMessage = "The recording path \"" + recPath
|
||||||
"The recording path '" + this.openviduConfig.getOpenViduRecordingPath() + "' is not valid. Reason: "
|
+ "\" is not valid. Reason: OpenVidu Server cannot find path \"" + recPath
|
||||||
+ e.getClass().getName());
|
+ "\" 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<ErrorEvent>() {
|
||||||
|
@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) {
|
public static String finalReason(String reason) {
|
||||||
|
|
Loading…
Reference in New Issue