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

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