Chris@0
|
1 /* $Id$
|
Chris@0
|
2
|
Chris@0
|
3 Part of SWI-Prolog
|
Chris@0
|
4
|
Chris@0
|
5 Author: Jan Wielemaker
|
Chris@0
|
6 E-mail: wielemak@science.uva.nl
|
Chris@0
|
7 WWW: http://www.swi-prolog.org
|
Chris@0
|
8 Copyright (C): 2004-2006, University of Amsterdam
|
Chris@0
|
9
|
Chris@0
|
10 This program is free software; you can redistribute it and/or
|
Chris@0
|
11 modify it under the terms of the GNU General Public License
|
Chris@0
|
12 as published by the Free Software Foundation; either version 2
|
Chris@0
|
13 of the License, or (at your option) any later version.
|
Chris@0
|
14
|
Chris@0
|
15 This program is distributed in the hope that it will be useful,
|
Chris@0
|
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
Chris@0
|
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
Chris@0
|
18 GNU General Public License for more details.
|
Chris@0
|
19
|
Chris@0
|
20 You should have received a copy of the GNU Lesser General Public
|
Chris@0
|
21 License along with this library; if not, write to the Free Software
|
Chris@0
|
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
Chris@0
|
23
|
Chris@0
|
24 As a special exception, if you link this library with other files,
|
Chris@0
|
25 compiled with a Free Software compiler, to produce an executable, this
|
Chris@0
|
26 library does not by itself cause the resulting executable to be covered
|
Chris@0
|
27 by the GNU General Public License. This exception does not however
|
Chris@0
|
28 invalidate any other reasons why the executable file might be covered by
|
Chris@0
|
29 the GNU General Public License.
|
Chris@0
|
30 */
|
Chris@0
|
31
|
Chris@0
|
32 :- module(serql_server,
|
Chris@0
|
33 [ serql_server/0,
|
Chris@0
|
34 serql_server/1, % +Options
|
Chris@0
|
35 serql_welcome/0
|
Chris@0
|
36 ]).
|
Chris@0
|
37
|
Chris@0
|
38 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
Chris@0
|
39 This module loads the SWI-Prolog SeRQL server as a library, providing
|
Chris@0
|
40 the public predicates defined in the header. Before loading this file,
|
Chris@0
|
41 the user should set up a the search path `serql'. For example:
|
Chris@0
|
42
|
Chris@0
|
43 :- dynamic
|
Chris@0
|
44 user:file_search_path/2.
|
Chris@0
|
45 :- multifile
|
Chris@0
|
46 user:file_search_path/2.
|
Chris@0
|
47
|
Chris@0
|
48 user:file_search_path(serql, '/usr/local/serql').
|
Chris@0
|
49
|
Chris@0
|
50 :- use_module(serql(load)).
|
Chris@0
|
51 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
Chris@0
|
52
|
Chris@0
|
53 :- dynamic
|
Chris@0
|
54 user:file_search_path/2.
|
Chris@0
|
55 :- multifile
|
Chris@0
|
56 user:file_search_path/2.
|
Chris@0
|
57
|
Chris@0
|
58 :- ( user:file_search_path(serql, _)
|
Chris@0
|
59 -> true
|
Chris@0
|
60 ; prolog_load_context(directory, Dir),
|
Chris@0
|
61 assert(user:file_search_path(serql, Dir))
|
Chris@0
|
62 ).
|
Chris@0
|
63
|
Chris@0
|
64 user:file_search_path(triple20, serql('Triple20/src')).
|
Chris@0
|
65 user:file_search_path(library, serql(lib)).
|
Chris@0
|
66 user:file_search_path(ontology_root, serql('Ontologies')).
|
Chris@0
|
67
|
Chris@0
|
68 :- load_files([version], [silent(true), if(not_loaded)]).
|
Chris@0
|
69 :- check_prolog_version(50625). % Demand >= 5.6.25
|
Chris@0
|
70
|
Chris@0
|
71 :- load_files([ parms,
|
Chris@0
|
72 library(option),
|
Chris@0
|
73 library(debug),
|
Chris@0
|
74 library(lists),
|
Chris@0
|
75 library(settings),
|
Chris@0
|
76 library(error),
|
Chris@0
|
77 library(broadcast),
|
Chris@0
|
78 server,
|
Chris@0
|
79 library('semweb/rdf_db'),
|
Chris@0
|
80 library('semweb/rdf_persistency'),
|
Chris@0
|
81 library('semweb/rdf_portray'),
|
Chris@0
|
82 library('http/http_session'),
|
Chris@0
|
83 library(http/thread_httpd),
|
Chris@0
|
84 user_db,
|
Chris@0
|
85 openid,
|
Chris@0
|
86 rdf_store,
|
Chris@0
|
87 jrn_export
|
Chris@0
|
88 ],
|
Chris@0
|
89 [ %silent(true),
|
Chris@0
|
90 if(not_loaded)
|
Chris@0
|
91 ]).
|
Chris@0
|
92
|
Chris@0
|
93 %% serql_server is det.
|
Chris@0
|
94 %% serql_server(+Options) is det.
|
Chris@0
|
95 %
|
Chris@0
|
96 % Start the HTTP server. Defined options are:
|
Chris@0
|
97 %
|
Chris@0
|
98 % * port(Port)
|
Chris@0
|
99 % Attach to Port instead of the port specified in the
|
Chris@0
|
100 % configuration file.
|
Chris@0
|
101 %
|
Chris@0
|
102 % * after_load(+Goal)
|
Chris@0
|
103 % Run Goal after loading/initialising the database. Note
|
Chris@0
|
104 % that serql_server/1 is not a meta-predicate. Goal is
|
Chris@0
|
105 % called in =user= and must be prefixed if calling in
|
Chris@0
|
106 % another module is required.
|
Chris@0
|
107 %
|
Chris@0
|
108 % In addition, all settings as defined in parms.pl are allowed as
|
Chris@0
|
109 % options:
|
Chris@0
|
110 %
|
Chris@0
|
111 % ==
|
Chris@0
|
112 % ?- serql_server([max_idle_time(600)]).
|
Chris@0
|
113 % ==
|
Chris@0
|
114
|
Chris@0
|
115 serql_server :-
|
Chris@0
|
116 serql_server([]).
|
Chris@0
|
117
|
Chris@0
|
118 serql_server(Options) :-
|
Chris@0
|
119 load_settings('settings.db'),
|
Chris@0
|
120 after_load_option(Options, AfterLoad, Options1),
|
Chris@0
|
121 set_options(Options1, Options2),
|
Chris@0
|
122 setting(http:port, Port),
|
Chris@0
|
123 attach_account_info,
|
Chris@0
|
124 set_session_options,
|
Chris@0
|
125 rdf_setup_store(Options2),
|
Chris@0
|
126 user:AfterLoad,
|
Chris@0
|
127 setting(http:workers, Workers),
|
Chris@0
|
128 setting(http:worker_options, Settings),
|
Chris@0
|
129 merge_options([workers(Workers)|Options2], Settings, HTTPOptions),
|
Chris@0
|
130 serql_server(Port, HTTPOptions),
|
Chris@0
|
131 print_message(informational, serql(server_started(Port))).
|
Chris@0
|
132
|
Chris@0
|
133 after_load_option(Options0, AfterLoad, Options) :-
|
Chris@0
|
134 select(after_load(AfterLoad), Options0, Options), !.
|
Chris@0
|
135 after_load_option(Options, true, Options).
|
Chris@0
|
136
|
Chris@0
|
137
|
Chris@0
|
138 %% set_options(+List, -NotProcesses)
|
Chris@0
|
139 %
|
Chris@0
|
140 % Set parameters as defined in parms.pl from all options that
|
Chris@0
|
141 % match a setting name. Using +Option(Value, ...), multiple rules
|
Chris@0
|
142 % are appended.
|
Chris@0
|
143
|
Chris@0
|
144 set_options([], []).
|
Chris@0
|
145 set_options([+Opt|T0], T) :- !,
|
Chris@0
|
146 Opt =.. [Name, Value],
|
Chris@0
|
147 current_setting(serql_parms:Name), !,
|
Chris@0
|
148 setting(serql_parms:Name, Old),
|
Chris@0
|
149 must_be(list(any), Old),
|
Chris@0
|
150 ( memberchk(Value, Old)
|
Chris@0
|
151 -> true
|
Chris@0
|
152 ; set_setting(serql_parms:Name, [Value|Old])
|
Chris@0
|
153 ),
|
Chris@0
|
154 set_options(T0, T).
|
Chris@0
|
155 set_options([Opt|T0], T) :-
|
Chris@0
|
156 Opt =.. [Name, Value],
|
Chris@0
|
157 current_setting(serql_parms:Name), !,
|
Chris@0
|
158 set_setting(serql_parms:Name, Value),
|
Chris@0
|
159 set_options(T0, T).
|
Chris@0
|
160 set_options([H|T0], [H|T]) :-
|
Chris@0
|
161 set_options(T0, T).
|
Chris@0
|
162
|
Chris@0
|
163
|
Chris@0
|
164 attach_account_info :-
|
Chris@0
|
165 setting(serql_parms:user_data, File),
|
Chris@0
|
166 set_user_database(File).
|
Chris@0
|
167
|
Chris@0
|
168 %% set_session_options
|
Chris@0
|
169 %
|
Chris@0
|
170 % Initialise session timeout from =|http:max_idle_time|=.
|
Chris@0
|
171
|
Chris@0
|
172 set_session_options :-
|
Chris@0
|
173 setting(http:max_idle_time, Idle),
|
Chris@0
|
174 http_set_session_options([timeout(Idle)]).
|
Chris@0
|
175
|
Chris@0
|
176
|
Chris@0
|
177 /*******************************
|
Chris@0
|
178 * UPDATE SETTINGS *
|
Chris@0
|
179 *******************************/
|
Chris@0
|
180
|
Chris@0
|
181 :- listen(settings(changed(http:max_idle_time, _, New)),
|
Chris@0
|
182 http_set_session_options([timeout(New)])).
|
Chris@0
|
183 :- listen(settings(changed(http:workers, _, New)),
|
Chris@0
|
184 ( must_be(between(1, 50), New),
|
Chris@0
|
185 setting(http:port, Port),
|
Chris@0
|
186 http_workers(Port, New))).
|
Chris@0
|
187
|
Chris@0
|
188
|
Chris@0
|
189 %% serql_welcome
|
Chris@0
|
190 %
|
Chris@0
|
191 % Print welcome banner.
|
Chris@0
|
192
|
Chris@0
|
193 serql_welcome :-
|
Chris@0
|
194 setting(http:port, Port),
|
Chris@0
|
195 print_message(informational, serql(welcome(Port))).
|
Chris@0
|
196
|
Chris@0
|
197
|
Chris@0
|
198
|
Chris@0
|
199
|
Chris@0
|
200 /*******************************
|
Chris@0
|
201 * MESSAGES *
|
Chris@0
|
202 *******************************/
|
Chris@0
|
203
|
Chris@0
|
204 :- multifile
|
Chris@0
|
205 prolog:message/3.
|
Chris@0
|
206
|
Chris@0
|
207 prolog:message(serql(server_started(Port))) -->
|
Chris@0
|
208 [ 'Started SeRQL server at port ~w'-[Port], nl,
|
Chris@0
|
209 'You may access the server at http://localhost:~w/'-[Port]
|
Chris@0
|
210 ].
|
Chris@0
|
211 prolog:message(serql(welcome(DefaultPort))) -->
|
Chris@0
|
212 [ nl,
|
Chris@0
|
213 'Use one of the calls below to start the SeRQL server:', nl, nl,
|
Chris@0
|
214 ' ?- serql_server. % start at port ~w'-[DefaultPort], nl,
|
Chris@0
|
215 ' ?- serql_server([port(Port)]). % start at Port'
|
Chris@0
|
216 ].
|
Chris@0
|
217
|
Chris@0
|
218
|
Chris@0
|
219 /*******************************
|
Chris@0
|
220 * XREF *
|
Chris@0
|
221 *******************************/
|
Chris@0
|
222
|
Chris@0
|
223 :- multifile
|
Chris@0
|
224 prolog:called_by/2.
|
Chris@0
|
225
|
Chris@0
|
226 prolog:called_by(serql_server(Options), Goals) :-
|
Chris@0
|
227 findall(G, (member(after_load(G), Options), callable(G)), Goals).
|