-
Notifications
You must be signed in to change notification settings - Fork 10
/
load.pl
115 lines (104 loc) · 2.88 KB
/
load.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
:- dynamic
pre_files/1.
:- findall(F, source_file(F), FL),
assertz(pre_files(FL)).
:- doc_collect(true).
:- attach_packs(packs, [duplicate(replace)]).
:- load_files([ library(pldoc/doc_library),
library(thread_pool),
library(http/http_session),
library(http/http_unix_daemon),
library(http/http_dyn_workers),
library(prolog_source),
plweb,
examples,
blog,
api,
wiki_edit,
stats,
pack,
register,
changelog,
tagit,
forum,
make,
test_recaptcha,
watchdog
],
[ silent(true)
]).
:- if(exists_source(library(ssh_server))).
:- use_module(library(ssh_server)).
:- use_module(library(broadcast)).
:- listen(http(pre_server_start),
start_sshd).
start_sshd :-
absolute_file_name(private('etc/ssh/authorized_keys'), File,
[ access(read)]),
absolute_file_name(private('etc/ssh/ssh_host_ecdsa_key'), HostKey,
[ access(read)]),
ssh_server([ port(2022),
bind_address(*),
authorized_keys_file(File),
host_key_file(HostKey)
]).
:- endif.
%% read_comments(+File)
%
% Reads PlDoc comments for a file that was already loaded before
% the server was started.
read_comments(File) :-
source_file_property(File, module(M)), !,
setup_call_cleanup(
( prolog_open_source(File, In),
set_prolog_flag(xref, true),
'$set_source_module'(Old, M)
),
( repeat,
prolog_read_source_term(In, Term, _,
[ process_comment(true)
]),
Term == end_of_file,
!
),
( '$set_source_module'(_, Old),
set_prolog_flag(xref, false),
prolog_close_source(In)
)).
read_comments(_). % not a module, we do not care
reload_pre_files :-
pre_files(FL),
forall(member(F, FL),
read_comments(F)).
:- reload_pre_files.
:- doc_load_library.
:- http_set_session_options([enabled(false)]).
:- send(@(pce), catch_error_signals, @(off)).
%% show_fd
%
% Show open file descriptors. Sanity-check that works only on
% Linux systems.
show_fd :-
current_prolog_flag(pid, Pid),
format(string(Cmd),
'/bin/sh -c "(cd /proc/~w/fd && ls -l | grep socket)"',
[Pid]),
shell(Cmd).
show_pools :-
format('~`-t~52|~n'),
format('~w~t~20|~t~w~8+~t~w~8+~t~w~8+~t~w~8+~n',
[ 'Pool name', 'Running', 'Size', 'Waiting', 'Backlog' ]),
format('~`-t~52|~n'),
forall(current_thread_pool(Pool), show_pool(Pool)),
format('~`-t~52|~n').
show_pool(Pool) :-
findall(P, thread_pool_property(Pool, P), List),
memberchk(size(Size), List),
memberchk(running(Running), List),
memberchk(backlog(Waiting), List),
memberchk(options(Options), List),
option(backlog(MaxBackLog), Options, infinite),
format('~w~t~20|~t~D ~8+~t~D ~8+~t~D ~8+~t~w ~8+~n',
[Pool, Running, Size, Waiting, MaxBackLog]).
stop :-
halt(42).