mirror of https://github.com/OpenVidu/openvidu.git
openvidu-server: COTURN log files garbage collector
parent
e2b88fe265
commit
e4e7ba6c2d
|
@ -1,6 +1,7 @@
|
||||||
package io.openvidu.server.coturn;
|
package io.openvidu.server.coturn;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
|
||||||
import org.apache.commons.lang3.RandomStringUtils;
|
import org.apache.commons.lang3.RandomStringUtils;
|
||||||
|
|
||||||
|
@ -9,6 +10,10 @@ import io.openvidu.server.config.OpenviduConfig;
|
||||||
|
|
||||||
public class BashCoturnCredentialsService extends CoturnCredentialsService {
|
public class BashCoturnCredentialsService extends CoturnCredentialsService {
|
||||||
|
|
||||||
|
private String logPath;
|
||||||
|
private AtomicLong logCounter = new AtomicLong(0);
|
||||||
|
private final long LOG_LIMIT = 30;
|
||||||
|
|
||||||
public BashCoturnCredentialsService(OpenviduConfig openviduConfig) {
|
public BashCoturnCredentialsService(OpenviduConfig openviduConfig) {
|
||||||
super(openviduConfig);
|
super(openviduConfig);
|
||||||
try {
|
try {
|
||||||
|
@ -26,6 +31,12 @@ public class BashCoturnCredentialsService extends CoturnCredentialsService {
|
||||||
} else {
|
} else {
|
||||||
log.info("COTURN Redis DB accessible with string " + this.coturnDatabaseString);
|
log.info("COTURN Redis DB accessible with string " + this.coturnDatabaseString);
|
||||||
log.info("Cleaning COTURN DB...");
|
log.info("Cleaning COTURN DB...");
|
||||||
|
if (response.contains("log file opened")) {
|
||||||
|
String[] logArray = response.split("\\r?\\n")[0].split("\\s+");
|
||||||
|
String logFile = logArray[logArray.length - 1];
|
||||||
|
this.logPath = logFile.substring(0, logFile.lastIndexOf('/') + 1);
|
||||||
|
log.info("Path of COTURN log files: " + this.logPath);
|
||||||
|
}
|
||||||
response = CommandExecutor.execCommand("/bin/sh", "-c",
|
response = CommandExecutor.execCommand("/bin/sh", "-c",
|
||||||
"redis-cli -n " + this.openviduConfig.getCoturnDatabaseDbname() + " flushdb");
|
"redis-cli -n " + this.openviduConfig.getCoturnDatabaseDbname() + " flushdb");
|
||||||
String response2 = CommandExecutor.execCommand("/bin/sh", "-c",
|
String response2 = CommandExecutor.execCommand("/bin/sh", "-c",
|
||||||
|
@ -53,6 +64,7 @@ public class BashCoturnCredentialsService extends CoturnCredentialsService {
|
||||||
String response = CommandExecutor.execCommand("/bin/sh", "-c", command);
|
String response = CommandExecutor.execCommand("/bin/sh", "-c", command);
|
||||||
if (response.contains("connection success: " + this.trimmedCoturnDatabaseString)) {
|
if (response.contains("connection success: " + this.trimmedCoturnDatabaseString)) {
|
||||||
credentials = new TurnCredentials(user, pass);
|
credentials = new TurnCredentials(user, pass);
|
||||||
|
this.cleanTurnLogFiles();
|
||||||
log.info("COTURN user created: true");
|
log.info("COTURN user created: true");
|
||||||
} else {
|
} else {
|
||||||
log.info("COTURN user created: false");
|
log.info("COTURN user created: false");
|
||||||
|
@ -72,6 +84,7 @@ public class BashCoturnCredentialsService extends CoturnCredentialsService {
|
||||||
String response = "";
|
String response = "";
|
||||||
try {
|
try {
|
||||||
response = CommandExecutor.execCommand("/bin/sh", "-c", command);
|
response = CommandExecutor.execCommand("/bin/sh", "-c", command);
|
||||||
|
this.cleanTurnLogFiles();
|
||||||
} catch (IOException | InterruptedException e) {
|
} catch (IOException | InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -80,4 +93,12 @@ public class BashCoturnCredentialsService extends CoturnCredentialsService {
|
||||||
return userRemoved;
|
return userRemoved;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void cleanTurnLogFiles() throws IOException, InterruptedException {
|
||||||
|
if (this.logCounter.incrementAndGet() > LOG_LIMIT) {
|
||||||
|
CommandExecutor.execCommand("/bin/sh", "-c", "rm " + this.logPath + "turn_*.log");
|
||||||
|
log.info("Garbage collector cleaning turn log files at path " + this.logPath);
|
||||||
|
this.logCounter.set(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue