#!/bin/sh
# BEGIN COPYRIGHT BLOCK
# Copyright (C) 2001 Sun Microsystems, Inc.  Used by permission.
# Copyright (C) 2005 Red Hat, Inc.
# All rights reserved.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
#

# END COPYRIGHT BLOCK

# This script sets up the environment for the httpd server and starts it.
# for httpd, on RHEL, this will typically be something like /usr/sbin/httpd.worker
# On HP-UX, this may be /opt/hpws/apache/bin/httpd.

unset PASSWORD_PIPE

LD_LIBRARY_PATH=/usr/lib64:${LD_LIBRARY_PATH};export LD_LIBRARY_PATH
LIBPATH=/usr/lib64:${LIBPATH}:/usr/threads/lib:/usr/ibmcxx/lib:/usr/lib:/lib; export LIBPATH
SHLIB_PATH=/usr/lib64:${SHLIB_PATH}; export SHLIB_PATH

HTTPD=/usr/sbin/httpd.worker

# see if httpd is linked with the openldap libraries - we need to override them
OS=`uname -s`
if [ $OS = "Linux" ]; then
    hasol=0

    /usr/bin/ldd $HTTPD 2>&1 | grep libldap > /dev/null 2>&1 && hasol=1

    if [ $hasol -eq 1 ] ; then
        LD_PRELOAD="/usr/lib64/libldap60.so"
        ssl_lib="/usr/lib64/libssl3.so"
        if [ -f "$ssl_lib" ] ; then
            LD_PRELOAD="$ssl_lib $LD_PRELOAD"
        fi
        export LD_PRELOAD
    fi
fi

# mod_deflate is not supported on HP-UX using the /opt/hpws apache
if [ $OS = "HP-UX" ] ; then
    OMIT_DEFLATE="-DOmitDeflate"
fi

# source env. for admin server
[ -f /etc/sysconfig/dirsrv-admin ] && . /etc/sysconfig/dirsrv-admin

if [ -x /usr/sbin/selinuxenabled ] && /usr/sbin/selinuxenabled; then
    SELINUX_CMD="runcon -t unconfined_t --"
fi

$SELINUX_CMD $HTTPD $OMIT_DEFLATE -k start -f /etc/dirsrv/admin-serv/httpd.conf "$@"
