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>
35 #if YAZ_VERSIONL >= 0x03001D
36 /* Windows service is available in YAZ 3.0.29 or later */
43 void child_handler(void *data)
48 if (*global_parameters.settings_path_override)
49 settings_read(global_parameters.settings_path_override);
50 else if (global_parameters.server->settings)
51 settings_read(global_parameters.server->settings);
53 yaz_log(YLOG_WARN, "No settings-directory specified");
54 global_parameters.odr_in = odr_createmem(ODR_DECODE);
55 global_parameters.odr_out = odr_createmem(ODR_ENCODE);
62 static void show_version(void)
64 char yaz_version_str[80];
65 printf("Pazpar2 " PACKAGE_VERSION "\n");
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))
96 int argc, char **argv)
100 int log_file_in_use = 0;
102 const char *pidfile = 0;
106 for (i = 0; i < argc; i++)
107 yaz_log(YLOG_LOG, "arg%d: %s", i, argv[i]);
109 if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
110 yaz_log(YLOG_WARN|YLOG_ERRNO, "signal");
115 yaz_log_init_prefix("pazpar2");
116 #if YAZ_VERSIONL >= 0x03001B
117 yaz_log_xml_errors(0, YLOG_WARN);
121 while ((ret = options("dDf:h:l:p:t:u:VX", argv, argc, &arg)) != -2)
126 global_parameters.dump_records = 1;
132 if (!read_config(arg))
136 strcpy(global_parameters.listener_override, arg);
139 yaz_log_init_file(arg);
146 strcpy(global_parameters.settings_path_override, arg);
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"
173 yaz_log(YLOG_LOG, "Pazpar2 %s started", VERSION);
174 if (daemon && !log_file_in_use)
176 yaz_log(YLOG_FATAL, "Logfile must be given (option -l) for daemon "
182 yaz_log(YLOG_FATAL, "Load config with -f");
185 global_parameters.server = config->servers;
187 ret = start_http_listener();
189 return ret; /* error starting http listener */
195 yaz_daemon("pazpar2",
196 (global_parameters.debug_mode ? YAZ_DAEMON_DEBUG : 0) +
197 (daemon ? YAZ_DAEMON_FORK : 0) + YAZ_DAEMON_KEEPALIVE,
198 child_handler, 0 /* child_data */,
205 static void sc_stop(yaz_sc_t s)
211 int main(int argc, char **argv)
215 yaz_sc_t s = yaz_sc_create("pazpar2", "Pazpar2");
217 ret = yaz_sc_program(s, argc, argv, sc_main, sc_stop);
221 ret = sc_main(argc, argv);
229 * indent-tabs-mode: nil
231 * vim: shiftwidth=4 tabstop=8 expandtab