From: Adam Dickmeiss Date: Wed, 20 Feb 2008 12:39:34 +0000 (+0000) Subject: Metaproxy daemon using yaz_daemon + new options. X-Git-Tag: METAPROXY.1.0.13~11 X-Git-Url: http://sru.miketaylor.org.uk/cgi-bin?a=commitdiff_plain;h=1c5e3c3f45380b6ad370fa7ba6c2b8239c21071c;p=metaproxy-moved-to-github.git Metaproxy daemon using yaz_daemon + new options. The metaproxy daemon server is now using yaz_daemon to faciliate change of identify, forking etc. New options are -D, -l, -p, -u, -X. Man page metaproxy.1 updated. --- diff --git a/doc/metaproxy.xml b/doc/metaproxy.xml index b10ea05..6cd9bea 100644 --- a/doc/metaproxy.xml +++ b/doc/metaproxy.xml @@ -4,7 +4,7 @@ %idcommon; ]> - + metaproxy @@ -13,14 +13,20 @@ metaproxy - Metaproxy - daemon + Metaproxy - server metaproxy + + + + + + @@ -43,12 +49,54 @@ + --version + + Displays Metaproxy version. + + + + --config config Specify the configuration. + + -D + + Puts Metaproxy in the background after startup. + + + + + -l logfile + + Specifies YAZ log file. + + + + + -p pidfile + + Specifies file which holds PID after startup. + + + + + -u ID + + Makes Metaproxy changes its identity to ID after startup. + + + + + -X + + Makes Metaproxy operate in debug mode. + + + diff --git a/src/metaproxy_prog.cpp b/src/metaproxy_prog.cpp index f9ee154..29f4697 100644 --- a/src/metaproxy_prog.cpp +++ b/src/metaproxy_prog.cpp @@ -1,4 +1,4 @@ -/* $Id: metaproxy_prog.cpp,v 1.12 2008-02-20 10:49:49 adam Exp $ +/* $Id: metaproxy_prog.cpp,v 1.13 2008-02-20 12:39:35 adam Exp $ Copyright (c) 2005-2008, Index Data. This file is part of Metaproxy. @@ -21,7 +21,9 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include "config.hpp" +#include #include +#include #include #include @@ -34,6 +36,14 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA namespace mp = metaproxy_1; +static void handler(void *data) +{ + mp::RouterFleXML *routerp = (mp::RouterFleXML*) data; + + mp::Package pack; + pack.router(*routerp).move(); +} + int main(int argc, char **argv) { try @@ -41,23 +51,47 @@ int main(int argc, char **argv) const char *fname = 0; int ret; char *arg; - while ((ret = options("h{help}V{version}c{config}:", + unsigned mode = 0; + const char *pidfile = 0; + const char *uid = 0; + + while ((ret = options("c{config}:Dh{help}l:p:u:V{version}X", argv, argc, &arg)) != -2) { switch (ret) { + case 'c': + fname = arg; + break; + case 'D': + mode = YAZ_DAEMON_FORK|YAZ_DAEMON_KEEPALIVE; + break; case 'h': std::cerr << "metaproxy\n" " -h|--help help\n" " -V|--version version\n" - " -c|--config config filename\n" + " -c|--config f config filename\n" + " -D daemon and keepalive operation\n" + " -l f log file f\n" + " -p f pid file f\n" + " -u id change uid to id\n" + " -X debug mode (no fork/daemon mode)\n" << std::endl; break; + case 'l': + yaz_log_init_file(arg); + break; + case 'p': + pidfile = arg; + break; + case 'u': + uid = arg; + break; case 'V': std::cout << "Metaproxy " VERSION "\n"; break; - case 'c': - fname = arg; + case 'X': + mode = YAZ_DAEMON_DEBUG; break; case -1: std::cerr << "bad option: " << arg << std::endl; @@ -69,6 +103,7 @@ int main(int argc, char **argv) std::cerr << "No configuration given\n"; std::exit(1); } + xmlDocPtr doc = xmlReadFile(fname, NULL, XML_PARSE_XINCLUDE + XML_PARSE_NOBLANKS @@ -85,9 +120,8 @@ int main(int argc, char **argv) } mp::FactoryStatic factory; mp::RouterFleXML router(doc, factory); - mp::Package pack; - pack.router(router).move(); - xmlFreeDoc(doc); + + yaz_daemon("metaproxy", mode, handler, &router, pidfile, uid); } catch (std::logic_error &e) { std::cerr << "std::logic error: " << e.what() << "\n";