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
33 #include <yaz/daemon.h>
37 void child_handler(void *data)
39 struct conf_service *service = global_parameters.server->service;
42 init_settings(service);
44 if (*global_parameters.settings_path_override)
45 settings_read(service, global_parameters.settings_path_override);
46 else if (global_parameters.server->settings)
47 settings_read(service, global_parameters.server->settings);
49 yaz_log(YLOG_WARN, "No settings-directory specified");
50 global_parameters.odr_in = odr_createmem(ODR_DECODE);
51 global_parameters.odr_out = odr_createmem(ODR_ENCODE);
57 static void show_version(void)
59 char yaz_version_str[80];
60 printf("Pazpar2 " PACKAGE_VERSION
61 #ifdef PAZPAR2_VERSION_SHA1
67 yaz_version(yaz_version_str, 0);
69 printf("Configuration:");
73 printf(" yaz:%s", yaz_version_str);
79 static int tcpip_init (void)
84 requested = MAKEWORD(1, 1);
85 if (WSAStartup(requested, &wd))
94 int argc, char **argv)
98 int log_file_in_use = 0;
100 const char *pidfile = 0;
102 int session_timeout = 60;
105 if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
106 yaz_log(YLOG_WARN|YLOG_ERRNO, "signal");
111 yaz_log_init_prefix("pazpar2");
112 yaz_log_xml_errors(0, YLOG_WARN);
114 while ((ret = options("dDf:h:l:p:t:T:u:VX", argv, argc, &arg)) != -2)
119 global_parameters.dump_records = 1;
125 if (!read_config(arg))
129 strcpy(global_parameters.listener_override, arg);
132 yaz_log_init_file(arg);
139 strcpy(global_parameters.settings_path_override, arg);
142 session_timeout = atoi(arg);
143 if (session_timeout < 9 || session_timeout > 86400)
145 yaz_log(YLOG_FATAL, "Session timeout out of range 10..86400: %d",
149 global_parameters.session_timeout = session_timeout;
157 global_parameters.debug_mode = 1;
160 fprintf(stderr, "Usage: pazpar2\n"
161 " -d (show internal records)\n"
162 " -D Daemon mode (background)\n"
164 " -h [host:]port (REST protocol listener)\n"
165 " -l file log to file\n"
166 " -p pidfile PID file\n"
168 " -T session_timeout\n"
173 " -install install windows service\n"
174 " -remove remove windows service\n"
181 yaz_log(YLOG_LOG, "Pazpar2 %s started", VERSION);
182 if (daemon && !log_file_in_use)
184 yaz_log(YLOG_FATAL, "Logfile must be given (option -l) for daemon "
190 yaz_log(YLOG_FATAL, "Load config with -f");
193 global_parameters.server = config->servers;
195 ret = start_http_listener();
197 return ret; /* error starting http listener */
201 yaz_daemon("pazpar2",
202 (global_parameters.debug_mode ? YAZ_DAEMON_DEBUG : 0) +
203 (daemon ? YAZ_DAEMON_FORK : 0) + YAZ_DAEMON_KEEPALIVE,
204 child_handler, 0 /* child_data */,
210 static void sc_stop(yaz_sc_t s)
215 int main(int argc, char **argv)
218 yaz_sc_t s = yaz_sc_create("pazpar2", "Pazpar2");
220 ret = yaz_sc_program(s, argc, argv, sc_main, sc_stop);
229 * c-file-style: "Stroustrup"
230 * indent-tabs-mode: nil
232 * vim: shiftwidth=4 tabstop=8 expandtab