Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.tron.core.db.Manager;
import org.tron.core.metrics.MetricsUtil;
import org.tron.core.net.TronNetService;
import org.tron.program.FullNode;

@Slf4j(topic = "app")
@Component
Expand Down Expand Up @@ -73,6 +74,7 @@ public void shutdown() {
dbManager.stopRePushTriggerThread();
EventPluginLoader.getInstance().stopPlugin();
logger.info("******** end to shutdown ********");
FullNode.shutDownSign = true;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package org.tron.core.config;

import ch.qos.logback.core.hook.ShutdownHookBase;
import ch.qos.logback.core.util.Duration;
import org.tron.program.FullNode;

/**
* @author kiven
* tron log shutdown hock
*/
public class TronLogShutdownHook extends ShutdownHookBase {

/**
* The default shutdown delay check unit.
*/
private static final Duration CHECK_SHUTDOWN_DELAY = Duration.buildByMilliseconds(100);

/**
* The check times before shutdown. default is 50
*/
private Integer check_times = 50;

public TronLogShutdownHook() {
}

@Override
public void run() {
try {
for (int i = 0; i < check_times; i++) {
if (FullNode.shutDownSign) {
break;
}
addInfo("Sleeping for " + CHECK_SHUTDOWN_DELAY);
Thread.sleep(CHECK_SHUTDOWN_DELAY.getMilliseconds());
}
} catch (InterruptedException e) {
addInfo("TronLogShutdownHook run error :" + e.getMessage());
}
super.stop();
}

}
2 changes: 2 additions & 0 deletions framework/src/main/java/org/tron/program/FullNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public class FullNode {

public static final int dbVersion = 2;

public static volatile boolean shutDownSign = false;

public static void load(String path) {
try {
File file = new File(path);
Expand Down
2 changes: 1 addition & 1 deletion framework/src/main/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<configuration>

<!-- Be sure to flush latest logs on exit -->
<shutdownHook class="ch.qos.logback.core.hook.DelayingShutdownHook"/>
<shutdownHook class="org.tron.core.config.TronLogShutdownHook"/>

<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
Expand Down