source: TI12-security/trunk/python/share/ndg-log @ 1300

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/python/share/ndg-log@1300
Revision 1300, 4.6 KB checked in by pjkersha, 15 years ago (diff)

Tests/SecurityClientTest?.py: change test defaults
share/ndg-*: clean up tab indents
www/cgi-bin/security.py: updated from cgi-bin test versions used in alpha tests.
NDG/SecurityCGI.py: modified some method names to include '_' prefix to highlight that they're not part of the
external interface.

NDG/SecurityClient.py: include explicit catch for HTTPResponse exception from ZSI ServiceProxy? - this error
is normally related to WSDL URI not found.

  • Property svn:executable set to *
Line 
1#!/bin/bash
2#
3# SysV init script for NDG Security Logging Service
4#
5# P J Kershaw
6#
7# 13/06/06
8#
9# Copyright (C) 2006 CCLRC & NERC
10#
11# This software may be distributed under the terms of the Q Public License,
12# version 1.0 or later.
13#
14# chkconfig: 2345 99 01
15# description: NERC Data Grid Security Logging Web Service
16#
17
18# Edit these variables as required
19user="globus"
20ndgSetupFilePath="/usr/local/NDG/ndgSetup.sh"
21
22# Command line args e.g. set alternative port number or log file
23# path.  Note security consideration that these args will appear in a ps
24# process listing
25args=
26
27# Source function library.
28. /etc/rc.d/init.d/functions
29
30serviceName=${0##*/}
31prog=LogServer.py
32RETVAL=0
33
34
35start()
36{
37    echo -n "Starting ${serviceName}: "
38
39    # Source NDG Environment
40    if [ -f ${ndgSetupFilePath} ]; then
41         . ${ndgSetupFilePath}
42    else
43        failure $"Set-up of NDG environment"
44        return
45    fi
46   
47    cmd="${NDG_DIR}/bin/${prog} ${args}"
48   
49    # See if it's already running. Look *only* at the pid file.
50    local pid=
51    if [ -f /var/run/${serviceName}.pid ]; then
52        local line p
53        read line < /var/run/${serviceName}.pid
54        for p in $line ; do
55            [ -z "${p//[0-9]/}" -a -d "/proc/$p" ] && pid="$pid $p"
56        done
57    fi
58
59    [ -n "${pid:-}" ] && return
60
61    # Make sure it doesn't core dump anywhere; while this could mask
62    # problems with the daemon, it also closes some security problems
63    ulimit -S -c 0 >/dev/null 2>&1
64
65    # Echo daemon
66    [ "${BOOTUP:-}" = "verbose" -a -z "$LSB" ] && echo -n " ${serviceName}"
67
68    # And start it up.
69    initlog $INITLOG_ARGS -c "su - ${user} -c \"${cmd}\""
70    RETVAL=$?
71   
72    if [ $RETVAL = 0 ]; then
73        # Get the process ID
74        pid=(`ps --no-headers -u ${user} -o pid,cmd --sort=-pid|grep "$prog"`)
75        echo ${pid} > /var/run/${serviceName}.pid
76        touch /var/lock/subsys/${serviceName}       
77        success $"${serviceName} startup"
78    else
79        failure $"${serviceName} startup"
80    fi
81   
82    echo
83}
84
85
86stop()
87{
88    echo -n "Shutting down ${serviceName}: "
89   
90    # Find pid
91    pid=
92    if [ -f /var/run/${serviceName}.pid ]; then
93        local line p
94        read line < /var/run/${serviceName}.pid
95        for p in $line ; do
96            [ -z "${p//[0-9]/}" -a -d "/proc/$p" ] && pid="$pid $p"
97        done
98    fi
99
100    if [ -z "$pid" ]; then
101        failure $"${serviceName} stop - no process found from PID file"
102        return
103    fi
104
105    # Kill it.
106    if [ -n "${pid:-}" ] ; then
107        [ "$BOOTUP" = "verbose" -a -z "$LSB" ] && echo -n "${serviceName} "
108           
109        if checkpid $pid 2>&1; then
110            # TERM first, then KILL if not dead
111            kill -TERM $pid
112            usleep 100000
113            if checkpid $pid && sleep 1 &&
114               checkpid $pid && sleep 3 &&
115               checkpid $pid ; then
116                kill -KILL $pid
117                usleep 100000
118               fi
119            checkpid $pid
120            RC=$?
121            [ "$RC" -eq 0 ] && failure $"${serviceName} shutdown" || \
122                success $"${serviceName} shutdown"
123            RC=$((! $RC))
124        fi   
125    else
126        failure $"${serviceName} shutdown"
127        RC=1
128    fi
129
130    # Remove pid file if any.
131    rm -f /var/run/${serviceName}.pid
132
133    echo
134}
135
136
137restart()
138{
139    stop
140    start
141}
142
143
144status()
145{
146    local pid=
147    local pidFilePath=/var/run/${serviceName}.pid
148   
149    # Get pid from "/var/run/*.pid" file
150    if [ -f $pidFilePath ] ; then
151        read pid < $pidFilePath
152        if [ -z "$pid" ]; then
153            echo $"Can't get pid from pid file $pidFilePath"
154            return
155        fi
156    else
157        echo $"No pid file $pidFilePath found"
158        return
159    fi
160
161    # look for pid in listing
162    local pidFound=
163    for i in `pidof -o $$ -o $PPID -o %PPID -x "python"`; do
164         [[ $i = $pid ]] && pidFound=Yes && break;
165    done
166   
167    if [ -n "$pidFound" ]; then
168        echo $"$prog (pid $pid) is running..."
169        return
170       
171    elif [ -f /var/lock/subsys/${serviceName} ]; then
172        echo $"$prog dead but subsys locked and pid file $pidFilePath exists"
173        return
174    else
175        echo $"$prog dead but pid file $pidFilePath exists"   
176    fi
177}
178
179
180case "$1" in
181    start)
182        start
183    ;;
184    stop)
185        stop
186    ;;
187    status)
188        # Use status defined in functions file
189        status
190    ;;
191    restart)
192        restart ${serviceName}
193    ;;
194    condrestart)
195    if [ -f /var/run/${serviceName}.pid ] ; then
196        stop
197        start
198    fi
199    ;;
200    *)
201        echo \
202        "Usage: ${serviceName} {start|stop|restart|condrestart|status}"
203        exit 1
204    ;;
205esac
Note: See TracBrowser for help on using the repository browser.