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)
42 if (*global_parameters.settings_path_override)
43 settings_read(global_parameters.settings_path_override);
44 else if (global_parameters.server->settings)
45 settings_read(global_parameters.server->settings);
47 yaz_log(YLOG_WARN, "No settings-directory specified");
48 global_parameters.odr_in = odr_createmem(ODR_DECODE);
49 global_parameters.odr_out = odr_createmem(ODR_ENCODE);
56 static void show_version(void)
58 char yaz_version_str[80];
59 printf("Pazpar2 " PACKAGE_VERSION
60 #ifdef PAZPAR2_VERSION_SHA1
66 yaz_version(yaz_version_str, 0);
68 printf("Configuration:");
72 printf(" yaz:%s", yaz_version_str);
78 static int tcpip_init (void)
83 requested = MAKEWORD(1, 1);
84 if (WSAStartup(requested, &wd))
93 int argc, char **argv)
97 int log_file_in_use = 0;
99 const char *pidfile = 0;
103 if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
104 yaz_log(YLOG_WARN|YLOG_ERRNO, "signal");
109 yaz_log_init_prefix("pazpar2");
110 yaz_log_xml_errors(0, YLOG_WARN);
112 while ((ret = options("dDf:h:l:p:t:u:VX", argv, argc, &arg)) != -2)
117 global_parameters.dump_records = 1;
123 if (!read_config(arg))
127 strcpy(global_parameters.listener_override, arg);
130 yaz_log_init_file(arg);
137 strcpy(global_parameters.settings_path_override, arg);
145 global_parameters.debug_mode = 1;
148 fprintf(stderr, "Usage: pazpar2\n"
149 " -d (show internal records)\n"
150 " -D Daemon mode (background)\n"
152 " -h [host:]port (REST protocol listener)\n"
153 " -l file log to file\n"
154 " -p pidfile PID file\n"
160 " -install install windows service\n"
161 " -remove remove windows service\n"
168 yaz_log(YLOG_LOG, "Pazpar2 %s started", VERSION);
169 if (daemon && !log_file_in_use)
171 yaz_log(YLOG_FATAL, "Logfile must be given (option -l) for daemon "
177 yaz_log(YLOG_FATAL, "Load config with -f");
180 global_parameters.server = config->servers;
182 ret = start_http_listener();
184 return ret; /* error starting http listener */
188 yaz_daemon("pazpar2",
189 (global_parameters.debug_mode ? YAZ_DAEMON_DEBUG : 0) +
190 (daemon ? YAZ_DAEMON_FORK : 0) + YAZ_DAEMON_KEEPALIVE,
191 child_handler, 0 /* child_data */,
197 static void sc_stop(yaz_sc_t s)
202 int main(int argc, char **argv)
205 yaz_sc_t s = yaz_sc_create("pazpar2", "Pazpar2");
207 ret = yaz_sc_program(s, argc, argv, sc_main, sc_stop);
216 * c-file-style: "Stroustrup"
217 * indent-tabs-mode: nil
219 * vim: shiftwidth=4 tabstop=8 expandtab