Metaproxy daemon using yaz_daemon + new options.
authorAdam Dickmeiss <adam@indexdata.dk>
Wed, 20 Feb 2008 12:39:34 +0000 (12:39 +0000)
committerAdam Dickmeiss <adam@indexdata.dk>
Wed, 20 Feb 2008 12:39:34 +0000 (12:39 +0000)
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.

doc/metaproxy.xml
src/metaproxy_prog.cpp

index b10ea05..6cd9bea 100644 (file)
@@ -4,7 +4,7 @@
  <!ENTITY % idcommon SYSTEM "common/common.ent">
      %idcommon;
 ]>
-<!-- $Id: metaproxy.xml,v 1.8 2007-05-22 11:05:45 adam Exp $ -->
+<!-- $Id: metaproxy.xml,v 1.9 2008-02-20 12:39:34 adam Exp $ -->
 <refentry id="ref-metaproxy">
  <refmeta>
   <refentrytitle>metaproxy</refentrytitle>
  
  <refnamediv>
   <refname>metaproxy</refname>
-  <refpurpose>Metaproxy - daemon</refpurpose>
+  <refpurpose>Metaproxy - server</refpurpose>
  </refnamediv>
  
  <refsynopsisdiv>
   <cmdsynopsis>
    <command>metaproxy</command>
    <arg choice="opt"><option>--help</option></arg>
+   <arg choice="opt"><option>--version</option></arg>
    <arg choice="opt"><option>--config <replaceable>config</replaceable></option></arg>
+   <arg choice="opt"><option>-D</option></arg>
+   <arg choice="opt"><option>-l <replaceable>logfile</replaceable></option></arg>
+   <arg choice="opt"><option>-p <replaceable>pidfile</replaceable></option></arg>
+   <arg choice="opt"><option>-u <replaceable>ID</replaceable></option></arg>
+   <arg choice="opt"><option>-X</option></arg>
   </cmdsynopsis>
  </refsynopsisdiv>
  
    </varlistentry>
 
    <varlistentry>
+    <term>--version</term>
+    <listitem><para>
+      Displays Metaproxy version.
+     </para></listitem>
+   </varlistentry>
+
+   <varlistentry>
     <term>--config <replaceable>config</replaceable></term>
     <listitem><para>
       Specify the configuration.
      </para></listitem>
    </varlistentry>
 
+   <varlistentry>
+    <term>-D</term>
+    <listitem><para>
+      Puts Metaproxy in the background after startup.
+     </para></listitem>
+   </varlistentry>
+
+   <varlistentry>
+    <term>-l <replaceable>logfile</replaceable></term>
+    <listitem><para>
+      Specifies YAZ log file.
+     </para></listitem>
+   </varlistentry>
+
+   <varlistentry>
+    <term>-p <replaceable>pidfile</replaceable></term>
+    <listitem><para>
+      Specifies file which holds PID after startup.
+     </para></listitem>
+   </varlistentry>
+
+   <varlistentry>
+    <term>-u <replaceable>ID</replaceable></term>
+    <listitem><para>
+      Makes Metaproxy changes its identity to ID after startup.
+     </para></listitem>
+   </varlistentry>
+
+   <varlistentry>
+    <term>-X</term>
+    <listitem><para>
+      Makes Metaproxy operate in debug mode.
+     </para></listitem>
+   </varlistentry>
+
   </variablelist>
  </refsect1>
 
index f9ee154..29f4697 100644 (file)
@@ -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 <yaz/log.h>
 #include <yaz/options.h>
+#include <yaz/daemon.h>
 
 #include <iostream>
 #include <stdexcept>
@@ -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";