1 /* This file is part of Pazpar2.
2 Copyright (C) 2006-2011 Index Data
4 Pazpar2 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 Pazpar2 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
33 #include "parameters.h"
36 #include <yaz/daemon.h>
38 #include <yaz/options.h>
46 static struct conf_config *sc_stop_config = 0;
48 void child_handler(void *data)
50 struct conf_config *config = (struct conf_config *) data;
52 config_process_events(config);
54 config_destroy(config);
57 static void show_version(void)
59 char yaz_version_str[80];
60 printf("Pazpar2 " PACKAGE_VERSION
61 #ifdef PAZPAR2_VERSION_SHA1
67 yaz_version(yaz_version_str, 0);
69 printf("Configuration:");
71 printf(" icu:enabled");
73 printf(" icu:disabled");
75 printf(" yaz:%s", yaz_version_str);
81 static int tcpip_init (void)
86 requested = MAKEWORD(1, 1);
87 if (WSAStartup(requested, &wd))
96 int argc, char **argv)
100 int log_file_in_use = 0;
102 const char *pidfile = 0;
104 const char *listener_override = 0;
105 const char *config_fname = 0;
106 const char *record_fname = 0;
107 struct conf_config *config = 0;
111 if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
112 yaz_log(YLOG_WARN|YLOG_ERRNO, "signal");
117 yaz_log_init_prefix("pazpar2");
118 yaz_log_xml_errors(0, YLOG_WARN);
120 while ((ret = options("dDf:h:l:p:R:tu:v:VX", argv, argc, &arg)) != -2)
125 global_parameters.dump_records = 1;
134 listener_override = arg;
137 yaz_log_init_file(arg);
145 global_parameters.predictable_sessions = 1;
154 yaz_log_init_level(yaz_log_mask_str(arg));
162 yaz_log(YLOG_FATAL|YLOG_ERRNO, "chdir %s", arg);
167 global_parameters.debug_mode++;
168 global_parameters.predictable_sessions = 1;
171 fprintf(stderr, "Usage: pazpar2\n"
172 " -d Show internal records\n"
173 " -D Daemon mode (background)\n"
174 " -f configfile Configuration\n"
175 " -h [host:]port Listener port\n"
176 " -l file Log to file\n"
177 " -p pidfile PID file\n"
178 " -R recfile HTTP recording file\n"
179 " -t Test configuration\n"
180 " -u uid Change user to uid\n"
182 " -v level Set log level\n"
183 " -w dir Working directory\n"
186 " -install Install windows service\n"
187 " -remove Remove windows service\n"
195 yaz_log(YLOG_FATAL, "Configuration must be given with option -f");
198 pazpar2_mutex_init();
200 config = config_create(config_fname, global_parameters.dump_records);
203 sc_stop_config = config;
206 yaz_log(YLOG_LOG, "Configuration OK");
207 config_destroy(config);
211 yaz_log(YLOG_LOG, "Pazpar2 " VERSION " "
212 #ifdef PAZPAR2_VERSION_SHA1
218 if (daemon && !log_file_in_use)
220 yaz_log(YLOG_FATAL, "Logfile must be given (option -l) for daemon "
224 ret = config_start_listeners(config, listener_override, record_fname);
226 return ret; /* error starting http listener */
230 yaz_daemon("pazpar2",
231 (global_parameters.debug_mode ? YAZ_DAEMON_DEBUG : 0) +
232 (daemon ? YAZ_DAEMON_FORK : 0) + YAZ_DAEMON_KEEPALIVE,
233 child_handler, config /* child_data */,
240 static void sc_stop(yaz_sc_t s)
242 config_stop_listeners(sc_stop_config);
245 int main(int argc, char **argv)
248 yaz_sc_t s = yaz_sc_create("pazpar2", "Pazpar2");
254 ret = yaz_sc_program(s, argc, argv, sc_main, sc_stop);
269 * c-file-style: "Stroustrup"
270 * indent-tabs-mode: nil
272 * vim: shiftwidth=4 tabstop=8 expandtab