1 /* This file is part of Pazpar2.
2 Copyright (C) 2006-2008 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>
36 void child_handler(void *data)
41 if (*global_parameters.settings_path_override)
42 settings_read(global_parameters.settings_path_override);
43 else if (global_parameters.server->settings)
44 settings_read(global_parameters.server->settings);
46 yaz_log(YLOG_WARN, "No settings-directory specified");
47 global_parameters.odr_in = odr_createmem(ODR_DECODE);
48 global_parameters.odr_out = odr_createmem(ODR_ENCODE);
55 static void show_version(void)
57 char yaz_version_str[80];
58 printf("Pazpar2 " PACKAGE_VERSION "\n");
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))
85 static int sc_main(yaz_sc_t s, int argc, char **argv)
89 int log_file_in_use = 0;
91 const char *pidfile = 0;
95 for (i = 0; i < argc; i++)
96 yaz_log(YLOG_LOG, "arg%d: %s", i, argv[i]);
98 if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
99 yaz_log(YLOG_WARN|YLOG_ERRNO, "signal");
104 yaz_log_init_prefix("pazpar2");
105 #if YAZ_VERSIONL >= 0x03001B
106 yaz_log_xml_errors(0, YLOG_WARN);
110 while ((ret = options("dDf:h:l:p:t:u:VX", argv, argc, &arg)) != -2)
115 global_parameters.dump_records = 1;
121 if (!read_config(arg))
125 strcpy(global_parameters.listener_override, arg);
128 yaz_log_init_file(arg);
135 strcpy(global_parameters.settings_path_override, arg);
143 global_parameters.debug_mode = 1;
146 fprintf(stderr, "Usage: pazpar2\n"
147 " -d (show internal records)\n"
148 " -D Daemon mode (background)\n"
150 " -h [host:]port (REST protocol listener)\n"
151 " -l file log to file\n"
152 " -p pidfile PID file\n"
162 yaz_log(YLOG_LOG, "Pazpar2 %s started", VERSION);
163 if (daemon && !log_file_in_use)
165 yaz_log(YLOG_FATAL, "Logfile must be given (option -l) for daemon "
171 yaz_log(YLOG_FATAL, "Load config with -f");
174 global_parameters.server = config->servers;
176 ret = start_http_listener();
178 return ret; /* error starting http listener */
182 yaz_daemon("pazpar2",
183 (global_parameters.debug_mode ? YAZ_DAEMON_DEBUG : 0) +
184 (daemon ? YAZ_DAEMON_FORK : 0) + YAZ_DAEMON_KEEPALIVE,
185 child_handler, 0 /* child_data */,
191 static void sc_stop(yaz_sc_t s)
196 int main(int argc, char **argv)
199 yaz_sc_t s = yaz_sc_create("pazpar2", "Pazpar2");
201 ret = yaz_sc_program(s, argc, argv, sc_main, sc_stop);
210 * indent-tabs-mode: nil
212 * vim: shiftwidth=4 tabstop=8 expandtab