1 /* This file is part of Metaproxy.
2 Copyright (C) 2005-2010 Index Data
4 Metaproxy is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
9 Metaproxy is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #include <yaz/options.h>
23 #include <yaz/daemon.h>
28 #include <libxml/xinclude.h>
30 #include <metaproxy/filter.hpp>
31 #include <metaproxy/package.hpp>
32 #include "router_flexml.hpp"
33 #include "factory_static.hpp"
45 namespace mp = metaproxy_1;
47 mp::RouterFleXML *routerp = 0;
49 static void sig_term_handler(int s)
58 static void handler(void *data)
60 routerp = (mp::RouterFleXML*) data;
62 signal(SIGTERM, sig_term_handler);
64 pack.router(*routerp).move();
69 int argc, char **argv)
73 const char *fname = 0;
77 const char *pidfile = 0;
80 while ((ret = options("c{config}:Dh{help}l:p:u:V{version}w:X",
81 argv, argc, &arg)) != -2)
89 mode = YAZ_DAEMON_FORK|YAZ_DAEMON_KEEPALIVE;
92 std::cerr << "metaproxy\n"
94 " -V|--version version\n"
95 " -c|--config f config filename\n"
96 " -D daemon and keepalive operation\n"
99 " -u id change uid to id\n"
100 " -w dir changes working directory to dir\n"
101 " -X debug mode (no fork/daemon mode)\n"
103 " -install install windows service\n"
104 " -remove remove windows service\n"
110 yaz_log_init_file(arg);
119 std::cout << VERSION "\n";
131 std::cerr << "chdir " << arg << " failed" << std::endl;
135 mode = YAZ_DAEMON_DEBUG;
138 std::cerr << "bad option: " << arg << std::endl;
144 std::cerr << "No configuration given; use -h for help\n";
148 yaz_log(YLOG_LOG, "Metaproxy " VERSION " started");
149 xmlDocPtr doc = xmlReadFile(fname,
151 XML_PARSE_XINCLUDE + XML_PARSE_NOBLANKS
152 + XML_PARSE_NSCLEAN + XML_PARSE_NONET );
156 yaz_log (YLOG_FATAL,"XML parsing failed");
159 // and perform Xinclude then
160 int r = xmlXIncludeProcess(doc);
163 yaz_log(YLOG_FATAL, "XInclude processing failed");
166 WRBUF base_path = wrbuf_alloc();
167 const char *last_p = strrchr(fname,
175 wrbuf_write(base_path, fname, last_p - fname);
177 mp::FactoryStatic factory;
178 mp::RouterFleXML *router =
179 new mp::RouterFleXML(doc, factory, false, wrbuf_cstr(base_path));
180 wrbuf_destroy(base_path);
184 yaz_daemon("metaproxy", mode, handler, router, pidfile, uid);
186 catch (std::logic_error &e) {
187 yaz_log (YLOG_FATAL,"std::logic error: %s" , e.what() );
190 catch (std::runtime_error &e) {
191 yaz_log(YLOG_FATAL, "std::runtime error: %s" , e.what() );
195 yaz_log(YLOG_FATAL, "Unknown Exception");
201 static void sc_stop(yaz_sc_t s)
206 int main(int argc, char **argv)
209 yaz_sc_t s = yaz_sc_create("metaproxy", "metaproxy");
211 ret = yaz_sc_program(s, argc, argv, sc_main, sc_stop);
222 * c-file-style: "Stroustrup"
223 * indent-tabs-mode: nil
225 * vim: shiftwidth=4 tabstop=8 expandtab