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;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
|
||||
|
@ -9,6 +10,10 @@ import io.openvidu.server.config.OpenviduConfig;
|
|||
|
||||
public class BashCoturnCredentialsService extends CoturnCredentialsService {
|
||||
|
||||
private String logPath;
|
||||
private AtomicLong logCounter = new AtomicLong(0);
|
||||
private final long LOG_LIMIT = 30;
|
||||
|
||||
public BashCoturnCredentialsService(OpenviduConfig openviduConfig) {
|
||||
super(openviduConfig);
|
||||
try {
|
||||
|
@ -26,6 +31,12 @@ public class BashCoturnCredentialsService extends CoturnCredentialsService {
|
|||
} else {
|
||||
log.info("COTURN Redis DB accessible with string " + this.coturnDatabaseString);
|
||||
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",
|
||||
"redis-cli -n " + this.openviduConfig.getCoturnDatabaseDbname() + " flushdb");
|
||||
String response2 = CommandExecutor.execCommand("/bin/sh", "-c",
|
||||
|
@ -53,6 +64,7 @@ public class BashCoturnCredentialsService extends CoturnCredentialsService {
|
|||
String response = CommandExecutor.execCommand("/bin/sh", "-c", command);
|
||||
if (response.contains("connection success: " + this.trimmedCoturnDatabaseString)) {
|
||||
credentials = new TurnCredentials(user, pass);
|
||||
this.cleanTurnLogFiles();
|
||||
log.info("COTURN user created: true");
|
||||
} else {
|
||||
log.info("COTURN user created: false");
|
||||
|
@ -72,6 +84,7 @@ public class BashCoturnCredentialsService extends CoturnCredentialsService {
|
|||
String response = "";
|
||||
try {
|
||||
response = CommandExecutor.execCommand("/bin/sh", "-c", command);
|
||||
this.cleanTurnLogFiles();
|
||||
} catch (IOException | InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -80,4 +93,12 @@ public class BashCoturnCredentialsService extends CoturnCredentialsService {
|
|||
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