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
30 #include "parameters.h"
33 #include <yaz/daemon.h>
35 #include <yaz/options.h>
43 static struct conf_config *sc_stop_config = 0;
45 void child_handler(void *data)
47 struct conf_config *config = (struct conf_config *) data;
49 config_process_events(config);
51 config_destroy(config);
54 static void show_version(void)
56 char yaz_version_str[80];
57 printf("Pazpar2 " PACKAGE_VERSION
58 #ifdef PAZPAR2_VERSION_SHA1
64 yaz_version(yaz_version_str, 0);
66 printf("Configuration:");
68 printf(" icu:enabled");
70 printf(" icu:disabled");
72 printf(" yaz:%s", yaz_version_str);
78 static int tcpip_init (void)
83 requested = MAKEWORD(1, 1);
84 if (WSAStartup(requested, &wd))
93 int argc, char **argv)
97 int log_file_in_use = 0;
99 const char *pidfile = 0;
101 const char *listener_override = 0;
102 const char *config_fname = 0;
103 struct conf_config *config = 0;
107 if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
108 yaz_log(YLOG_WARN|YLOG_ERRNO, "signal");
113 yaz_log_init_prefix("pazpar2");
114 yaz_log_xml_errors(0, YLOG_WARN);
116 while ((ret = options("dDf:h:l:p:tu:v:VX", argv, argc, &arg)) != -2)
121 global_parameters.dump_records = 1;
130 listener_override = arg;
133 yaz_log_init_file(arg);
146 yaz_log_init_level(yaz_log_mask_str(arg));
151 global_parameters.debug_mode++;
154 fprintf(stderr, "Usage: pazpar2\n"
155 " -d Show internal records\n"
156 " -D Daemon mode (background)\n"
157 " -f configfile Configuration\n"
158 " -h [host:]port Listener port\n"
159 " -l file Log to file\n"
160 " -p pidfile PID file\n"
161 " -t Test configuration\n"
162 " -u uid Change user to uid\n"
164 " -v level Set log level\n"
167 " -install Install windows service\n"
168 " -remove Remove windows service\n"
176 yaz_log(YLOG_FATAL, "Configuration must be given with option -f");
179 pazpar2_mutex_init();
181 config = config_create(config_fname, global_parameters.dump_records);
184 sc_stop_config = config;
187 yaz_log(YLOG_LOG, "Configuration OK");
188 config_destroy(config);
192 yaz_log(YLOG_LOG, "Pazpar2 " VERSION " "
193 #ifdef PAZPAR2_VERSION_SHA1
199 if (daemon && !log_file_in_use)
201 yaz_log(YLOG_FATAL, "Logfile must be given (option -l) for daemon "
205 ret = config_start_listeners(config, listener_override);
207 return ret; /* error starting http listener */
211 yaz_daemon("pazpar2",
212 (global_parameters.debug_mode ? YAZ_DAEMON_DEBUG : 0) +
213 (daemon ? YAZ_DAEMON_FORK : 0) + YAZ_DAEMON_KEEPALIVE,
214 child_handler, config /* child_data */,
221 static void sc_stop(yaz_sc_t s)
223 config_stop_listeners(sc_stop_config);
226 int main(int argc, char **argv)
229 yaz_sc_t s = yaz_sc_create("pazpar2", "Pazpar2");
235 ret = yaz_sc_program(s, argc, argv, sc_main, sc_stop);
250 * c-file-style: "Stroustrup"
251 * indent-tabs-mode: nil
253 * vim: shiftwidth=4 tabstop=8 expandtab