1#! /bin/sh
2#
3# sqlrcachemanager   This starts and stops the SQL Relay cache manager.
4#
5# chkconfig: 345 85 15
6# description: SQL Relay Cache Manager
7#
8### BEGIN INIT INFO
9# Provides:		sqlrcachemanager
10# Required-Start:	$local_fs $remote_fs $network $time
11# Required-Stop:	$local_fs $remote_fs $network $time
12# Should-Start:		$syslog
13# Should-Stop:		$syslog
14# Default-Start:
15# Default-Stop:		0 1 2 3 4 5 6
16# Short-Description:	SQL Relay Cache Manager
17### END INIT INFO
18#
19# PROVIDE: sqlrcachemanager
20# REQUIRE: NETWORKING
21
22
23# define default message functions
24success() {
25    printf success
26}
27failure() {
28    printf failure
29}
30passed() {
31    printf passed
32}
33
34
35# override them with fancier ones if available
36if ( test -r "/etc/init.d/functions" )
37then
38    . /etc/init.d/functions
39else
40    if ( test -r "/etc/rc.d/init.d/functions" )
41    then
42        . /etc/rc.d/init.d/functions
43    fi
44fi
45
46
47# for BSD-ish systems, bail if sqlrcachemanager isn't enabled in /etc/rc.conf
48BSD="no"
49PRINTACTION="yes"
50if ( test -r "/etc/rc.conf" )
51then
52
53    BSD="yes"
54
55    # load subroutines to process /etc/rc.conf
56    . /etc/rc.conf
57
58    UNAME=`uname`
59    if ( test "$UNAME" = "OpenBSD" )
60    then
61
62	PRINTACTION="no"
63
64        # on OpenBSD sqlrcachemanager_flags=NO disables
65        if ( test "${sqlrcachemanager_flags}" = "NO" -o \
66                    "${sqlrcachemanager_flags}" = "No" -o \
67                    "${sqlrcachemanager_flags}" = "no" )
68        then
69            exit 0
70        fi
71
72    elif ( test "$UNAME" = "FreeBSD" )
73    then
74
75        # on FreeBSD sqlrcachemanager_enable=YES enables
76        if ( test "${sqlrcachemanager_enable}" != "YES" -a \
77                    "${sqlrcachemanager_enable}" != "Yes" -a \
78                    "${sqlrcachemanager_enable}" != "yes" )
79        then
80            exit 0
81        fi
82
83    else
84
85        # on NetBSD and Minix (and others) sqlrcachemanager=YES enables
86        if ( test "${sqlrcachemanager}" != "YES" -a \
87                    "${sqlrcachemanager}" != "Yes" -a \
88                    "${sqlrcachemanager}" != "yes" )
89        then
90            exit 0
91        fi
92    fi
93fi
94
95
96# define paths
97prefix=@prefix@
98sysconfdir=@sysconfdir@
99localstatedir=@localstatedir@
100tmpdir=${localstatedir}/sqlrelay/tmp
101
102
103# define lock directory
104lockdir=/tmp
105if ( test -w "/var/lock/subsys" )
106then
107    lockdir=/var/lock/subsys
108elif ( test -w "/var/lock" )
109then
110    lockdir=/var/lock
111fi
112
113
114# Add appropriate bin/lib paths
115if ( test "${prefix}" != "/usr" )
116then
117    PATH=$PATH:${prefix}/bin
118    export PATH
119    LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${prefix}/lib
120    export LD_LIBRARY_PATH
121fi
122
123
124# initialize return value
125RETVAL=0
126
127
128cleanup() {
129    for i in `ls ${tmpdir}/pids/* 2>/dev/null`
130    do
131        if ( test -r "$i" )
132        then
133            PID=`cat $i`
134            if ( test -z "`ps -p $PID 2> /dev/null | grep sqlr-`" )
135            then
136                echo "$PID is not sqlr! removing pidfile ..."
137                rm -f $i
138            fi
139        fi
140    done
141}
142
143start_sqlrcachemanager() {
144
145    # print Starting if necessary
146    if ( test "$BSD" = "yes" -a "$PRINTACTION" = "yes" )
147    then
148        printf "Starting"
149    fi
150
151    # on BSD, print:
152    # sqlrcachemanager
153    #
154    # on non-BSD, print:
155    # Starting sqlrcachemanager: success
156    if ( test "$BSD" = "yes" )
157    then
158        printf " sqlrcachemanager"
159    fi
160
161    sqlr-cachemanager 0<&- 1>&- 2>&-
162    RETVAL=$?
163    if ( test "$BSD" = "no" )
164    then
165        printf "Starting sqlrcachemanager: "
166        if ( test $RETVAL -eq 0 )
167        then
168            success
169        else
170            failure
171        fi
172        echo
173    fi
174
175    if ( test "$BSD" = "yes" -a "$PRINTACTION" = "yes" )
176    then
177        echo "."
178    fi
179
180    if ( test $RETVAL -eq 0 )
181    then
182        touch ${lockdir}/sqlrcachemanager
183    fi
184
185    cleanup
186
187    return $RETVAL
188}
189
190stop_sqlrcachemanager() {
191
192    # print Stopping if necessary
193    if ( test "$BSD" = "yes" -a "$PRINTACTION" = "yes" )
194    then
195        printf "Stopping"
196    fi
197
198    # on BSD, print:
199    # sqlrcachemanager
200    #
201    # on non-BSD, print:
202    # sqlrcachemanager: success
203    if ( test "$BSD" = "yes" )
204    then
205        printf " sqlrcachemanager"
206    fi
207
208    for i in `ls ${tmpdir}/pids/sqlr-cachemanager.* 2>/dev/null`
209    do
210        if ( test -r "$i" )
211        then
212            PID=`cat $i`
213            kill ${PID} 0<&- 1>&- 2>&-
214            RETVAL=$?
215            if ( test "$BSD" = "no" )
216            then
217                printf "Stopping sqlrcachemanager: "
218                if ( test $RETVAL -eq 0 )
219                then
220                    success
221                else
222                    failure
223                fi
224                echo
225            fi
226        fi
227    done
228
229    if ( test "$BSD" = "yes" -a "$PRINTACTION" = "yes" )
230    then
231        echo "."
232    fi
233
234    if ( test $RETVAL -eq 0 )
235    then
236        rm -f ${lockdir}/sqlrcachemanager
237    fi
238
239    cleanup
240
241    return $RETVAL
242}
243
244restart_sqlrcachemanager() {
245    stop_sqlrcachemanager
246    start_sqlrcachemanager
247}
248
249condrestart_sqlrcachemanager() {
250    if ( test -r "${lockdir}/sqlrcachemanager" )
251    then
252        restart_sqlrcachemanager
253    fi
254    return 0
255}
256
257
258# See how we were called.
259case "$1" in
260    start)
261        start_sqlrcachemanager
262        ;;
263    stop)
264        stop_sqlrcachemanager
265        ;;
266    restart)
267        restart_sqlrcachemanager
268        ;;
269    reload)
270        restart_sqlrcachemanager
271        ;;
272    condrestart)
273        condrestart_sqlrcachemanager
274        ;;
275    *)
276        if ( test -r "/etc/rc.subr" -o -r "/etc/rc.d/rc.subr" )
277        then
278            # on BSD systems assume start
279            start_sqlrcachemanager
280        else
281            # on others, print usage
282            echo "Usage: sqlrcachemanager {start|stop|restart|condrestart}"
283            RETVAL=1
284        fi
285esac
286
287exit $RETVAL
288