Skip to content

Commit 541a45f

Browse files
tulinkryVladimir Kotal
authored andcommitted
start/stop the watchdog service if the configuration change is made on the fly (#1649)
fixes #1614
1 parent ca9a887 commit 541a45f

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

src/org/opensolaris/opengrok/configuration/RuntimeEnvironment.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,6 +1640,14 @@ public void applyConfig(Configuration config, boolean reindex) {
16401640
config.refreshDateForLastIndexRun();
16411641
}
16421642

1643+
// start/stop the watchdog if necessarry
1644+
if (isAuthorizationWatchdog() && config.getPluginDirectory() != null) {
1645+
startWatchDogService(new File(config.getPluginDirectory()));
1646+
} else {
1647+
stopWatchDogService();
1648+
}
1649+
1650+
// set the new plugin directory and reload the authorization framework
16431651
getAuthorizationFramework().setPluginDirectory(config.getPluginDirectory());
16441652
getAuthorizationFramework().reload();
16451653
}
@@ -1766,10 +1774,12 @@ protected void handleMessage(Message m, final OutputStream output) throws IOExce
17661774
* @param directory root directory for plugins
17671775
*/
17681776
public void startWatchDogService(File directory) {
1777+
stopWatchDogService();
17691778
if (directory == null || !directory.isDirectory() || !directory.canRead()) {
17701779
LOGGER.log(Level.INFO, "Watch dog cannot be started - invalid directory: {0}", directory);
17711780
return;
17721781
}
1782+
LOGGER.log(Level.INFO, "Starting watchdog in: {0}", directory);
17731783
watchDogThread = new Thread(new Runnable() {
17741784
@Override
17751785
public void run() {
@@ -1781,11 +1791,12 @@ public void run() {
17811791
@Override
17821792
public FileVisitResult postVisitDirectory(Path d, IOException exc) throws IOException {
17831793
// attach monitor
1794+
LOGGER.log(Level.FINEST, "Watchdog registering {0}", d);
17841795
d.register(watchDogWatcher, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY);
17851796
return CONTINUE;
17861797
}
17871798
});
1788-
1799+
17891800
LOGGER.log(Level.INFO, "Watch dog started {0}", directory);
17901801
while (!Thread.currentThread().isInterrupted()) {
17911802
final WatchKey key;
@@ -1815,9 +1826,10 @@ public FileVisitResult postVisitDirectory(Path d, IOException exc) throws IOExce
18151826
}
18161827
}
18171828
} catch (InterruptedException | IOException ex) {
1829+
LOGGER.log(Level.FINEST, "Watchdog finishing (exiting)", ex);
18181830
Thread.currentThread().interrupt();
18191831
}
1820-
LOGGER.log(Level.INFO, "Watchdog finishing (exiting)");
1832+
LOGGER.log(Level.FINER, "Watchdog finishing (exiting)");
18211833
}
18221834
}, "watchDogService");
18231835
watchDogThread.start();
@@ -1831,17 +1843,18 @@ public void stopWatchDogService() {
18311843
try {
18321844
watchDogWatcher.close();
18331845
} catch (IOException ex) {
1834-
LOGGER.log(Level.INFO, "Cannot close WatchDogService: ", ex);
1846+
LOGGER.log(Level.WARNING, "Cannot close WatchDogService: ", ex);
18351847
}
18361848
}
18371849
if (watchDogThread != null) {
18381850
watchDogThread.interrupt();
18391851
try {
18401852
watchDogThread.join();
18411853
} catch (InterruptedException ex) {
1842-
LOGGER.log(Level.INFO, "Cannot join WatchDogService thread: ", ex);
1854+
LOGGER.log(Level.WARNING, "Cannot join WatchDogService thread: ", ex);
18431855
}
18441856
}
1857+
LOGGER.log(Level.INFO, "Watchdog stoped");
18451858
}
18461859

18471860
public void startExpirationTimer() {

0 commit comments

Comments
 (0)