1 /* This file is part of Pazpar2.
2 Copyright (C) 2006-2010 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>
38 static struct conf_config *sc_stop_config = 0;
40 void child_handler(void *data)
42 struct conf_config *config = (struct conf_config *) data;
44 config_process_events(config);
46 config_destroy(config);
49 static void show_version(void)
51 char yaz_version_str[80];
52 printf("Pazpar2 " PACKAGE_VERSION
53 #ifdef PAZPAR2_VERSION_SHA1
59 yaz_version(yaz_version_str, 0);
61 printf("Configuration:");
63 printf(" icu:enabled");
65 printf(" icu:disabled");
67 printf(" yaz:%s", yaz_version_str);
73 static int tcpip_init (void)
78 requested = MAKEWORD(1, 1);
79 if (WSAStartup(requested, &wd))
88 int argc, char **argv)
92 int log_file_in_use = 0;
94 const char *pidfile = 0;
96 const char *listener_override = 0;
97 const char *config_fname = 0;
98 struct conf_config *config = 0;
102 if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
103 yaz_log(YLOG_WARN|YLOG_ERRNO, "signal");
108 yaz_log_init_prefix("pazpar2");
109 yaz_log_xml_errors(0, YLOG_WARN);
111 while ((ret = options("dDf:h:l:p:tu:v:VX", argv, argc, &arg)) != -2)
116 global_parameters.dump_records = 1;
125 listener_override = arg;
128 yaz_log_init_file(arg);
141 yaz_log_init_level(yaz_log_mask_str(arg));
146 global_parameters.debug_mode++;
149 fprintf(stderr, "Usage: pazpar2\n"
150 " -d Show internal records\n"
151 " -D Daemon mode (background)\n"
152 " -f configfile Configuration\n"
153 " -h [host:]port Listener port\n"
154 " -l file Log to file\n"
155 " -p pidfile PID file\n"
156 " -t Test configuration\n"
157 " -u uid Change user to uid\n"
159 " -v level Set log level\n"
162 " -install Install windows service\n"
163 " -remove Remove windows service\n"
171 yaz_log(YLOG_FATAL, "Configuration must be given with option -f");
174 pazpar2_mutex_init();
176 config = config_create(config_fname, global_parameters.dump_records);
179 sc_stop_config = config;
182 yaz_log(YLOG_LOG, "Configuration OK");
183 config_destroy(config);
187 yaz_log(YLOG_LOG, "Pazpar2 " VERSION " "
188 #ifdef PAZPAR2_VERSION_SHA1
194 if (daemon && !log_file_in_use)
196 yaz_log(YLOG_FATAL, "Logfile must be given (option -l) for daemon "
200 ret = config_start_listeners(config, listener_override);
202 return ret; /* error starting http listener */
206 yaz_daemon("pazpar2",
207 (global_parameters.debug_mode ? YAZ_DAEMON_DEBUG : 0) +
208 (daemon ? YAZ_DAEMON_FORK : 0) + YAZ_DAEMON_KEEPALIVE,
209 child_handler, config /* child_data */,
216 static void sc_stop(yaz_sc_t s)
218 config_stop_listeners(sc_stop_config);
221 int main(int argc, char **argv)
224 yaz_sc_t s = yaz_sc_create("pazpar2", "Pazpar2");
226 ret = yaz_sc_program(s, argc, argv, sc_main, sc_stop);
235 * c-file-style: "Stroustrup"
236 * indent-tabs-mode: nil
238 * vim: shiftwidth=4 tabstop=8 expandtab