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"
32 #include <yaz/daemon.h>
34 #include <yaz/options.h>
37 static struct conf_config *sc_stop_config = 0;
39 void child_handler(void *data)
41 struct conf_config *config = (struct conf_config *) data;
43 config_start_databases(config);
47 config_destroy(config);
50 static void show_version(void)
52 char yaz_version_str[80];
53 printf("Pazpar2 " PACKAGE_VERSION
54 #ifdef PAZPAR2_VERSION_SHA1
60 yaz_version(yaz_version_str, 0);
62 printf("Configuration:");
64 printf(" icu:enabled");
66 printf(" icu:disabled");
68 printf(" yaz:%s", yaz_version_str);
74 static int tcpip_init (void)
79 requested = MAKEWORD(1, 1);
80 if (WSAStartup(requested, &wd))
89 int argc, char **argv)
93 int log_file_in_use = 0;
95 const char *pidfile = 0;
97 const char *listener_override = 0;
98 const char *config_fname = 0;
99 struct conf_config *config = 0;
103 if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
104 yaz_log(YLOG_WARN|YLOG_ERRNO, "signal");
109 yaz_log_init_prefix("pazpar2");
110 yaz_log_xml_errors(0, YLOG_WARN);
112 while ((ret = options("dDf:h:l:p:tu:v:VX", argv, argc, &arg)) != -2)
117 global_parameters.dump_records = 1;
126 listener_override = arg;
129 yaz_log_init_file(arg);
142 yaz_log_init_level(yaz_log_mask_str(arg));
147 global_parameters.debug_mode = 1;
150 fprintf(stderr, "Usage: pazpar2\n"
151 " -d Show internal records\n"
152 " -D Daemon mode (background)\n"
153 " -f configfile Configuration\n"
154 " -h [host:]port Listener port\n"
155 " -l file Log to file\n"
156 " -p pidfile PID file\n"
157 " -t Test configuration\n"
158 " -u uid Change user to uid\n"
160 " -v level Set log level\n"
163 " -install Install windows service\n"
164 " -remove Remove windows service\n"
172 yaz_log(YLOG_FATAL, "Configuration must be given with option -f");
175 config = config_create(config_fname, global_parameters.dump_records);
178 sc_stop_config = config;
181 yaz_log(YLOG_LOG, "Configuration OK");
182 config_destroy(config);
186 yaz_log(YLOG_LOG, "Pazpar2 " VERSION " "
187 #ifdef PAZPAR2_VERSION_SHA1
193 if (daemon && !log_file_in_use)
195 yaz_log(YLOG_FATAL, "Logfile must be given (option -l) for daemon "
199 ret = config_start_listeners(config, listener_override);
201 return ret; /* error starting http listener */
205 yaz_daemon("pazpar2",
206 (global_parameters.debug_mode ? YAZ_DAEMON_DEBUG : 0) +
207 (daemon ? YAZ_DAEMON_FORK : 0) + YAZ_DAEMON_KEEPALIVE,
208 child_handler, config /* child_data */,
215 static void sc_stop(yaz_sc_t s)
217 config_stop_listeners(sc_stop_config);
220 int main(int argc, char **argv)
223 yaz_sc_t s = yaz_sc_create("pazpar2", "Pazpar2");
225 ret = yaz_sc_program(s, argc, argv, sc_main, sc_stop);
234 * c-file-style: "Stroustrup"
235 * indent-tabs-mode: nil
237 * vim: shiftwidth=4 tabstop=8 expandtab