1 package org.esigate.extension;
2
3 import java.io.File;
4 import java.util.Properties;
5
6 import org.esigate.Driver;
7 import org.esigate.DriverFactory;
8 import org.slf4j.Logger;
9 import org.slf4j.LoggerFactory;
10
11 import sun.misc.Signal;
12 import sun.misc.SignalHandler;
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 @SuppressWarnings("restriction")
28 public class ConfigReloadOnHup implements Extension {
29 private static final Logger LOG = LoggerFactory.getLogger(ConfigReloadOnHup.class);
30 private static final String SIGNAL_NAME = "HUP";
31
32 @Override
33 public void init(Driver driver, Properties properties) {
34
35 }
36
37 private static final SignalHandler SH = new SignalHandler() {
38 @Override
39 public void handle(Signal signal) {
40 if (SIGNAL_NAME.equals(signal.getName())) {
41 LOG.warn("Signal " + SIGNAL_NAME + " received. Reloading configuration.");
42 DriverFactory.configure();
43 }
44
45 }
46 };
47
48
49 static {
50 String envPath = System.getProperty("esigate.config");
51 if (envPath != null) {
52 File configuration = new File(envPath);
53
54
55 Signal signal = new Signal(SIGNAL_NAME);
56 Signal.handle(signal, SH);
57
58 LOG.info("Will reload configuration from {} on signal {}", configuration.getAbsoluteFile(),
59 signal.getNumber());
60 } else {
61
62 LOG.warn("Cannot reload configuration from classpath. Please use -Desigate.config");
63 }
64 }
65 }