122 int argc,
char **argv)
124 bool test_config =
false;
125 const char *fname = 0;
129 const char *pidfile = 0;
132 const char *socket_limit = 0;
135 yaz_enable_panic_backtrace(argv[0]);
138 while ((ret = options(
"c{config}:Dh{help}l:m:p:s:tu:v:V{version}w:X",
139 argv, argc, &arg)) != -2)
147 mode = YAZ_DAEMON_FORK|YAZ_DAEMON_KEEPALIVE;
150 std::cerr <<
"metaproxy\n"
152 " -V|--version version\n"
154 " -c|--config f config filename\n"
155 " -D daemon and keepalive operation\n"
157 " -m logformat log time format (strftime)\n"
159 " -s n socket limit\n"
160 " -t test configuration\n"
161 " -u id change uid to id\n"
162 " -w dir changes working directory to dir\n"
163 " -X debug mode (no fork/daemon mode)\n"
165 " -install install windows service\n"
166 " -remove remove windows service\n"
172 yaz_log_init_file(arg);
175 yaz_log_time_format(arg);
184 yaz_log(YLOG_WARN,
"Option -s unsuppoted on this platform");
194 yaz_log_init_level(yaz_log_mask_str(arg));
213 std::cerr <<
"chdir " << arg <<
" failed" << std::endl;
217 mode = YAZ_DAEMON_DEBUG;
220 std::cerr <<
"bad option: " << arg << std::endl;
226 std::cerr <<
"No configuration given; use -h for help\n";
230 yaz_log(YLOG_LOG,
"metaproxy %s " VERSION
234 , test_config ?
"test" :
"start"
237 char yaz_version_str[20];
238 char yaz_sha1_str[41];
239 yaz_version(yaz_version_str, yaz_sha1_str);
240 yaz_log(YLOG_LOG,
"YAZ %s %s", yaz_version_str, yaz_sha1_str);
245 yaz_log_xml_errors(0, YLOG_LOG);
246 xmlDocPtr doc = xmlReadFile(fname,
248 XML_PARSE_XINCLUDE + XML_PARSE_NOBLANKS
249 + XML_PARSE_NSCLEAN + XML_PARSE_NONET );
253 yaz_log(YLOG_FATAL,
"XML parsing failed");
257 int r = xmlXIncludeProcess(doc);
260 yaz_log(YLOG_FATAL,
"XInclude processing failed");
264 const char *last_p = strrchr(fname,
272 wrbuf_write(base_path, fname, last_p - fname);
274 wrbuf_puts(base_path,
".");
277 mp::RouterXML *router =
278 new mp::RouterXML(doc, test_config, wrbuf_cstr(base_path));
284 struct rlimit limit_data;
285 limit_data.rlim_cur = atoi(socket_limit);
286 limit_data.rlim_max = atoi(socket_limit);
287 int r = setrlimit(RLIMIT_NOFILE, &limit_data);
290 yaz_log(YLOG_FATAL,
"setrlimit: %s", strerror(errno));
298 yaz_daemon(
"metaproxy", mode | YAZ_DAEMON_LOG_REOPEN,
300 router, pidfile, uid);
304 catch (std::logic_error &e) {
305 yaz_log(YLOG_FATAL,
"std::logic error: %s" , e.what() );
308 catch (std::runtime_error &e) {
309 yaz_log(YLOG_FATAL,
"std::runtime error: %s" , e.what() );
313 yaz_log(YLOG_FATAL,
"Unknown Exception");
318 yaz_log(YLOG_LOG,
"metaproxy test exit code %d", ret);