changeset 2022:969291201e12

ping lucene backups
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 20 Oct 2025 17:25:47 -0600
parents b8e5d53c4fc9
children 544ccce564f6
files host/admin/src/init.luan host/admin/src/private/host/Config.luan host/admin/src/private/lib/monitor.luan host/admin/src/private/lib/monitor_lucene_backups.luan src/goodjava/lucene/backup/BackupIndexWriter.java src/goodjava/lucene/backup/BackupServer.java src/luan/modules/lucene/Lucene.luan
diffstat 7 files changed, 62 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
diff -r b8e5d53c4fc9 -r 969291201e12 host/admin/src/init.luan
--- a/host/admin/src/init.luan	Mon Oct 20 14:45:27 2025 -0600
+++ b/host/admin/src/init.luan	Mon Oct 20 17:25:47 2025 -0600
@@ -4,6 +4,7 @@
 Hosted.set_https and Hosted.set_https(true)
 
 require "site:/private/lib/monitor.luan"
+require "site:/private/lib/monitor_lucene_backups.luan"
 
 Http.dont_gc and Http.dont_gc()
 
diff -r b8e5d53c4fc9 -r 969291201e12 host/admin/src/private/host/Config.luan
--- a/host/admin/src/private/host/Config.luan	Mon Oct 20 14:45:27 2025 -0600
+++ b/host/admin/src/private/host/Config.luan	Mon Oct 20 17:25:47 2025 -0600
@@ -26,7 +26,7 @@
 else
 	local dir = Io.uri("file:.").canonical().to_string()
 	if String.starts_with( dir, "/Users/fschmidt/" ) then
-		BackupIndexWriter.backupDomains = {"localhost"}
+		-- BackupIndexWriter.backupDomains = {"localhost"}
 	end
 end
 
diff -r b8e5d53c4fc9 -r 969291201e12 host/admin/src/private/lib/monitor.luan
--- a/host/admin/src/private/lib/monitor.luan	Mon Oct 20 14:45:27 2025 -0600
+++ b/host/admin/src/private/lib/monitor.luan	Mon Oct 20 17:25:47 2025 -0600
@@ -9,6 +9,7 @@
 local Http = require "luan:http/Http.luan"
 local Config = require "site:/private/Config.luan"
 local Utils = require "site:/private/lib/Utils.luan"
+local send_mail = Utils.send_mail or error()
 local Logging = require "luan:logging/Logging.luan"
 local logger = Logging.logger "monitor"
 
@@ -52,7 +53,7 @@
 				logger.info("stopped with stop script")
 			else
 				logger.error("restart successful\n"..s)
-				Utils.send_mail {
+				send_mail {
 					Subject = domain.." restarted"
 					body = s
 				}
@@ -61,7 +62,7 @@
 		catch e
 			logger.error("restart failed: "..e.get_message())
 			if fails < 5 then
-				Utils.send_mail {
+				send_mail {
 					Subject = domain.." restart failed"
 					body = e.get_message()
 				}
diff -r b8e5d53c4fc9 -r 969291201e12 host/admin/src/private/lib/monitor_lucene_backups.luan
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/host/admin/src/private/lib/monitor_lucene_backups.luan	Mon Oct 20 17:25:47 2025 -0600
@@ -0,0 +1,30 @@
+local Luan = require "luan:Luan.luan"
+local error = Luan.error
+local Time = require "luan:Time.luan"
+local Thread = require "luan:Thread.luan"
+local Lucene = require "luan:lucene/Lucene.luan"
+local ping_backups = Lucene.ping_backups or error()
+local Utils = require "site:/private/lib/Utils.luan"
+local send_mail = Utils.send_mail or error()
+local Logging = require "luan:logging/Logging.luan"
+local logger = Logging.logger "monitor_lucene_backups"
+
+
+local function check()
+	local backup_domain = ping_backups()
+	if backup_domain == nil then
+		logger.info("lucene backups are okay")
+	else
+		local msg = "lucene backups to "..backup_domain.." aren't working"
+		logger.error(msg)
+		send_mail {
+			Subject = "lucene backups"
+			body = msg
+		}
+	end
+end
+
+Thread.schedule(check,{repeating_delay=Time.period{hours=1}})
+check()
+
+return true
diff -r b8e5d53c4fc9 -r 969291201e12 src/goodjava/lucene/backup/BackupIndexWriter.java
--- a/src/goodjava/lucene/backup/BackupIndexWriter.java	Mon Oct 20 14:45:27 2025 -0600
+++ b/src/goodjava/lucene/backup/BackupIndexWriter.java	Mon Oct 20 17:25:47 2025 -0600
@@ -231,4 +231,21 @@
 		return new BackupIndexWriter(indexWriter,logDir,logTime,domain,name);
 	}
 
+	// returns failed domain or null
+	public static String ping() throws IOException {
+		if( backupDomains == null ) {
+			logger.error("backupDomains not set");
+			return null;
+		}
+		for( String backupDomain : backupDomains ) {
+			try {
+				Socket socket = BackupServer.clientSocket(backupDomain);
+				socket.close();
+			} catch(ConnectException e) {
+				return backupDomain;
+			}
+		}
+		return null;
+	}
+
 }
diff -r b8e5d53c4fc9 -r 969291201e12 src/goodjava/lucene/backup/BackupServer.java
--- a/src/goodjava/lucene/backup/BackupServer.java	Mon Oct 20 14:45:27 2025 -0600
+++ b/src/goodjava/lucene/backup/BackupServer.java	Mon Oct 20 17:25:47 2025 -0600
@@ -161,7 +161,7 @@
 
 	// for client
 
-	public static RpcClient rpcClient(String backupDomain) throws IOException {
+	static Socket clientSocket(String backupDomain) throws IOException {
 		Socket socket;
 		if( BackupServer.cipherSuites == null ) {
 			socket = new Socket(backupDomain,BackupServer.port);
@@ -169,6 +169,11 @@
 			socket = IoUtils.getSSLSocketFactory().createSocket(backupDomain,BackupServer.port);
 			((SSLSocket)socket).setEnabledCipherSuites(BackupServer.cipherSuites);
 		}
+		return socket;
+	}
+
+	public static RpcClient rpcClient(String backupDomain) throws IOException {
+		Socket socket = clientSocket(backupDomain);
 		return new RpcClient(socket);
 	}
 
diff -r b8e5d53c4fc9 -r 969291201e12 src/luan/modules/lucene/Lucene.luan
--- a/src/luan/modules/lucene/Lucene.luan	Mon Oct 20 14:45:27 2025 -0600
+++ b/src/luan/modules/lucene/Lucene.luan	Mon Oct 20 17:25:47 2025 -0600
@@ -22,6 +22,7 @@
 local LuceneIndex = require "java:luan.modules.lucene.LuceneIndex"
 local NumberFieldParser = require "java:goodjava.lucene.queryparser.NumberFieldParser"
 local GoodQueryParser = require "java:goodjava.lucene.queryparser.GoodQueryParser"
+local BackupIndexWriter = require "java:goodjava.lucene.backup.BackupIndexWriter"
 local Logging = require "luan:logging/Logging.luan"
 local logger = Logging.logger "Lucene"
 
@@ -252,4 +253,7 @@
 	end
 end
 
+-- returns failed backup domain or nil
+Lucene.ping_backups = BackupIndexWriter.ping
+
 return Lucene