1 /* This file is part of Pazpar2.
2 Copyright (C) 2006-2009 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);
48 static void show_version(void)
50 char yaz_version_str[80];
51 printf("Pazpar2 " PACKAGE_VERSION
52 #ifdef PAZPAR2_VERSION_SHA1
58 yaz_version(yaz_version_str, 0);
60 printf("Configuration:");
64 printf(" yaz:%s", yaz_version_str);
70 static int tcpip_init (void)
75 requested = MAKEWORD(1, 1);
76 if (WSAStartup(requested, &wd))
85 int argc, char **argv)
89 int log_file_in_use = 0;
91 const char *pidfile = 0;
93 const char *listener_override = 0;
94 const char *config_fname = 0;
95 struct conf_config *config = 0;
99 if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
100 yaz_log(YLOG_WARN|YLOG_ERRNO, "signal");
105 yaz_log_init_prefix("pazpar2");
106 yaz_log_xml_errors(0, YLOG_WARN);
108 while ((ret = options("dDf:h:l:p:tu:VX", argv, argc, &arg)) != -2)
113 global_parameters.dump_records = 1;
122 listener_override = arg;
125 yaz_log_init_file(arg);
140 global_parameters.debug_mode = 1;
143 fprintf(stderr, "Usage: pazpar2\n"
144 " -d Show internal records\n"
145 " -D Daemon mode (background)\n"
146 " -f configfile Configuration\n"
147 " -h [host:]port Listener port\n"
148 " -l file Log to file\n"
149 " -p pidfile PID file\n"
150 " -t Test configuration\n"
151 " -u uid Change user to uid\n"
155 " -install Install windows service\n"
156 " -remove Remove windows service\n"
164 yaz_log(YLOG_FATAL, "Configuration must be given with option -f");
167 config = config_create(config_fname, global_parameters.dump_records);
170 sc_stop_config = config;
173 yaz_log(YLOG_LOG, "Configuration OK");
174 config_destroy(config);
178 yaz_log(YLOG_LOG, "Pazpar2 %s started", VERSION);
179 if (daemon && !log_file_in_use)
181 yaz_log(YLOG_FATAL, "Logfile must be given (option -l) for daemon "
185 ret = config_start_listeners(config, listener_override);
187 return ret; /* error starting http listener */
191 yaz_daemon("pazpar2",
192 (global_parameters.debug_mode ? YAZ_DAEMON_DEBUG : 0) +
193 (daemon ? YAZ_DAEMON_FORK : 0) + YAZ_DAEMON_KEEPALIVE,
194 child_handler, config /* child_data */,
201 static void sc_stop(yaz_sc_t s)
203 config_stop_listeners(sc_stop_config);
206 int main(int argc, char **argv)
209 yaz_sc_t s = yaz_sc_create("pazpar2", "Pazpar2");
211 ret = yaz_sc_program(s, argc, argv, sc_main, sc_stop);
220 * c-file-style: "Stroustrup"
221 * indent-tabs-mode: nil
223 * vim: shiftwidth=4 tabstop=8 expandtab