openvidu-server: checkDockerEnabled refactoring

pull/375/head
pabloFuente 2019-08-02 13:51:43 +02:00
parent bf76ff2bb5
commit bca34e150d
2 changed files with 22 additions and 18 deletions

View File

@ -168,7 +168,26 @@ public class RecordingManager {
if (dockerManager == null) { if (dockerManager == null) {
this.dockerManager = new DockerManager(); this.dockerManager = new DockerManager();
} }
dockerManager.checkDockerEnabled(openviduConfig.getSpringProfile()); try {
dockerManager.checkDockerEnabled();
} catch (OpenViduException e) {
String message = e.getMessage();
if ("docker".equals(openviduConfig.getSpringProfile())) {
final String NEW_LINE = System.getProperty("line.separator");
message += ": make sure you include the following flags in your \"docker run\" command:" + NEW_LINE
+ " -e openvidu.recording.path=/YOUR/PATH/TO/VIDEO/FILES" + NEW_LINE
+ " -e MY_UID=$(id -u $USER)" + NEW_LINE + " -v /var/run/docker.sock:/var/run/docker.sock"
+ NEW_LINE + " -v /YOUR/PATH/TO/VIDEO/FILES:/YOUR/PATH/TO/VIDEO/FILES" + NEW_LINE;
} else {
message += ": you need Docker CE installed in this machine to enable OpenVidu recording service. "
+ "If Docker CE is already installed, make sure to add OpenVidu Server user to "
+ "\"docker\" group: " + System.lineSeparator() + " 1) $ sudo usermod -aG docker $USER"
+ System.lineSeparator()
+ " 2) Log out and log back to the host to reevaluate group membership";
}
log.error(message);
throw e;
}
this.checkRecordingPaths(openviduRecordingPath, openviduRecordingCustomLayout); this.checkRecordingPaths(openviduRecordingPath, openviduRecordingCustomLayout);
} }

View File

@ -97,27 +97,12 @@ public class DockerManager {
return imageExists; return imageExists;
} }
public void checkDockerEnabled(String springProfile) throws OpenViduException { public void checkDockerEnabled() throws OpenViduException {
try { try {
this.dockerImageExistsLocally("hello-world"); this.dockerImageExistsLocally("hello-world");
log.info("Docker is installed and enabled"); log.info("Docker is installed and enabled");
} catch (ProcessingException exception) { } catch (ProcessingException exception) {
String message = "Exception connecting to Docker daemon: "; throw new OpenViduException(Code.DOCKER_NOT_FOUND, "Exception connecting to Docker daemon");
if ("docker".equals(springProfile)) {
final String NEW_LINE = System.getProperty("line.separator");
message += "make sure you include the following flags in your \"docker run\" command:" + NEW_LINE
+ " -e openvidu.recording.path=/YOUR/PATH/TO/VIDEO/FILES" + NEW_LINE
+ " -e MY_UID=$(id -u $USER)" + NEW_LINE + " -v /var/run/docker.sock:/var/run/docker.sock"
+ NEW_LINE + " -v /YOUR/PATH/TO/VIDEO/FILES:/YOUR/PATH/TO/VIDEO/FILES" + NEW_LINE;
} else {
message += "you need Docker CE installed in this machine to enable OpenVidu recording service. "
+ "If Docker CE is already installed, make sure to add OpenVidu Server user to "
+ "\"docker\" group: " + System.lineSeparator() + " 1) $ sudo usermod -aG docker $USER"
+ System.lineSeparator()
+ " 2) Log out and log back to the host to reevaluate group membership";
}
log.error(message);
throw new OpenViduException(Code.DOCKER_NOT_FOUND, message);
} }
} }