22 #include <sys/resource.h>
26 #include <yaz/options.h>
27 #include <yaz/daemon.h>
30 #include <yaz/backtrace.h>
33 #include <libxml/xinclude.h>
35 #include <metaproxy/filter.hpp>
36 #include <metaproxy/package.hpp>
37 #include <metaproxy/util.hpp>
38 #include <metaproxy/router_xml.hpp>
59 sprintf(str,
"%lld", (
long long) getpid());
60 yaz_log_init_prefix(str);
94 routerp = (mp::RouterXML*) data;
98 pack.router(*routerp).move();
99 yaz_log(YLOG_LOG,
"metaproxy stop");
121 int argc,
char **argv)
123 bool test_config =
false;
124 const char *fname = 0;
128 const char *pidfile = 0;
131 const char *socket_limit = 0;
134 yaz_enable_panic_backtrace(argv[0]);
137 while ((ret = options(
"c{config}:Dh{help}l:m:p:s:tu:v:V{version}w:X",
138 argv, argc, &arg)) != -2)
146 mode = YAZ_DAEMON_FORK|YAZ_DAEMON_KEEPALIVE;
149 std::cerr <<
"metaproxy\n"
151 " -V|--version version\n"
153 " -c|--config f config filename\n"
154 " -D daemon and keepalive operation\n"
156 " -m logformat log time format (strftime)\n"
158 " -s n socket limit\n"
159 " -t test configuration\n"
160 " -u id change uid to id\n"
161 " -w dir changes working directory to dir\n"
162 " -X debug mode (no fork/daemon mode)\n"
164 " -install install windows service\n"
165 " -remove remove windows service\n"
171 yaz_log_init_file(arg);
174 yaz_log_time_format(arg);
183 yaz_log(YLOG_WARN,
"Option -s unsuppoted on this platform");
193 yaz_log_init_level(yaz_log_mask_str(arg));
212 std::cerr <<
"chdir " << arg <<
" failed" << std::endl;
216 mode = YAZ_DAEMON_DEBUG;
219 std::cerr <<
"bad option: " << arg << std::endl;
225 std::cerr <<
"No configuration given; use -h for help\n";
229 yaz_log(YLOG_LOG,
"metaproxy %s " VERSION
233 , test_config ?
"test" :
"start"
236 char yaz_version_str[20];
237 char yaz_sha1_str[41];
238 yaz_version(yaz_version_str, yaz_sha1_str);
239 yaz_log(YLOG_LOG,
"YAZ %s %s", yaz_version_str, yaz_sha1_str);
244 yaz_log_xml_errors(0, YLOG_LOG);
245 xmlDocPtr doc = xmlReadFile(fname,
247 XML_PARSE_XINCLUDE + XML_PARSE_NOBLANKS
248 + XML_PARSE_NSCLEAN + XML_PARSE_NONET );
252 yaz_log(YLOG_FATAL,
"XML parsing failed");
256 int r = xmlXIncludeProcess(doc);
259 yaz_log(YLOG_FATAL,
"XInclude processing failed");
263 const char *last_p = strrchr(fname,
271 wrbuf_write(base_path, fname, last_p - fname);
273 wrbuf_puts(base_path,
".");
276 mp::RouterXML *router =
277 new mp::RouterXML(doc, test_config, wrbuf_cstr(base_path));
283 struct rlimit limit_data;
284 limit_data.rlim_cur = atoi(socket_limit);
285 limit_data.rlim_max = atoi(socket_limit);
286 int r = setrlimit(RLIMIT_NOFILE, &limit_data);
289 yaz_log(YLOG_FATAL,
"setrlimit: %s", strerror(errno));
297 yaz_daemon(
"metaproxy", mode | YAZ_DAEMON_LOG_REOPEN,
299 router, pidfile, uid);
303 catch (std::logic_error &e) {
304 yaz_log(YLOG_FATAL,
"std::logic error: %s" , e.what() );
307 catch (std::runtime_error &e) {
308 yaz_log(YLOG_FATAL,
"std::runtime error: %s" , e.what() );
312 yaz_log(YLOG_FATAL,
"Unknown Exception");
317 yaz_log(YLOG_LOG,
"metaproxy test exit code %d", ret);
326 int main(
int argc,
char **argv)
329 yaz_sc_t s = yaz_sc_create(
"metaproxy",
"metaproxy");