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 struct conf_config *sc_stop_config = 0;
39 void child_handler(void *data)
41 struct conf_config *config = (struct conf_config *) data;
42 config_read_settings(config);
47 static void show_version(void)
49 char yaz_version_str[80];
50 printf("Pazpar2 " PACKAGE_VERSION
51 #ifdef PAZPAR2_VERSION_SHA1
57 yaz_version(yaz_version_str, 0);
59 printf("Configuration:");
63 printf(" yaz:%s", yaz_version_str);
69 static int tcpip_init (void)
74 requested = MAKEWORD(1, 1);
75 if (WSAStartup(requested, &wd))
84 int argc, char **argv)
88 int log_file_in_use = 0;
90 const char *pidfile = 0;
92 int session_timeout = 60;
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:tT:u:VX", argv, argc, &arg)) != -2)
113 global_parameters.dump_records = 1;
122 listener_override = arg;
125 yaz_log_init_file(arg);
135 session_timeout = atoi(arg);
136 if (session_timeout < 9 || session_timeout > 86400)
138 yaz_log(YLOG_FATAL, "Session timeout out of range 10..86400: %d",
142 global_parameters.session_timeout = session_timeout;
150 global_parameters.debug_mode = 1;
153 fprintf(stderr, "Usage: pazpar2\n"
154 " -d Show internal records\n"
155 " -D Daemon mode (background)\n"
156 " -f configfile Configuration\n"
157 " -h [host:]port Listener port\n"
158 " -l file Log to file\n"
159 " -p pidfile PID file\n"
160 " -t Test configuration\n"
161 " -T session_timeout Session timeout\n"
162 " -u uid Change user to uid\n"
166 " -install Install windows service\n"
167 " -remove Remove windows service\n"
175 yaz_log(YLOG_FATAL, "Configuration must be given with option -f");
178 config = config_create(config_fname, global_parameters.dump_records);
181 sc_stop_config = config;
184 yaz_log(YLOG_LOG, "Configuration OK");
185 config_destroy(config);
189 yaz_log(YLOG_LOG, "Pazpar2 %s started", VERSION);
190 if (daemon && !log_file_in_use)
192 yaz_log(YLOG_FATAL, "Logfile must be given (option -l) for daemon "
196 ret = config_start_listeners(config, listener_override);
198 return ret; /* error starting http listener */
202 yaz_daemon("pazpar2",
203 (global_parameters.debug_mode ? YAZ_DAEMON_DEBUG : 0) +
204 (daemon ? YAZ_DAEMON_FORK : 0) + YAZ_DAEMON_KEEPALIVE,
205 child_handler, config /* child_data */,
212 static void sc_stop(yaz_sc_t s)
214 config_stop_listeners(sc_stop_config);
217 int main(int argc, char **argv)
220 yaz_sc_t s = yaz_sc_create("pazpar2", "Pazpar2");
222 ret = yaz_sc_program(s, argc, argv, sc_main, sc_stop);
231 * c-file-style: "Stroustrup"
232 * indent-tabs-mode: nil
234 * vim: shiftwidth=4 tabstop=8 expandtab