101511a
#!/bin/bash
101511a
101511a
# globus-gatekeeper
101511a
#
101511a
# chkconfig: - 20 80
101511a
# description: Authorize and execute a grid service
101511a
101511a
### BEGIN INIT INFO
101511a
# Provides:          globus-gatekeeper
101511a
# Required-Start:    $remote_fs $network $time
101511a
# Required-Stop:     $remote_fs $network
101511a
# Default-Stop:      0 1 2 3 4 5 6
101511a
# Short-Description: Globus Gatekeeper
101511a
# Description:       The Globus Gatekeeper service authenticates network
101511a
#                    connections using an SSL-based protocol and then
101511a
#                    starts service instances on the remote user's behalf.
101511a
#                    It is part of the Globus Toolkit(tm)
101511a
### END INIT INFO
101511a
101511a
# Copyright 1999-2010 University of Chicago
101511a
# 
101511a
# Licensed under the Apache License, Version 2.0 (the "License");
101511a
# you may not use this file except in compliance with the License.
101511a
# You may obtain a copy of the License at
101511a
# 
101511a
# http://www.apache.org/licenses/LICENSE-2.0
101511a
# 
101511a
# Unless required by applicable law or agreed to in writing, software
101511a
# distributed under the License is distributed on an "AS IS" BASIS,
101511a
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
101511a
# See the License for the specific language governing permissions and
101511a
# limitations under the License.
101511a
101511a
progname=globus-gatekeeper
101511a
prog=/usr/sbin/${progname}
101511a
101511a
if [ -r /etc/sysconfig/globus-gatekeeper ] ; then
101511a
    . /etc/sysconfig/globus-gatekeeper
101511a
fi
101511a
101511a
test -f ${prog} || exit 0
101511a
395e545
lockfile=/run/lock/subsys/${progname}
101511a
395e545
GLOBUS_GATEKEEPER_PIDFILE="${GLOBUS_GATEKEEPER_PIDFILE:-/run/${progname}.pid}"
101511a
GLOBUS_GATEKEEPER_PORT="${GLOBUS_GATEKEEPER_PORT:-2119}"
101511a
101511a
start() {
101511a
    status > /dev/null
101511a
    rc=$?
101511a
101511a
    if [ $rc -eq 0 ]; then
101511a
        echo "$progname is already running"
101511a
        return 0
101511a
    fi
101511a
101511a
    cert="${GLOBUS_GATEKEEPER_CERT_FILE:-/etc/grid-security/hostcert.pem}"
101511a
    if [ ! -f $cert ]; then
101511a
        echo "Error: Gatekeeper's certificate file ($cert) is missing."
101511a
        echo "Failed to start globus-gatekeeper"
101511a
        exit 6
101511a
    fi
101511a
101511a
    key="${GLOBUS_GATEKEEPER_KEY_FILE:-/etc/grid-security/hostkey.pem}"
101511a
    if [ ! -f $key ]; then
101511a
        echo "Error: Gatekeeper's private key file is ($key) is missing."
101511a
        echo "Failed to start globus-gatekeeper"
101511a
        exit 6
101511a
    fi
101511a
101511a
    if [ "${GLOBUS_GATEKEEPER_KERBEROS_ENABLED:-false}" = "true" ]; then
101511a
        kflag="-k"
101511a
    else
101511a
        kflag=""
101511a
    fi
101511a
101511a
    ${GLOBUS_GATEKEEPER_NICE_LEVEL:+nice -n "${GLOBUS_GATEKEEPER_NICE_LEVEL}"} \
101511a
    ${prog} \
101511a
        -pidfile "${GLOBUS_GATEKEEPER_PIDFILE}" \
101511a
        ${GLOBUS_GATEKEEPER_LOG_FACILITY:+-lf "$GLOBUS_GATEKEEPER_LOG_FACILITY"} \
101511a
        ${GLOBUS_GATEKEEPER_PORT:+-p "${GLOBUS_GATEKEEPER_PORT}"} \
101511a
        ${GLOBUS_GATEKEEPER_LOG:+-l "${GLOBUS_GATEKEEPER_LOG}"} \
101511a
        ${GLOBUS_GATEKEEPER_GRID_SERVICES:+-grid_services "${GLOBUS_GATEKEEPER_GRID_SERVICES}"} \
101511a
        ${GLOBUS_GATEKEEPER_GRIDMAP:+-gridmap "${GLOBUS_GATEKEEPER_GRIDMAP}"} \
101511a
        ${GLOBUS_GATEKEEPER_CERT_DIR:+-x509_cert_dir "${GLOBUS_GATEKEEPER_CERT_DIR}"} \
101511a
        ${GLOBUS_GATEKEEPER_CERT_FILE:+-x509_user_cert "${GLOBUS_GATEKEEPER_CERT_FILE}"} \
101511a
        ${GLOBUS_GATEKEEPER_KEY_FILE:+-x509_user_key "${GLOBUS_GATEKEEPER_KEY_FILE}"} \
101511a
        $kflag \
101511a
        ${GLOBUS_GATEKEEPER_KMAP:+-globuskmap "${GLOBUS_GATEKEEPER_KMAP}"} \
101511a
        > /dev/null
101511a
    rc=$?
101511a
101511a
    if [ "$rc" = 0 ]; then
101511a
        echo "Started globus-gatekeeper"
101511a
        touch "$lockfile"
101511a
    else
101511a
        echo "Failed to start globus-gatekeeper"
101511a
    fi
101511a
101511a
    return $rc;
101511a
}
101511a
101511a
stop() {
101511a
    if test -f "${GLOBUS_GATEKEEPER_PIDFILE}"; then
101511a
        read pid < "${GLOBUS_GATEKEEPER_PIDFILE}" 2> /dev/null
101511a
        if [ "$pid" -gt 0 ] 2> /dev/null; then
101511a
            if kill -0 "${pid}" 2> /dev/null; then
101511a
                kill -TERM "${pid}"
101511a
101511a
                if sleep 1 && kill -0 "${pid}" 2> /dev/null && sleep 3 && kill -0 "${pid}" 2> /dev/null;then
101511a
                    kill -KILL "${pid}"
101511a
                fi
101511a
101511a
                if kill -0 "${pid}" 2> /dev/null; then
101511a
                    echo "Failed to stop globus-gatekeeper"
101511a
                    return 1
101511a
                else
101511a
                    echo "Stopped globus-gatekeeper"
101511a
                fi
101511a
101511a
            fi
101511a
        fi
101511a
        rm -f "${GLOBUS_GATEKEEPER_PIDFILE}"
101511a
        rm -f "$lockfile"
101511a
    else
101511a
        echo "$progname is not running"
101511a
        return 0
101511a
    fi
101511a
}
101511a
101511a
restart() {
101511a
    stop
101511a
    start
101511a
}
101511a
101511a
status() {
101511a
    if test -f "${GLOBUS_GATEKEEPER_PIDFILE}"; then
101511a
        read pid <"${GLOBUS_GATEKEEPER_PIDFILE}" 2>/dev/null
101511a
        if [ "$pid" -gt 0 ] 2> /dev/null; then
101511a
            if ps -p "$pid" > /dev/null; then
101511a
                echo "globus-gatekeeper is running (pid=$pid)"
101511a
                return 0
101511a
            else
101511a
                echo "Stale PID file for globus-gatekeeper"
101511a
                return 1
101511a
            fi
101511a
        fi
101511a
    elif test -f "${lockfile}"; then
101511a
        echo "Stale lock file for globus-gatekeeper"
101511a
        return 2
101511a
    else
101511a
        echo "globus-gatekeeper is not running"
101511a
        return 3
101511a
    fi
101511a
}
101511a
101511a
case "$1" in
101511a
    start)
101511a
        start
101511a
        ;;
101511a
101511a
    stop)
101511a
        stop
101511a
        ;;
101511a
101511a
    restart)
101511a
        restart
101511a
        ;;
101511a
101511a
    reload)
101511a
        exit 0
101511a
        ;;
101511a
101511a
    force-reload)
101511a
        restart
101511a
        ;;
101511a
    status)
101511a
        status
101511a
        ;;
101511a
    condrestart|try-restart)
101511a
        status || exit 0
101511a
        restart
101511a
        ;;
101511a
    *)
101511a
        echo "Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
101511a
        exit 2
101511a
esac