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_xml_errors(0, YLOG_WARN);
125 yaz_enable_panic_backtrace(argv[0]);
127 while ((ret = options("dDf:h:l:m:p:R:tu:v:Vw:X", argv, argc, &arg)) != -2)
132 global_parameters.dump_records++;
141 listener_override = arg;
144 yaz_log_init_file(arg);
148 yaz_log_time_format(arg);
155 global_parameters.predictable_sessions = 1;
164 yaz_log_init_level(yaz_log_mask_str(arg));
178 yaz_log(YLOG_FATAL|YLOG_ERRNO, "chdir %s", arg);
183 global_parameters.debug_mode++;
184 global_parameters.predictable_sessions = 1;
187 fprintf(stderr, "Usage: pazpar2\n"
188 " -d Show internal records\n"
189 " -D Daemon mode (background)\n"
190 " -f configfile Configuration\n"
191 " -h [host:]port Listener port\n"
192 " -l file Log to file\n"
193 " -m logformat log time format (strftime)\n"
194 " -p pidfile PID file\n"
195 " -R recfile HTTP recording file\n"
196 " -t Test configuration\n"
197 " -u uid Change user to uid\n"
199 " -v level Set log level\n"
200 " -w dir Working directory\n"
203 " -install Install windows service\n"
204 " -remove Remove windows service\n"
212 yaz_log(YLOG_FATAL, "Configuration must be given with option -f");
215 pazpar2_mutex_init();
218 char yaz_version_str[20];
219 char yaz_sha1_str[41];
220 yaz_log(YLOG_LOG, "Pazpar2 %s " VERSION " "
221 #ifdef PAZPAR2_VERSION_SHA1
226 , test_mode ? "test" : "start");
227 yaz_version(yaz_version_str, yaz_sha1_str);
228 yaz_log(YLOG_LOG, "YAZ %s %s", yaz_version_str, yaz_sha1_str);
231 config = config_create(config_fname);
234 sc_stop_config = config;
237 yaz_log(YLOG_LOG, "Configuration OK");
238 config_destroy(config);
243 if (daemon && !log_file_in_use)
245 yaz_log(YLOG_FATAL, "Logfile must be given (option -l) for daemon "
250 ret = config_start_listeners(config, listener_override,
255 yaz_daemon("pazpar2",
256 (global_parameters.debug_mode ? YAZ_DAEMON_DEBUG : 0) +
257 (daemon ? YAZ_DAEMON_FORK : 0) + YAZ_DAEMON_KEEPALIVE,
258 child_handler, config /* child_data */,
261 yaz_log(YLOG_LOG, "Pazpar2 stop");
268 static void sc_stop(yaz_sc_t s)
270 config_stop_listeners(sc_stop_config);
273 int main(int argc, char **argv)
276 yaz_sc_t s = yaz_sc_create("pazpar2", "Pazpar2");
282 ret = yaz_sc_program(s, argc, argv, sc_main, sc_stop);
297 * c-file-style: "Stroustrup"
298 * indent-tabs-mode: nil
300 * vim: shiftwidth=4 tabstop=8 expandtab