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>
47 static struct conf_config *sc_stop_config = 0;
49 void child_handler(void *data)
51 struct conf_config *config = (struct conf_config *) data;
53 config_process_events(config);
55 config_destroy(config);
58 static void show_version(void)
60 char yaz_version_str[80];
61 printf("Pazpar2 " PACKAGE_VERSION
62 #ifdef PAZPAR2_VERSION_SHA1
68 yaz_version(yaz_version_str, 0);
70 printf("Configuration:");
72 printf(" icu:enabled");
74 printf(" icu:disabled");
76 printf(" yaz:%s", yaz_version_str);
82 static int tcpip_init (void)
87 requested = MAKEWORD(1, 1);
88 if (WSAStartup(requested, &wd))
97 int argc, char **argv)
101 int log_file_in_use = 0;
103 const char *pidfile = 0;
105 const char *listener_override = 0;
106 const char *config_fname = 0;
107 const char *record_fname = 0;
108 struct conf_config *config = 0;
115 if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
116 yaz_log(YLOG_WARN|YLOG_ERRNO, "signal");
121 yaz_log_init_prefix("pazpar2");
122 yaz_log_xml_errors(0, YLOG_WARN);
124 while ((ret = options("dDf:h:l:m:p:R:tu:v:Vw:X", argv, argc, &arg)) != -2)
129 global_parameters.dump_records++;
138 listener_override = arg;
141 yaz_log_init_file(arg);
145 yaz_log_time_format(arg);
152 global_parameters.predictable_sessions = 1;
161 yaz_log_init_level(yaz_log_mask_str(arg));
175 yaz_log(YLOG_FATAL|YLOG_ERRNO, "chdir %s", arg);
180 global_parameters.debug_mode++;
181 global_parameters.predictable_sessions = 1;
184 fprintf(stderr, "Usage: pazpar2\n"
185 " -d Show internal records\n"
186 " -D Daemon mode (background)\n"
187 " -f configfile Configuration\n"
188 " -h [host:]port Listener port\n"
189 " -l file Log to file\n"
190 " -m logformat log time format (strftime)\n"
191 " -p pidfile PID file\n"
192 " -R recfile HTTP recording file\n"
193 " -t Test configuration\n"
194 " -u uid Change user to uid\n"
196 " -v level Set log level\n"
197 " -w dir Working directory\n"
200 " -install Install windows service\n"
201 " -remove Remove windows service\n"
209 yaz_log(YLOG_FATAL, "Configuration must be given with option -f");
212 pazpar2_mutex_init();
216 yaz_log(YLOG_LOG, "Pazpar2 start " VERSION " "
217 #ifdef PAZPAR2_VERSION_SHA1
224 config = config_create(config_fname);
227 sc_stop_config = config;
230 yaz_log(YLOG_LOG, "Configuration OK");
231 config_destroy(config);
236 if (daemon && !log_file_in_use)
238 yaz_log(YLOG_FATAL, "Logfile must be given (option -l) for daemon "
243 ret = config_start_listeners(config, listener_override,
248 yaz_daemon("pazpar2",
249 (global_parameters.debug_mode ? YAZ_DAEMON_DEBUG : 0) +
250 (daemon ? YAZ_DAEMON_FORK : 0) + YAZ_DAEMON_KEEPALIVE,
251 child_handler, config /* child_data */,
254 yaz_log(YLOG_LOG, "Pazpar2 stop");
261 static void sc_stop(yaz_sc_t s)
263 config_stop_listeners(sc_stop_config);
266 int main(int argc, char **argv)
269 yaz_sc_t s = yaz_sc_create("pazpar2", "Pazpar2");
275 ret = yaz_sc_program(s, argc, argv, sc_main, sc_stop);
290 * c-file-style: "Stroustrup"
291 * indent-tabs-mode: nil
293 * vim: shiftwidth=4 tabstop=8 expandtab