mirror of https://github.com/OpenVidu/openvidu.git
openvidu-server: composed quickstart recording stop bug fix
parent
593b2fa80d
commit
b9d28d11cd
|
@ -78,7 +78,7 @@ public class ComposedQuickStartRecordingService extends ComposedRecordingService
|
||||||
recordExecCommand += "export " + envs.get(i) + " ";
|
recordExecCommand += "export " + envs.get(i) + " ";
|
||||||
}
|
}
|
||||||
recordExecCommand += "&& ./composed_quick_start.sh --start-recording > /var/log/ffmpeg.log 2>&1 &";
|
recordExecCommand += "&& ./composed_quick_start.sh --start-recording > /var/log/ffmpeg.log 2>&1 &";
|
||||||
dockerManager.runCommandInContainer(containerId, recordExecCommand, 0);
|
dockerManager.runCommandInContainer(containerId, recordExecCommand);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
this.cleanRecordingMaps(recording);
|
this.cleanRecordingMaps(recording);
|
||||||
throw this.failStartRecording(session, recording,
|
throw this.failStartRecording(session, recording,
|
||||||
|
@ -116,7 +116,7 @@ public class ComposedQuickStartRecordingService extends ComposedRecordingService
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
dockerManager.runCommandInContainer(containerId, "./composed_quick_start.sh --stop-recording", 10);
|
dockerManager.runCommandInContainerSync(containerId, "./composed_quick_start.sh --stop-recording", 10);
|
||||||
} catch (InterruptedException e1) {
|
} catch (InterruptedException e1) {
|
||||||
cleanRecordingMaps(recording);
|
cleanRecordingMaps(recording);
|
||||||
log.error("Error stopping recording for session id: {}", session.getSessionId());
|
log.error("Error stopping recording for session id: {}", session.getSessionId());
|
||||||
|
|
|
@ -396,7 +396,7 @@ public class ComposedRecordingService extends RecordingService {
|
||||||
protected void stopAndRemoveRecordingContainer(Recording recording, String containerId, int secondsOfWait) {
|
protected void stopAndRemoveRecordingContainer(Recording recording, String containerId, int secondsOfWait) {
|
||||||
// Gracefully stop ffmpeg process
|
// Gracefully stop ffmpeg process
|
||||||
try {
|
try {
|
||||||
dockerManager.runCommandInContainer(containerId, "echo 'q' > stop", 0);
|
dockerManager.runCommandInContainer(containerId, "echo 'q' > stop");
|
||||||
} catch (InterruptedException e1) {
|
} catch (InterruptedException e1) {
|
||||||
e1.printStackTrace();
|
e1.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,23 +26,29 @@ import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import javax.ws.rs.ProcessingException;
|
import javax.ws.rs.ProcessingException;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import com.github.dockerjava.api.DockerClient;
|
import com.github.dockerjava.api.DockerClient;
|
||||||
import com.github.dockerjava.api.async.ResultCallback;
|
import com.github.dockerjava.api.command.CreateContainerCmd;
|
||||||
import com.github.dockerjava.api.command.*;
|
import com.github.dockerjava.api.command.CreateContainerResponse;
|
||||||
|
import com.github.dockerjava.api.command.ExecCreateCmdResponse;
|
||||||
|
import com.github.dockerjava.api.command.InspectContainerResponse;
|
||||||
|
import com.github.dockerjava.api.command.InspectImageResponse;
|
||||||
import com.github.dockerjava.api.exception.ConflictException;
|
import com.github.dockerjava.api.exception.ConflictException;
|
||||||
import com.github.dockerjava.api.exception.DockerClientException;
|
import com.github.dockerjava.api.exception.DockerClientException;
|
||||||
import com.github.dockerjava.api.exception.InternalServerErrorException;
|
import com.github.dockerjava.api.exception.InternalServerErrorException;
|
||||||
import com.github.dockerjava.api.exception.NotFoundException;
|
import com.github.dockerjava.api.exception.NotFoundException;
|
||||||
import com.github.dockerjava.api.model.*;
|
import com.github.dockerjava.api.model.Bind;
|
||||||
|
import com.github.dockerjava.api.model.Container;
|
||||||
|
import com.github.dockerjava.api.model.HostConfig;
|
||||||
|
import com.github.dockerjava.api.model.Volume;
|
||||||
import com.github.dockerjava.core.DefaultDockerClientConfig;
|
import com.github.dockerjava.core.DefaultDockerClientConfig;
|
||||||
import com.github.dockerjava.core.DockerClientBuilder;
|
import com.github.dockerjava.core.DockerClientBuilder;
|
||||||
import com.github.dockerjava.core.DockerClientConfig;
|
import com.github.dockerjava.core.DockerClientConfig;
|
||||||
import com.github.dockerjava.core.command.ExecStartResultCallback;
|
import com.github.dockerjava.core.command.ExecStartResultCallback;
|
||||||
import com.github.dockerjava.core.command.PullImageResultCallback;
|
import com.github.dockerjava.core.command.PullImageResultCallback;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import io.openvidu.client.OpenViduException;
|
import io.openvidu.client.OpenViduException;
|
||||||
import io.openvidu.client.OpenViduException.Code;
|
import io.openvidu.client.OpenViduException.Code;
|
||||||
import io.openvidu.server.recording.service.WaitForContainerStoppedCallback;
|
import io.openvidu.server.recording.service.WaitForContainerStoppedCallback;
|
||||||
|
@ -102,9 +108,8 @@ public class DockerManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String runContainer(String container, String containerName, String user, List<Volume> volumes,
|
public String runContainer(String container, String containerName, String user, List<Volume> volumes,
|
||||||
List<Bind> binds, String networkMode, List<String> envs, List<String> command, Long shmSize, boolean privileged,
|
List<Bind> binds, String networkMode, List<String> envs, List<String> command, Long shmSize,
|
||||||
Map<String, String> labels)
|
boolean privileged, Map<String, String> labels) throws Exception {
|
||||||
throws Exception {
|
|
||||||
|
|
||||||
CreateContainerCmd cmd = dockerClient.createContainerCmd(container).withEnv(envs);
|
CreateContainerCmd cmd = dockerClient.createContainerCmd(container).withEnv(envs);
|
||||||
if (containerName != null) {
|
if (containerName != null) {
|
||||||
|
@ -167,21 +172,30 @@ public class DockerManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String runCommandInContainer(String containerId, String command, int secondsOfWait)
|
public void runCommandInContainer(String containerId, String command) throws InterruptedException {
|
||||||
|
ExecCreateCmdResponse execCreateCmdResponse = dockerClient.execCreateCmd(containerId).withAttachStdout(true)
|
||||||
|
.withAttachStderr(true).withCmd("bash", "-c", command).exec();
|
||||||
|
dockerClient.execStartCmd(execCreateCmdResponse.getId()).exec(new ExecStartResultCallback() {
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void runCommandInContainerSync(String containerId, String command, int secondsOfWait)
|
||||||
throws InterruptedException {
|
throws InterruptedException {
|
||||||
ExecCreateCmdResponse execCreateCmdResponse = dockerClient.execCreateCmd(containerId).withAttachStdout(true)
|
ExecCreateCmdResponse execCreateCmdResponse = dockerClient.execCreateCmd(containerId).withAttachStdout(true)
|
||||||
.withAttachStderr(true).withCmd("bash", "-c", command).exec();
|
.withAttachStderr(true).withCmd("bash", "-c", command).exec();
|
||||||
CountDownLatch latch = new CountDownLatch(1);
|
CountDownLatch latch = new CountDownLatch(1);
|
||||||
final String[] stringResponse = new String[1];
|
|
||||||
dockerClient.execStartCmd(execCreateCmdResponse.getId()).exec(new ExecStartResultCallback() {
|
dockerClient.execStartCmd(execCreateCmdResponse.getId()).exec(new ExecStartResultCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void onNext(Frame item) {
|
public void onComplete() {
|
||||||
stringResponse[0] = new String(item.getPayload());
|
|
||||||
latch.countDown();
|
latch.countDown();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
try {
|
||||||
latch.await(secondsOfWait, TimeUnit.SECONDS);
|
latch.await(secondsOfWait, TimeUnit.SECONDS);
|
||||||
return stringResponse[0];
|
} catch (InterruptedException e) {
|
||||||
|
throw new InterruptedException("Container " + containerId + " did not return from executing command \""
|
||||||
|
+ command + "\" in " + secondsOfWait + " seconds");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void waitForContainerStopped(String containerId, int secondsOfWait) throws Exception {
|
public void waitForContainerStopped(String containerId, int secondsOfWait) throws Exception {
|
||||||
|
|
Loading…
Reference in New Issue