View source with formatted comments or as raw
    1#!/usr/bin/env swipl
    2
    3:- module(swish_daemon, []).    4
    5/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    6Run
    7
    8    ./daemon.pl --help for help
    9- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
   10
   11/*  Part of SWISH
   12
   13    Author:        Jan Wielemaker
   14    E-mail:        J.Wielemaker@cs.vu.nl
   15    WWW:           http://www.swi-prolog.org
   16    Copyright (C): 2014-2016, VU University Amsterdam
   17			      CWI Amsterdam
   18    All rights reserved.
   19
   20    Redistribution and use in source and binary forms, with or without
   21    modification, are permitted provided that the following conditions
   22    are met:
   23
   24    1. Redistributions of source code must retain the above copyright
   25       notice, this list of conditions and the following disclaimer.
   26
   27    2. Redistributions in binary form must reproduce the above copyright
   28       notice, this list of conditions and the following disclaimer in
   29       the documentation and/or other materials provided with the
   30       distribution.
   31
   32    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   33    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
   34    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
   35    FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
   36    COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
   37    INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
   38    BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
   39    LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
   40    CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   41    LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
   42    ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   43    POSSIBILITY OF SUCH DAMAGE.
   44*/
   45
   46:- use_module(library(http/http_unix_daemon)).   47:- use_module(library(option)).   48:- use_module(library(main)).   49
   50:- initialization(swish_daemon, main).   51
   52swish_daemon :-
   53	current_prolog_flag(argv, Argv),
   54	argv_options(Argv, _RestArgv, Options0),
   55	swish_options(Options0, Options),
   56	(   option(https(_), Options)
   57	->  use_module(swish(lib/ssl_certificate))
   58	;   true
   59	),
   60	http_daemon(Options).
   61
   62swish_options(Options0, Options) :-
   63	option(https(_), Options0), !,
   64	add_default_option(certfile, Options0, 'https/server.crt', Options1),
   65	add_default_option(keyfile,  Options1, 'https/server.key', Options).
   66swish_options(Options, Options).
   67
   68add_default_option(Name, Options0, Default, Options) :-
   69	Term =.. [Name,Value],
   70	(   option(Term, Options0)
   71	->  Options = Options0
   72	;   Value = Default,
   73	    Options = [Term|Options0]
   74	).
   75
   76user:file_search_path(swish, SwishDir) :-
   77	getenv('SWISH_HOME', SwishDir), !.
   78user:file_search_path(swish, SwishDir) :-
   79	source_file(swish_daemon, ThisFile),
   80	file_directory_name(ThisFile, SwishDir).
   81
   82:- [swish(swish)].