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 static char *path_override = 0;
39 void child_handler(void *data)
41 struct conf_config *config = (struct conf_config *) data;
42 config_read_settings(config, path_override);
44 global_parameters.odr_in = odr_createmem(ODR_DECODE);
45 global_parameters.odr_out = odr_createmem(ODR_ENCODE);
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:");
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 int session_timeout = 60;
96 const char *listener_override = 0;
97 const char *proxy_override = 0;
98 struct conf_config *config;
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:t:T:u:VX", argv, argc, &arg)) != -2)
115 global_parameters.dump_records = 1;
121 config = read_config(arg);
126 listener_override = arg;
129 yaz_log_init_file(arg);
139 session_timeout = atoi(arg);
140 if (session_timeout < 9 || session_timeout > 86400)
142 yaz_log(YLOG_FATAL, "Session timeout out of range 10..86400: %d",
146 global_parameters.session_timeout = session_timeout;
154 global_parameters.debug_mode = 1;
157 fprintf(stderr, "Usage: pazpar2\n"
158 " -d (show internal records)\n"
159 " -D Daemon mode (background)\n"
161 " -h [host:]port (REST protocol listener)\n"
162 " -l file log to file\n"
163 " -p pidfile PID file\n"
165 " -T session_timeout\n"
170 " -install install windows service\n"
171 " -remove remove windows service\n"
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 "
187 yaz_log(YLOG_FATAL, "Load config with -f");
190 ret = start_http_listener(config, listener_override, proxy_override);
192 return ret; /* error starting http listener */
196 yaz_daemon("pazpar2",
197 (global_parameters.debug_mode ? YAZ_DAEMON_DEBUG : 0) +
198 (daemon ? YAZ_DAEMON_FORK : 0) + YAZ_DAEMON_KEEPALIVE,
199 child_handler, config /* child_data */,
205 static void sc_stop(yaz_sc_t s)
210 int main(int argc, char **argv)
213 yaz_sc_t s = yaz_sc_create("pazpar2", "Pazpar2");
215 ret = yaz_sc_program(s, argc, argv, sc_main, sc_stop);
224 * c-file-style: "Stroustrup"
225 * indent-tabs-mode: nil
227 * vim: shiftwidth=4 tabstop=8 expandtab