Mercurial Hosting > nabble
annotate conf/serve_nabble.luan @ 27:22a701699b2a
add Disk.jtp
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Thu, 02 Jul 2020 16:00:09 -0600 |
parents | abe0694e9849 |
children |
rev | line source |
---|---|
0 | 1 java() |
2 local Luan = require "luan:Luan.luan" | |
3 local error = Luan.error | |
4 local ipairs = Luan.ipairs or error() | |
5 local Io = require "luan:Io.luan" | |
6 local String = require "luan:String.luan" | |
7 local LoggerFactory = require "java:org.slf4j.LoggerFactory" | |
8 local Log4j = require "java:nabble.utils.Log4j" | |
9 local Init = require "file:conf/Init.luan" | |
10 | |
11 | |
12 local Serve = {} | |
13 | |
14 Serve.username = "nabble" | |
15 Serve.password = "password" | |
16 | |
17 Serve.is_www = false | |
18 Serve.is_forums = true | |
19 | |
20 Serve.www_port = 8080 | |
21 Serve.forums_port = 8080 | |
22 | |
23 local log_to_console = false | |
24 | |
25 for _, arg in ipairs{...} do | |
26 if arg == "console" then | |
27 log_to_console = true | |
28 end | |
29 if arg == "www" then | |
30 Serve.is_www = true | |
31 end | |
32 end | |
33 | |
34 Init.fix_serve(Serve) | |
35 | |
36 if log_to_console then | |
37 Log4j.initForConsole() | |
38 else | |
39 Log4j.initBasicFiles("logs/info.log", "logs/warn.log", "logs/error.log", "5MB") | |
40 Log4j.initForClass("nabble.view.web.embed.JsEmbed", "logs/embed.log", "1MB") | |
41 end | |
42 | |
43 local logger = LoggerFactory.getLogger("serve_nabble"); | |
44 | |
45 local function add_contexts(jetty) | |
46 local context = jetty.newTools2Context() | |
47 jetty.authenticate(context, "/*", Serve.username, Serve.password) | |
48 | |
49 -- /logs folder | |
50 context = jetty.newFolderContext("/logs", "logs", { "/*" }, true); | |
51 jetty.authenticate(context, "/*", Serve.username, Serve.password) | |
52 | |
53 -- /conf folder | |
54 context = jetty.newFolderContext("/conf", "conf", { "/*" }, true); | |
55 jetty.authenticate(context, "/*", Serve.username, Serve.password) | |
56 end | |
57 | |
58 | |
59 if Serve.is_www then | |
60 | |
61 -- jetty | |
62 | |
63 local GlobalJetty = require "java:global.GlobalJetty" | |
64 | |
65 local jetty = GlobalJetty.new(); | |
66 local context = jetty.newWebContext(); | |
67 | |
68 jetty.authenticate(context, "/tools/*", Serve.username, Serve.password) | |
69 | |
70 add_contexts(jetty) | |
71 | |
72 -- /html folder | |
73 context = jetty.newFolderContext("/html", "html", { "/*" }, true); | |
74 jetty.authenticate(context,"/*", Serve.username, Serve.password); | |
75 | |
76 local log = jetty.newNCSARequestLog() | |
77 local server = jetty.newServer(Serve.www_port, log); | |
78 server.start(); | |
79 | |
80 logger.error("www server started"); | |
81 end | |
82 | |
83 | |
84 if Serve.is_forums then | |
85 local Jetty = require "java:nabble.utils.Jetty" | |
86 | |
87 local jettyConfig = { | |
88 cache = "true" | |
89 timeLimit = "60000" | |
90 errorCacheSize = "1000" | |
91 ipListSize = "5" | |
92 exportDir = "export/" | |
93 } | |
94 | |
95 local jetty = Jetty.new(); | |
96 local context = jetty.newWebContext(jettyConfig); | |
97 | |
98 context.setMaxFormContentSize(500000); | |
99 jetty.authenticate(context, "/tools/*", Serve.username, Serve.password); | |
100 | |
101 | |
102 -- Start Filters | |
103 | |
104 Init.add_filters(context) | |
105 | |
106 jetty.addNabbleErrorFilter(context); | |
107 | |
108 jetty.addNabbleConnectionLimitFilter(context, { max = "115", queueSize = "1000", timeoutDelay = "45000" }); | |
109 | |
110 jetty.addBadBotFilter(context, { max = "10" }); | |
111 | |
2
abe0694e9849
replace local_dir with home_dir
Franklin Schmidt <fschmidt@gmail.com>
parents:
0
diff
changeset
|
112 jetty.addCachingFilter(context, { dir = Init.home_dir.."local/cache", hasDelayedDelete = "true", acceptEncoding = "gzip" }); |
0 | 113 local FileHandler = require "java:cachingfilter.FileHandler" |
114 FileHandler.factory = FileHandler.mappedOrIoFile; | |
115 | |
116 jetty.addGzipFilter(context); | |
117 | |
118 add_contexts(jetty) | |
119 | |
120 -- /backups folder | |
2
abe0694e9849
replace local_dir with home_dir
Franklin Schmidt <fschmidt@gmail.com>
parents:
0
diff
changeset
|
121 context = jetty.newFolderContext("/backups", Init.home_dir.."local/schemas", { "/*" }, false); |
0 | 122 |
123 local log | |
124 if log_to_console then | |
125 log = jetty.newNCSARequestLog() | |
126 else | |
127 Io.uri("file:logs/daily").mkdir() | |
128 log = jetty.newNCSARequestLog("logs/daily/yyyy_mm_dd.log") | |
129 log.setRetainDays(30) | |
130 end | |
131 | |
132 local server = jetty.newServer(Serve.forums_port, log); | |
133 jetty.setThreadPool(server); | |
134 | |
135 local DbGlobalUpdater = require "java:nabble.model.DbGlobalUpdater" | |
136 DbGlobalUpdater.updateGlobal() | |
137 logger.info "db update done" | |
138 | |
139 local ClearCache = require "java:nabble.view.lib.ClearCache" | |
140 ClearCache.run() | |
141 --logger.info "db cache cleared" | |
142 | |
143 server.start(); | |
144 | |
145 logger.error("nabble server started"); | |
146 | |
147 jetty.addShutdownHook(server); | |
148 end_if |