~zulcss/ubuntu/lucid/likewise-open/likewise-open-sru

« back to all changes in this revision

Viewing changes to packaging/debian/likewise-open.init

  • Committer: Bazaar Package Importer
  • Author(s): Rick Clark
  • Date: 2008-08-27 08:56:20 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20080827085620-5q0f58b9qtog9myq
Tags: 4.1.0.2956-0ubuntu1
* missing-likewise-logo.diff: removed
* fixed copyright notice
* updated Standards-Version to 3.8.0
* removed path from command in prerm
* removed stop in S runlevel

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#! /bin/sh
2
 
# ex: set tabstop=4 expandtab shiftwidth=4:
3
 
#
4
 
# Copyright (c) Centeris Corporation 2006
5
 
# Author: Gerald Carter <jerry@centeris.com>
6
 
#
7
 
# /etc/init.d/likewise-open
8
 
#
9
 
#LWI_STARTUP_TYPE_REDHAT###
10
 
#LWI_STARTUP_TYPE_REDHAT# chkconfig: 35 90 10
11
 
#LWI_STARTUP_TYPE_REDHAT# description: Start and Stop the Centeris Likewise Identity Auth Daemon
12
 
#LWI_STARTUP_TYPE_REDHAT###
13
 
#LWI_STARTUP_TYPE_SUSE#
14
 
#LWI_STARTUP_TYPE_SUSE### BEGIN INIT INFO
15
 
#LWI_STARTUP_TYPE_SUSE# Provides: likewise-open
16
 
#LWI_STARTUP_TYPE_SUSE# Required-Start: $network $remote_fs
17
 
#LWI_STARTUP_TYPE_SUSE# Required-Stop: $network $remote_fs centeris.com-gpagentd
18
 
#LWI_STARTUP_TYPE_SUSE# Default-Start: 3 5
19
 
#LWI_STARTUP_TYPE_SUSE# Default-Stop: 0 1 2 6
20
 
#LWI_STARTUP_TYPE_SUSE# Description: Start the Centeris Likewise Identity Auth Daemon
21
 
#LWI_STARTUP_TYPE_SUSE### END INIT INFO
22
 
 
23
 
CONF=/etc/samba/lwiauthd.conf
24
 
CENTERIS_PREFIX=/usr
25
 
AUTHD_BIN=${CENTERIS_PREFIX}/sbin/likewise-winbindd
26
 
PIDFILE=/var/run/likewise-winbindd.pid
27
 
SCRIPTNAME="likewise-open"
28
 
 
29
 
## Have to set the path for HP-UX boot process
30
 
PATH=/sbin:/usr/sbin:/bin:/usr/bin:$PATH
31
 
export PATH
32
 
 
33
 
if [ ! -f ${CONF} ]; then
34
 
    echo "Missing ${CONF}"
35
 
    exit 1
36
 
fi
37
 
 
38
 
PROG_BIN="${AUTHD_BIN}"
39
 
 
40
 
if [ ! -x ${AUTHD_BIN} ]; then
41
 
    echo "Missing ${AUTHD_BIN}"
42
 
    exit 1
43
 
fi
44
 
 
45
 
##
46
 
## Determine what platform we are on
47
 
##
48
 
PLATFORM=""
49
 
if [ -f /etc/init.d/functions ]; then
50
 
    . /etc/init.d/functions
51
 
    PLATFORM="REDHAT"
52
 
elif [ -f /etc/rc.status ]; then
53
 
    . /etc/rc.status
54
 
    PLATFORM="SUSE"
55
 
elif [ -f /etc/debian_version ]; then
56
 
    . /lib/lsb/init-functions
57
 
    PLATFORM="DEBIAN"
58
 
elif [ `uname -s` = 'AIX' ]; then
59
 
    PLATFORM="AIX"
60
 
elif [ `uname -s` = 'HP-UX' ]; then
61
 
    PLATFORM="HP-UX"
62
 
else
63
 
    PLATFORM="UNKNOWN"
64
 
fi
65
 
 
66
 
if [ $PLATFORM = "HP-UX" ]; then
67
 
    LOCKFILE="/var/run/${SCRIPTNAME}.lock"
68
 
else
69
 
    LOCKFILE="/var/lock/subsys/${SCRIPTNAME}"
70
 
fi
71
 
 
72
 
if ! type printf 1>/dev/null 2>/dev/null; then
73
 
    # Usually printf is a shell built in, but on HPUX it is a program located
74
 
    # at /bin/printf. During system startup and shutdown the path is only
75
 
    # /sbin, so we need to manually find printf
76
 
    if [ -x /bin/printf ]; then
77
 
        alias printf=/bin/printf
78
 
    else
79
 
        echo "WARNING: unable to find printf program"
80
 
    fi
81
 
fi
82
 
 
83
 
# echo_replacement emulates echo for all platforms using printf. printf is a
84
 
# shell builtin that exists on all platforms.
85
 
echo_replacement()
86
 
{
87
 
    if [ "$1" = "-n" ]; then
88
 
        shift;
89
 
        printf %s "$*"
90
 
    else
91
 
        printf %s\\n "$*"
92
 
    fi
93
 
}
94
 
 
95
 
# 'echo -n' works with bash, but not with sh on Solaris, HPUX, and AIX.
96
 
if [ "`echo -n`" = "-n" ]; then
97
 
    alias echo=echo_replacement
98
 
fi
99
 
 
100
 
seq_replacement()
101
 
{
102
 
    FIRST=1
103
 
    INCREMENT=1
104
 
    case "$#" in
105
 
        0)
106
 
            echo too few arguments
107
 
            return 1
108
 
            ;;
109
 
        1)
110
 
            LAST="$1"
111
 
            ;;
112
 
        2)
113
 
            FIRST="$1"
114
 
            LAST="$2"
115
 
            ;;
116
 
        3)
117
 
            FIRST="$1"
118
 
            INCREMENT="$2"
119
 
            LAST="$3"
120
 
            ;;
 
2
### BEGIN INIT INFO
 
3
# Provides:          likewise-open
 
4
# Required-Start:    $network $local_fs $remote_fs
 
5
# Required-Stop:     $network $local_fs $remote_fs
 
6
# Default-Start:     2 3 4 5
 
7
# Default-Stop:      S 0 1 6
 
8
# Short-Description: Start likewise-open
 
9
# Description: Start and Stop the Likewise Identity Auth Daemon
 
10
### END INIT INFO
 
11
 
 
12
# Author: Rick Clark <rick.clark@ubuntu.com>
 
13
 
 
14
 
 
15
# PATH should only include /usr/* if it runs after the mountnfs.sh script
 
16
PATH=/usr/sbin:/usr/bin:/sbin:/bin
 
17
 
 
18
DESC="Start and Stop the Likewise Identity Auth Daemon"
 
19
NAME=likewise-winbindd
 
20
DAEMON=/usr/sbin/$NAME
 
21
PIDFILE=/var/run/$NAME.pid
 
22
 
 
23
 
 
24
# Exit if the package is not installed
 
25
[ -x "$DAEMON" ] || exit 0
 
26
 
 
27
# Read configuration variable file if it is present
 
28
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
 
29
 
 
30
# Load the VERBOSE setting and other rcS variables
 
31
[ -f /etc/default/rcS ] && . /etc/default/rcS
 
32
 
 
33
unset TMPDIR
 
34
 
 
35
# Define LSB log_* functions.
 
36
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
 
37
. /lib/lsb/init-functions
 
38
 
 
39
 
 
40
case "$1" in
 
41
        start)
 
42
                log_daemon_msg "Starting the Likewise-open auth daemon"
 
43
                start-stop-daemon --start --quiet --oknodo --exec $DAEMON
 
44
                log_end_msg $?
 
45
                ;;
 
46
 
 
47
        stop)
 
48
                log_daemon_msg "Stopping the Likewise-open auth daemon"
 
49
                start-stop-daemon --stop --quiet --oknodo --exec $DAEMON
 
50
                log_end_msg $?
 
51
                ;;
 
52
       status)
 
53
               pidofproc -p $PIDFILE $DAEMON >/dev/null
 
54
               status=$?
 
55
               if [ $status -eq 0 ]; then
 
56
                       log_success_msg "$NAME is running"
 
57
               else
 
58
                       log_failure_msg "$NAME is not running"
 
59
               fi
 
60
               exit $status
 
61
               ;;
 
62
 
 
63
        restart|force-reload)
 
64
                $0 stop && sleep 2 && $0 start
 
65
                ;;
 
66
 
121
67
        *)
122
 
            echo too many arguments
123
 
            return 1
124
 
            ;;
125
 
    esac
126
 
    let "i = $FIRST"
127
 
    while [ $i -le $LAST ]; do
128
 
        echo $i
129
 
        let "i = i + $INCREMENT"
130
 
    done
131
 
    return 0;
132
 
}
133
 
 
134
 
# seq doesn't exist on HPUX
135
 
if ! type seq 2>/dev/null 1>/dev/null; then
136
 
    alias seq=seq_replacement
137
 
fi
138
 
 
139
 
##
140
 
## small wrapper functions around distro specific calls
141
 
##
142
 
 
143
 
status_success() {
144
 
    case "${PLATFORM}" in 
145
 
        REDHAT)
146
 
            echo_success
147
 
            echo
148
 
            ;;
149
 
        SUSE)
150
 
            rc_reset
151
 
            rc_status -v
152
 
            ;;
153
 
        DEBIAN)
154
 
            ;;
155
 
        AIX | HP-UX | UNKNOWN)
156
 
            echo "...ok"
157
 
            ;;
158
 
    esac
159
 
}
160
 
 
161
 
status_failed() {
162
 
    status=$1
163
 
    case "${PLATFORM}" in 
164
 
        REDHAT)
165
 
            echo_failure
166
 
            echo
167
 
            ;;
168
 
        SUSE)
169
 
            rc_failed $status
170
 
            rc_status -v
171
 
            ;;
172
 
        DEBIAN)
173
 
            ;;
174
 
        AIX | HP-UX | UNKNOWN)
175
 
            echo "...failed"
176
 
            ;;
177
 
    esac
178
 
}
179
 
 
180
 
print_status () {
181
 
    status=$1
182
 
 
183
 
    if [ $status = 0 ]; then
184
 
        status_success
185
 
    else
186
 
        status_failed $status
187
 
    fi
188
 
}
189
 
 
190
 
generic_status()
191
 
{
192
 
    #Uses return codes specified in
193
 
    # http://refspecs.freestandards.org/LSB_3.1.0/LSB-Core-generic/LSB-Core-generic/iniscrptact.html
194
 
    if [ -f "$PIDFILE" ]; then
195
 
        local pid="`cat "${PIDFILE}"`";
196
 
 
197
 
        #Is the pid valid?
198
 
        #Does the program with that pid match our program name?
199
 
        #HP-UX needs UNIX95 set to support the -o option
200
 
        local pid_comm="`UNIX95=1 ps -p $pid -o args= | awk '{print $1}'`"
201
 
        if [ "$pid_comm" = "<defunct>" ]; then
202
 
            #It is a zombie process
203
 
            return 4
204
 
        fi
205
 
        if [ "$pid_comm" = "${PROG_BIN}" ]; then
206
 
            #If the system keeps cmdline files, check it
207
 
            if [ -e /proc/${pid}/cmdline ]; then
208
 
                #We can't check the exe file because we may be looking
209
 
                #at a version of the program that has been overwritten
210
 
                grep -q ${PROG_BIN} /proc/${pid}/cmdline && return 0
211
 
            else
212
 
                return 0
213
 
            fi
214
 
        fi
215
 
 
216
 
        #Program is dead, but lock file exists
217
 
        [ -f "${LOCKFILE}" ] && return 2
218
 
 
219
 
        #Program is dead, but pid file exists
220
 
        return 1
221
 
    fi
222
 
 
223
 
    #Program is not running
224
 
    return 3
225
 
}
226
 
 
227
 
daemon_start() {
228
 
    case "${PLATFORM}" in 
229
 
        REDHAT)
230
 
            echo -n $"Starting `basename ${AUTHD_BIN}`: "
231
 
            daemon ${AUTHD_BIN}
232
 
            status=$?
233
 
            ;;
234
 
        SUSE)
235
 
            echo -n "Starting Centeris Authentication Services"
236
 
            startproc ${AUTHD_BIN}
237
 
            status=$?
238
 
            ;;
239
 
        DEBIAN)
240
 
            log_daemon_msg "Starting Likewise Open Authentication Services" "likewise-open"
241
 
            start-stop-daemon --start --exec ${AUTHD_BIN}
242
 
            status=$?
243
 
            log_end_msg $status
244
 
            sleep 1
245
 
            ;;
246
 
        AIX)
247
 
            echo -n "Starting Centeris Authentication Services"
248
 
            if (lssrc -s dhcpcd | grep active >/dev/null); then
249
 
                # Wait up to 30 seconds for an ip address
250
 
                for i in `seq 30`; do
251
 
                    ifconfig -a | grep inet | grep -v 127.0.0 | grep -v 0.0.0.0 | grep -v ::1/0 >/dev/null && break
252
 
                    sleep 1
253
 
                done
254
 
            fi
255
 
            ${AUTHD_BIN}
256
 
            status=$?
257
 
            if [ $status -eq 0 ]; then
258
 
                status=1
259
 
                for i in `seq 5`; do
260
 
                    #Did the program start?
261
 
                    generic_status
262
 
                    status=$?
263
 
                    [ $status -eq 0 ] && break
264
 
                    sleep 1
265
 
                done
266
 
            fi
267
 
            if [ $status -eq 0 ]; then
268
 
                #This command will wait for likewise-winbindd to initialize before
269
 
                #returning
270
 
                #Ignore the exit code incase we aren't joined to a domain
271
 
                $CENTERIS_PREFIX/bin/lwiinfo -D `$CENTERIS_PREFIX/bin/lwiinfo --own-domain` 1>/dev/null 2>/dev/null
272
 
            fi
273
 
            ;;
274
 
        HP-UX)
275
 
            echo -n "Starting Centeris Authentication Services"
276
 
            ${AUTHD_BIN}
277
 
            status=$?
278
 
            if [ $status -eq 0 ]; then
279
 
                status=1
280
 
                for i in `seq 5`; do
281
 
                    #Did the program start?
282
 
                    generic_status
283
 
                    status=$?
284
 
                    [ $status -eq 0 ] && break
285
 
                    sleep 1
286
 
                done
287
 
            fi
288
 
            ;;
289
 
        UNKNOWN)
290
 
            ${AUTHD_BIN}
291
 
            status=$?
292
 
            ;;
293
 
    esac
294
 
 
295
 
    [ $status = 0 ] && [ ${PLATFORM} != "DEBIAN" ] && touch ${LOCKFILE}
296
 
    return $status
297
 
}
298
 
 
299
 
daemon_stop() {
300
 
    case "${PLATFORM}" in 
301
 
        REDHAT)
302
 
            echo -n $"Stopping `basename ${AUTHD_BIN}`: "
303
 
            killproc `basename ${AUTHD_BIN}`
304
 
            status=$?
305
 
            ;;
306
 
        SUSE)
307
 
            echo -n "Stopping Centeris Authentication Services"
308
 
            killproc -TERM ${AUTHD_BIN}
309
 
            status=$?
310
 
            ;;
311
 
        DEBIAN)
312
 
            log_daemon_msg "Stopping Likewise Open Authentication Services"
313
 
            status=1
314
 
            #only try to stop the daemon if it is running
315
 
            if generic_status; then
316
 
                kill -TERM "`cat "${PIDFILE}"`"
317
 
 
318
 
                #Wait up to 5 seconds for the program to end
319
 
                for i in `seq 5`; do
320
 
                    #Did the program end?
321
 
                    generic_status
322
 
                    [ $? -ne 0 -a $? -ne 4 ] && status=0 && break
323
 
                    # use the following line instead after bug 3634 is fixed
324
 
                    #[ $? -eq 3 -o $? -eq 2 ] && status=0 && break
325
 
                    sleep 1
326
 
                done
327
 
            fi
328
 
            log_end_msg $status
329
 
            ;;
330
 
        AIX | HP-UX)
331
 
            echo -n "Stopping Centeris Authentication Services"
332
 
            status=1
333
 
            #only try to stop the daemon if it is running
334
 
            if generic_status; then
335
 
                pid="`cat "${PIDFILE}"`"
336
 
                kill -TERM $pid
337
 
 
338
 
                #Wait up to 5 seconds for the program to end
339
 
                for i in `seq 5`; do
340
 
                    #Did the program end?
341
 
                    generic_status
342
 
                    [ $? -ne 0 -a $? -ne 4 ] && status=0 && break
343
 
                    # use the following line instead after bug 3634 is fixed
344
 
                    #[ $? -eq 3 -o $? -eq 2 ] && status=0 && break
345
 
                    sleep 1
346
 
                done
347
 
            fi
348
 
            ;;
349
 
        UNKNOWN)
350
 
            killall -TERM `basename ${AUTHD_BIN}`
351
 
            status=$?
352
 
            ;;
353
 
    esac
354
 
 
355
 
    [ $status = 0 ] && rm -f ${LOCKFILE}
356
 
    return $status
357
 
}
358
 
 
359
 
daemon_status() {
360
 
    case "${PLATFORM}" in
361
 
        REDHAT)
362
 
        status ${AUTHD_BIN}
363
 
        ;;
364
 
        SUSE)
365
 
        checkproc ${AUTHD_BIN}
366
 
        rc_status -v
367
 
        ;;
368
 
        DEBIAN)
369
 
        #After the AIX functions are found safe, we should use them here
370
 
        status="1";
371
 
        if [ -e ${PIDFILE} ]; then
372
 
            pid=`cat ${PIDFILE}`
373
 
            if [ -e /proc/${pid}/cmdline ]; then
374
 
            grep -q ${AUTHD_BIN} /proc/${pid}/cmdline
375
 
            if [ $? = 0 ]; then
376
 
                status="0"
377
 
            fi
378
 
            fi
379
 
        fi
380
 
        if [ $status = 0 ]; then
381
 
            echo "running";
382
 
        else
383
 
            echo "stopped"
384
 
        fi
385
 
        return $status
386
 
        ;;
387
 
        AIX | HP-UX)
388
 
            generic_status
389
 
            status=$?
390
 
            case "$status" in
391
 
                0)
392
 
                    echo "running";
393
 
                    ;;
394
 
                1)
395
 
                    echo "stopped";
396
 
                    #Use the bellow line instead after bug 3634 is fixed
397
 
                    #echo "died leaving pid file";
398
 
                    ;;
399
 
                2)
400
 
                    echo "died leaving lock file";
401
 
                    ;;
402
 
                3)
403
 
                    echo "stopped";
404
 
                    ;;
405
 
            esac
406
 
            return $status
407
 
        ;;
408
 
        UNKNOWN)
409
 
        echo "Not implemented."
410
 
        ;;
411
 
    esac
412
 
}
413
 
 
414
 
#Sends the signal specified by the first parameter to all instances
415
 
#of $PROG_BIN
416
 
generic_killall()
417
 
{
418
 
    #This gets the list of all current running instances of PROG_BIN,
419
 
    #but it can't tell which directory the program was run from. If
420
 
    #cmdline is available in the proc pseudo-filesystem, we'll verify
421
 
    #the pids.
422
 
    local unverified_pids=`UNIX95=1 ps -e -o pid,args= | grep "${PROG_BIN}" | awk '{print $1}'`
423
 
    local pids=
424
 
    for pid in $unverified_pids; do
425
 
        #If the system keeps cmdline files, check them
426
 
        if [ -e /proc/${pid}/cmdline ]; then
427
 
            #We can't check the exe file because we may be looking
428
 
            #at a version of the program that has been overwritten
429
 
            grep -q ${AUTHD_BIN} /proc/${pid}/cmdline && pids="$pids $pid"
430
 
        else
431
 
            pids="$pids $pid"
432
 
        fi
433
 
    done
434
 
 
435
 
    for pid in $pids; do
436
 
        [ ! -z "`UNIX95=1 ps -p $pid -o pid=`" ] && kill "$1" $pid
437
 
    done
438
 
 
439
 
    #The manpage of killall says it returns 0 if at least one process is
440
 
    #killed. I can't get it to return anything other than 0. Even if no
441
 
    #processes die with SIGTERM. We'll just return 0 here too
442
 
    return 0
443
 
}
444
 
 
445
 
####################################################################
446
 
## Main init script code
447
 
##
448
 
 
449
 
case "$1" in 
450
 
    start)
451
 
        daemon_start
452
 
        ret=$?
453
 
        print_status $ret
454
 
        ;;
455
 
 
456
 
    stop)
457
 
        daemon_stop
458
 
        ret=$?
459
 
        print_status $ret
460
 
        ;;
461
 
 
462
 
    # HP-UX calls this
463
 
    stop_msg)
464
 
        echo "Stopping Centeris Authentication Services"
465
 
        exit 0
466
 
        ;;
467
 
 
468
 
    # HP-UX calls this
469
 
    start_msg)
470
 
        echo "Starting Centeris Authentication Services"
471
 
        exit 0
472
 
        ;;
473
 
 
474
 
    restart)
475
 
        daemon_stop
476
 
        ret=$?
477
 
        print_status $ret
478
 
        # Start can't follow a stop too closely on Debian...
479
 
        if [ ${PLATFORM} = "DEBIAN" ]; then
480
 
            sleep 1
481
 
        fi
482
 
        daemon_start
483
 
        ret=$?
484
 
        print_status $ret
485
 
        ;;
486
 
        
487
 
    status)
488
 
        daemon_status
489
 
        ;;
490
 
 
491
 
    force-reload)
492
 
        daemon_stop
493
 
        ret=$?
494
 
        print_status $ret
495
 
        # Start can't follow a stop too closely on Debian...
496
 
        if [ ${PLATFORM} = "DEBIAN" ]; then
497
 
            sleep 1
498
 
        fi
499
 
        daemon_start
500
 
        ret=$?
501
 
        print_status $ret
502
 
        ;;
503
 
 
504
 
    reload)
505
 
        echo -n "Reloading Centeris Authentication configuration file"
506
 
        if [ ${PLATFORM} = "AIX" ] || [ ${PLATFORM} = "HP-UX" ]; then
507
 
            #killall on AIX cannot search for a program name. We have to use
508
 
            #our own
509
 
            generic_killall -HUP
510
 
        else
511
 
            killall -HUP `basename ${AUTHD_BIN}`
512
 
        fi
513
 
        ret=$?
514
 
        print_status $ret
515
 
        ;;
516
 
 
517
 
    *)
518
 
        echo "Usage: $0 {start|stop|restart|status|reload|force-reload}"
519
 
        exit 1
520
 
        ;;
 
68
                echo "Usage: $0 {start|stop|status|restart|force-reload}"
 
69
                exit 1
 
70
                ;;
521
71
esac
522
 
 
523
 
 
524
 
## end of script
525
 
####################################################################