Added option -V which shows version information.
[pazpar2-moved-to-github.git] / src / pazpar2.c
1 /* $Id: pazpar2.c,v 1.93 2007-09-10 08:42:48 adam Exp $
2    Copyright (c) 2006-2007, Index Data.
3
4 This file is part of Pazpar2.
5
6 Pazpar2 is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2, or (at your option) any later
9 version.
10
11 Pazpar2 is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with Pazpar2; see the file LICENSE.  If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
19 02111-1307, USA.
20  */
21
22 #if HAVE_CONFIG_H
23 #include "cconfig.h"
24 #endif
25
26
27 #include <signal.h>
28 #include <assert.h>
29
30 #include "pazpar2.h"
31 #include "database.h"
32 #include "settings.h"
33
34 void child_handler(void *data)
35 {
36     start_proxy();
37     init_settings();
38
39     if (*global_parameters.settings_path_override)
40         settings_read(global_parameters.settings_path_override);
41     else if (global_parameters.server->settings)
42         settings_read(global_parameters.server->settings);
43     else
44         yaz_log(YLOG_WARN, "No settings-directory specified");
45     global_parameters.odr_in = odr_createmem(ODR_DECODE);
46     global_parameters.odr_out = odr_createmem(ODR_ENCODE);
47
48
49     pazpar2_event_loop();
50
51 }
52
53 static void show_version(void)
54 {
55     char yaz_version_str[80];
56     printf("Pazpar2 " VERSION "\n");
57
58     yaz_version(yaz_version_str, 0);
59
60     printf("Configuration:");
61 #if HAVE_ICU
62     printf(" icu:?");
63 #endif
64     printf(" yaz:%s", yaz_version_str);
65     printf("\n");
66     exit(0);
67 }            
68
69 int main(int argc, char **argv)
70 {
71     int daemon = 0;
72     int ret;
73     int log_file_in_use = 0;
74     char *arg;
75     const char *pidfile = 0;
76     const char *uid = 0;
77
78     if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
79         yaz_log(YLOG_WARN|YLOG_ERRNO, "signal");
80
81     yaz_log_init_prefix("pazpar2");
82
83     while ((ret = options("dDf:h:l:p:t:u:VX", argv, argc, &arg)) != -2)
84     {
85         switch (ret)
86         {
87         case 'd':
88             global_parameters.dump_records = 1;
89             break;
90         case 'D':
91             daemon = 1;
92             break;
93         case 'f':
94             if (!read_config(arg))
95                 exit(1);
96             break;
97         case 'h':
98             strcpy(global_parameters.listener_override, arg);
99             break;
100         case 'l':
101             yaz_log_init_file(arg);
102             log_file_in_use = 1;
103             break;
104         case 'p':
105             pidfile = arg;
106             break;
107         case 't':
108             strcpy(global_parameters.settings_path_override, arg);
109             break;
110         case 'u':
111             uid = arg;
112             break;
113         case 'V':
114             show_version();
115         case 'X':
116             global_parameters.debug_mode = 1;
117             break;
118         default:
119             fprintf(stderr, "Usage: pazpar2\n"
120                     "    -d                      (show internal records)\n"
121                     "    -D                      Daemon mode (background)\n"
122                     "    -f configfile\n"
123                     "    -h [host:]port          (REST protocol listener)\n"
124                     "    -l file                 log to file\n"
125                     "    -p pidfile              PID file\n"
126                     "    -t settings\n"
127                     "    -u uid\n"
128                     "    -V                      show version\n"
129                     "    -X                      debug mode\n"
130                 );
131             exit(1);
132         }
133     }
134
135     yaz_log(YLOG_LOG, "Pazpar2 %s started", VERSION);
136     if (daemon && !log_file_in_use)
137     {
138         yaz_log(YLOG_FATAL, "Logfile must be given (option -l) for daemon "
139                 "mode");
140         exit(1);
141     }
142     if (!config)
143     {
144         yaz_log(YLOG_FATAL, "Load config with -f");
145         exit(1);
146     }
147     global_parameters.server = config->servers;
148
149     start_http_listener();
150     pazpar2_process(global_parameters.debug_mode, daemon,
151                     child_handler, 0 /* child_data */,
152                     pidfile, uid);
153     return 0;
154 }
155
156
157 /*
158  * Local variables:
159  * c-basic-offset: 4
160  * indent-tabs-mode: nil
161  * End:
162  * vim: shiftwidth=4 tabstop=8 expandtab
163  */