summaryrefslogtreecommitdiffstats
path: root/ldap/admin/src/scripts/restart-dirsrv.in
blob: 76fb176dbb5c44b7a4e49ee222646ec1e63634f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/sh

# Script that restarts the ns-slapd server.
# Exit status can be:
#       0: Server restarted successfully
#       1: Server could not be started
#       2: Server started successfully (was not running)
#       3: Server could not be stopped

restart_instance() {
    SERV_ID=$1

    server_already_stopped=0
    @sbindir@/stop-dirsrv -d $initconfig_dir $SERV_ID
    status=$?
    if [ $status -eq 1 ] ; then
        return 3;
    else
       if [ $status -eq 2 ] ; then
            server_already_stopped=1
       fi
    fi
    @sbindir@/start-dirsrv -d $initconfig_dir $SERV_ID
    status=$?
    if [ $server_already_stopped -eq 1 ] && [ $status -eq 0 ] ; then
        return 2;
    fi
    return $status
}

while getopts "d:" flag
do
    case "$flag" in
        d) initconfig_dir="$OPTARG";;
    esac
done
shift $(($OPTIND-1))

if [ "$initconfig_dir" = "" ]; then
    if [ $USER = root ] ; then
        initconfig_dir=@initconfigdir@
    else
        initconfig_dir=$HOME/.@package_name@
    fi
fi

if [ "$#" -eq 0 ]; then
    # We're restarting all instances.
    ret=0
    for i in $initconfig_dir/@package_name@-*; do
        regex=s,$initconfig_dir/@package_name@-,,g
        inst=`echo $i | sed -e $regex`
        echo Restarting instance \"$inst\"
        restart_instance $inst
        if [ "$?" -ne 0 ]; then
            ret=$?
        fi
    done
    exit $ret
else
    # We're restarting a single instance.
    restart_instance $*
    exit $?
fi