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:");
62 printf(" icu:enabled");
64 printf(" icu:disabled");
66 printf(" yaz:%s", yaz_version_str);
72 static int tcpip_init (void)
77 requested = MAKEWORD(1, 1);
78 if (WSAStartup(requested, &wd))
87 int argc, char **argv)
91 int log_file_in_use = 0;
93 const char *pidfile = 0;
95 const char *listener_override = 0;
96 const char *config_fname = 0;
97 struct conf_config *config = 0;
101 if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
102 yaz_log(YLOG_WARN|YLOG_ERRNO, "signal");
107 yaz_log_init_prefix("pazpar2");
108 yaz_log_xml_errors(0, YLOG_WARN);
110 while ((ret = options("dDf:h:l:p:tu:VX", argv, argc, &arg)) != -2)
115 global_parameters.dump_records = 1;
124 listener_override = arg;
127 yaz_log_init_file(arg);
142 global_parameters.debug_mode = 1;
145 fprintf(stderr, "Usage: pazpar2\n"
146 " -d Show internal records\n"
147 " -D Daemon mode (background)\n"
148 " -f configfile Configuration\n"
149 " -h [host:]port Listener port\n"
150 " -l file Log to file\n"
151 " -p pidfile PID file\n"
152 " -t Test configuration\n"
153 " -u uid Change user to uid\n"
157 " -install Install windows service\n"
158 " -remove Remove windows service\n"
166 yaz_log(YLOG_FATAL, "Configuration must be given with option -f");
169 config = config_create(config_fname, global_parameters.dump_records);
172 sc_stop_config = config;
175 yaz_log(YLOG_LOG, "Configuration OK");
176 config_destroy(config);
180 yaz_log(YLOG_LOG, "Pazpar2 %s started", VERSION);
181 if (daemon && !log_file_in_use)
183 yaz_log(YLOG_FATAL, "Logfile must be given (option -l) for daemon "
187 ret = config_start_listeners(config, listener_override);
189 return ret; /* error starting http listener */
193 yaz_daemon("pazpar2",
194 (global_parameters.debug_mode ? YAZ_DAEMON_DEBUG : 0) +
195 (daemon ? YAZ_DAEMON_FORK : 0) + YAZ_DAEMON_KEEPALIVE,
196 child_handler, config /* child_data */,
203 static void sc_stop(yaz_sc_t s)
205 config_stop_listeners(sc_stop_config);
208 int main(int argc, char **argv)
211 yaz_sc_t s = yaz_sc_create("pazpar2", "Pazpar2");
213 ret = yaz_sc_program(s, argc, argv, sc_main, sc_stop);
222 * c-file-style: "Stroustrup"
223 * indent-tabs-mode: nil
225 * vim: shiftwidth=4 tabstop=8 expandtab