1 /* This file is part of Pazpar2.
2 Copyright (C) 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
34 #include "parameters.h"
37 #include <yaz/daemon.h>
39 #include <yaz/options.h>
41 #include <yaz/backtrace.h>
48 static struct conf_config *sc_stop_config = 0;
50 void child_handler(void *data)
52 struct conf_config *config = (struct conf_config *) data;
54 config_process_events(config);
56 config_destroy(config);
59 static void show_version(void)
61 char yaz_version_str[20];
62 printf("Pazpar2 " PACKAGE_VERSION
63 #ifdef PAZPAR2_VERSION_SHA1
69 yaz_version(yaz_version_str, 0);
71 printf("Configuration:");
73 printf(" icu:enabled");
75 printf(" icu:disabled");
77 printf(" yaz:%s", yaz_version_str);
83 static int tcpip_init (void)
88 requested = MAKEWORD(1, 1);
89 if (WSAStartup(requested, &wd))
98 int argc, char **argv)
102 int log_file_in_use = 0;
104 const char *pidfile = 0;
106 const char *listener_override = 0;
107 const char *config_fname = 0;
108 const char *record_fname = 0;
109 struct conf_config *config = 0;
116 if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
117 yaz_log(YLOG_WARN|YLOG_ERRNO, "signal");
122 yaz_log_init_prefix("pazpar2");
123 yaz_log_init_level(yaz_log_mask_str("post"));
124 yaz_log_xml_errors(0, YLOG_WARN);
126 yaz_enable_panic_backtrace(argv[0]);
128 while ((ret = options("dDf:h:l:m:p:R:tu:v:Vw:X", argv, argc, &arg)) != -2)
133 global_parameters.dump_records++;
142 listener_override = arg;
145 yaz_log_init_file(arg);
149 yaz_log_time_format(arg);
155 if (strcmp(arg, "-"))
157 global_parameters.predictable_sessions = 1;
166 yaz_log_init_level(yaz_log_mask_str(arg));
180 yaz_log(YLOG_FATAL|YLOG_ERRNO, "chdir %s", arg);
185 global_parameters.debug_mode++;
186 global_parameters.predictable_sessions = 1;
189 fprintf(stderr, "Usage: pazpar2\n"
190 " -d Show internal records\n"
191 " -D Daemon mode (background)\n"
192 " -f configfile Configuration\n"
193 " -h [host:]port Listener port\n"
194 " -l file Log to file\n"
195 " -m logformat log time format (strftime)\n"
196 " -p pidfile PID file\n"
197 " -R recfile HTTP recording file\n"
198 " -t Test configuration\n"
199 " -u uid Change user to uid\n"
201 " -v level Set log level\n"
202 " -w dir Working directory\n"
205 " -install Install windows service\n"
206 " -remove Remove windows service\n"
214 yaz_log(YLOG_FATAL, "Configuration must be given with option -f");
217 pazpar2_mutex_init();
220 char yaz_version_str[20];
221 char yaz_sha1_str[41];
222 yaz_log(YLOG_LOG, "Pazpar2 %s " VERSION " "
223 #ifdef PAZPAR2_VERSION_SHA1
228 , test_mode ? "test" : "start");
229 yaz_version(yaz_version_str, yaz_sha1_str);
230 yaz_log(YLOG_LOG, "YAZ %s %s", yaz_version_str, yaz_sha1_str);
233 config = config_create(config_fname);
236 sc_stop_config = config;
239 yaz_log(YLOG_LOG, "Configuration OK");
240 config_destroy(config);
245 if (daemon && !log_file_in_use)
247 yaz_log(YLOG_FATAL, "Logfile must be given (option -l) for daemon "
252 ret = config_start_listeners(config, listener_override,
257 yaz_daemon("pazpar2",
258 (global_parameters.debug_mode ? YAZ_DAEMON_DEBUG : 0) +
259 (daemon ? YAZ_DAEMON_FORK : 0) + YAZ_DAEMON_KEEPALIVE,
260 child_handler, config /* child_data */,
263 yaz_log(YLOG_LOG, "Pazpar2 stop");
270 static void sc_stop(yaz_sc_t s)
272 config_stop_listeners(sc_stop_config);
275 int main(int argc, char **argv)
278 yaz_sc_t s = yaz_sc_create("pazpar2", "Pazpar2");
284 ret = yaz_sc_program(s, argc, argv, sc_main, sc_stop);
299 * c-file-style: "Stroustrup"
300 * indent-tabs-mode: nil
302 * vim: shiftwidth=4 tabstop=8 expandtab