diff conf/serve_nabble.luan @ 0:7ecd1a4ef557

add content
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 21 Mar 2019 19:15:52 -0600
parents
children abe0694e9849
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/conf/serve_nabble.luan	Thu Mar 21 19:15:52 2019 -0600
@@ -0,0 +1,148 @@
+java()
+local Luan = require "luan:Luan.luan"
+local error = Luan.error
+local ipairs = Luan.ipairs or error()
+local Io = require "luan:Io.luan"
+local String = require "luan:String.luan"
+local LoggerFactory = require "java:org.slf4j.LoggerFactory"
+local Log4j = require "java:nabble.utils.Log4j"
+local Init = require "file:conf/Init.luan"
+
+
+local Serve = {}
+
+Serve.username = "nabble"
+Serve.password = "password"
+
+Serve.is_www = false
+Serve.is_forums = true
+
+Serve.www_port = 8080
+Serve.forums_port = 8080
+
+local log_to_console = false
+
+for _, arg in ipairs{...} do
+	if arg == "console" then
+		log_to_console = true
+	end
+	if arg == "www" then
+		Serve.is_www = true
+	end
+end
+
+Init.fix_serve(Serve)
+
+if log_to_console then
+	Log4j.initForConsole()
+else
+	Log4j.initBasicFiles("logs/info.log", "logs/warn.log", "logs/error.log", "5MB")
+	Log4j.initForClass("nabble.view.web.embed.JsEmbed", "logs/embed.log", "1MB")
+end
+
+local logger = LoggerFactory.getLogger("serve_nabble");
+
+local function add_contexts(jetty)
+	local context = jetty.newTools2Context()
+	jetty.authenticate(context, "/*", Serve.username, Serve.password)
+	
+	-- /logs folder
+	context = jetty.newFolderContext("/logs", "logs", { "/*" }, true);
+	jetty.authenticate(context, "/*", Serve.username, Serve.password)
+	
+	-- /conf folder
+	context = jetty.newFolderContext("/conf", "conf", { "/*" }, true);
+	jetty.authenticate(context, "/*", Serve.username, Serve.password)
+end
+
+
+if Serve.is_www then
+
+	-- jetty
+
+	local GlobalJetty = require "java:global.GlobalJetty"
+	
+	local jetty = GlobalJetty.new();
+	local context = jetty.newWebContext();
+	
+	jetty.authenticate(context, "/tools/*", Serve.username, Serve.password)
+	
+	add_contexts(jetty)
+	
+	-- /html folder
+	context = jetty.newFolderContext("/html", "html", { "/*" }, true);
+	jetty.authenticate(context,"/*", Serve.username, Serve.password);
+	
+	local log = jetty.newNCSARequestLog()
+	local server = jetty.newServer(Serve.www_port, log);
+	server.start();
+	
+	logger.error("www server started");
+end
+
+
+if Serve.is_forums then
+	local Jetty = require "java:nabble.utils.Jetty"
+	
+	local jettyConfig = {
+		cache = "true"
+		timeLimit = "60000"
+		errorCacheSize = "1000"
+		ipListSize = "5"
+		exportDir = "export/"
+	}
+	
+	local jetty = Jetty.new();
+	local context = jetty.newWebContext(jettyConfig);
+	
+	context.setMaxFormContentSize(500000);
+	jetty.authenticate(context, "/tools/*", Serve.username, Serve.password);
+	
+	
+	-- Start Filters
+	
+	Init.add_filters(context)
+
+	jetty.addNabbleErrorFilter(context);
+	
+	jetty.addNabbleConnectionLimitFilter(context, { max = "115", queueSize = "1000", timeoutDelay = "45000" });
+	
+	jetty.addBadBotFilter(context, { max = "10" });
+	
+	jetty.addCachingFilter(context, { dir = Init.local_dir.."cache", hasDelayedDelete = "true", acceptEncoding = "gzip" });
+	local FileHandler = require "java:cachingfilter.FileHandler"
+	FileHandler.factory = FileHandler.mappedOrIoFile;
+	
+	jetty.addGzipFilter(context);
+	
+	add_contexts(jetty)
+	
+	-- /backups folder
+	context = jetty.newFolderContext("/backups", Init.local_dir.."schemas", { "/*" }, false);
+	
+	local log
+	if log_to_console then
+		log = jetty.newNCSARequestLog()
+	else
+		Io.uri("file:logs/daily").mkdir()
+		log = jetty.newNCSARequestLog("logs/daily/yyyy_mm_dd.log")
+		log.setRetainDays(30)
+	end
+	
+	local server = jetty.newServer(Serve.forums_port, log);
+	jetty.setThreadPool(server);
+
+	local DbGlobalUpdater = require "java:nabble.model.DbGlobalUpdater"
+	DbGlobalUpdater.updateGlobal()
+	logger.info "db update done"
+
+	local ClearCache = require "java:nabble.view.lib.ClearCache"
+	ClearCache.run()
+	--logger.info "db cache cleared"
+
+	server.start();
+	
+	logger.error("nabble server started");
+	
+	jetty.addShutdownHook(server);
+end_if