~upstart-devel/upstart/upstart-jobs

« back to all changes in this revision

Viewing changes to utopic/etc/init.d/dirsrv-admin

  • Committer: Dimitri John Ledkov
  • Date: 2014-11-19 12:58:41 UTC
  • Revision ID: dimitri.j.ledkov@intel.com-20141119125841-98dr37roy8dvcv3b
auto update

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/sh
2
 
# -*- Mode: Python -*-
3
 
# vi:si:et:sw=4:sts=4:ts=4
4
 
 
5
 
### BEGIN INIT INFO
6
 
# Provides:          dirsrv-admin
7
 
# Required-Start:    $remote_fs dirsrv
8
 
# Required-Stop:     $remote_fs
9
 
# Should-Start:      $network
10
 
# Should-Stop:       $network
11
 
# Default-Start:     2 3 4 5
12
 
# Default-Stop:      0 1 6
13
 
# Short-Description: Start and stop 389 Directory Admin Server
14
 
# Description:       dirsrv is the Admin server for 389 LDAP Directory
15
 
### END INIT INFO
16
 
 
17
 
PATH=/sbin:/bin:/usr/sbin:/usr/bin
18
 
test -f /etc/default/dirsrv-admin && . /etc/default/dirsrv-admin
19
 
 
20
 
. /lib/lsb/init-functions
21
 
 
22
 
DISTRO=$(lsb_release -is 2>/dev/null || echo Debian)
23
 
CONFIG_DIR="/etc/dirsrv"
24
 
BASEEXEC="start-ds-admin"
25
 
EXEC="/usr/sbin/$BASEEXEC"
26
 
PROG="ds-admin"
27
 
PIDDIR="/var/run/dirsrv-admin"
28
 
ADMCONF="$CONFIG_DIR/admin-serv/adm.conf"
29
 
 
30
 
check_network() {
31
 
    if [ -z "$(/sbin/ifconfig)" ]; then
32
 
        log_action_msg "No networks configured."
33
 
        return 1 
34
 
    fi
35
 
    return 0
36
 
}
37
 
 
38
 
 
39
 
# On Solaris /var/run is in tmpfs and gets wiped out upon reboot
40
 
# we have to recreate the /var/run/dirsrv-admin directory
41
 
# We also have to make sure that the directory is writable
42
 
# by the directory server process
43
 
# the argument to this function is the server instance directory,
44
 
# which must have a dse.ldif file in it
45
 
fix_pid_dir_ownership()
46
 
{
47
 
    if [ -d $piddir ] ; then
48
 
        owner=`grep \^sysuser "$ADMCONF" | awk '{print $2}'`
49
 
        dirowner=`ls -ld $piddir | awk '{print $3}'`
50
 
        dirgrp=`ls -ld $piddir | awk '{print $4}'`
51
 
        if [ "$owner" != "$dirowner" ]; then
52
 
            groups $owner | grep $dirgrp > /dev/null 2>&1
53
 
            rc=$?
54
 
            if [ $rc -eq 0 ]; then
55
 
                chmod 770 $piddir
56
 
            else
57
 
                log_failure_msg "$piddir is not writable for $owner"
58
 
                exit 1
59
 
            fi
60
 
        fi
61
 
    else
62
 
        mkdir -p $piddir
63
 
        owner=`grep \^nsslapd-localuser $1/dse.ldif | awk '{print $2}'`
64
 
        if [ -n "$owner" ] ; then
65
 
            chown $owner $piddir
66
 
            chmod 700 $piddir
67
 
        fi
68
 
    fi
69
 
}
70
 
 
71
 
start_script=/usr/sbin/start-ds-admin
72
 
restart_script=/usr/sbin/restart-ds-admin
73
 
stop_script=/usr/sbin/stop-ds-admin
74
 
exec=`grep "^HTTPD=" $start_script | awk -F= '{print $2}'`
75
 
prog="dirsrv-admin"
76
 
# PID directory
77
 
piddir="/var/run/dirsrv"
78
 
# PID file
79
 
pidfile=$piddir/admin-serv.pid
80
 
 
81
 
[ -f $exec ] || exit 0
82
 
 
83
 
if [ ! -f "$ADMCONF" ]; then
84
 
    log_action_msg "No $ADMCONF file is present"
85
 
    # Quit without failing since the server is not configured yet
86
 
    exit 0 
87
 
fi
88
 
 
89
 
 
90
 
umask 077
91
 
 
92
 
# since we use the start script to start admin, we source the
93
 
# init config file there, not here
94
 
# if we ever get rid of the start script, we'll have to uncomment
95
 
# the following line
96
 
#[ -f /etc/default/dirsrv-admin ] && . /etc/default/dirsrv-admin
97
 
 
98
 
start() {
99
 
    if [ ! -f $start_script ]; then
100
 
        log_failure_msg "*** Error: $start_script does not exist"
101
 
        exit 1
102
 
    fi
103
 
    echo  "Starting $prog: "
104
 
 
105
 
    # the server creates pidfile and writes the pid to it when it is fully
106
 
    # started and available to serve clients
107
 
    server_running=0
108
 
    if [ -f $pidfile ]; then
109
 
        pid=`cat $pidfile`
110
 
        if kill -0 $pid > /dev/null 2>&1 ; then
111
 
            log_success_msg " already running"
112
 
            server_running=1
113
 
        else
114
 
            log_warning_msg " not running, but pid file exists - attempt to start anyway..."
115
 
            rm -f $pidfile
116
 
        fi
117
 
    fi
118
 
    server_started=0
119
 
    if [ $server_running -eq 0 ] ; then
120
 
        rm -f $pidfile
121
 
        fix_pid_dir_ownership 
122
 
        $start_script
123
 
        if [ $? -eq 0 ]; then
124
 
            server_started=1 # well, perhaps not running, but started ok
125
 
        else
126
 
            failure; echo
127
 
        fi
128
 
    fi
129
 
    if [ $server_started -eq 1 ] ; then
130
 
        loop_counter=1
131
 
                # wait for 10 minutes (600 times 1 seconds)
132
 
        max_count=600
133
 
        while test $loop_counter -le $max_count ; do
134
 
            loop_counter=`expr $loop_counter + 1`
135
 
            if test ! -f $pidfile ; then
136
 
                sleep 1
137
 
            else
138
 
                pid=`cat $pidfile`
139
 
                break
140
 
            fi
141
 
        done
142
 
        if kill -0 $pid > /dev/null 2>&1 && test -f $pidfile ; then
143
 
            log_success_msg " success"
144
 
        else
145
 
            log_failure_msg "*** Error: $prog failed to start"
146
 
        fi
147
 
    fi
148
 
}
149
 
 
150
 
stop() {
151
 
    if [ ! -f $stop_script ]; then
152
 
       log_failure_msg "$stop_script does not exist"
153
 
       exit 1
154
 
    fi
155
 
    echo "Shutting down $prog: "
156
 
    if [ -f $pidfile ]; then
157
 
        pid=`cat $pidfile`
158
 
        server_stopped=0
159
 
        if kill -0 $pid > /dev/null 2>&1 ; then
160
 
            kill $pid
161
 
            if [ $? -eq 0 ]; then
162
 
                server_stopped=1
163
 
            else
164
 
                failure; echo
165
 
            fi
166
 
        fi
167
 
        if [ $server_stopped -eq 1 ] ; then
168
 
            loop_counter=1
169
 
                        # wait for 10 minutes (600 times 1 second)
170
 
            max_count=600
171
 
            while test $loop_counter -le $max_count; do
172
 
                loop_counter=`expr $loop_counter + 1`
173
 
                if kill -0 $pid > /dev/null 2>&1 ; then
174
 
                    sleep 1
175
 
                else
176
 
                    if test -f $pidfile ; then
177
 
                        rm -f $pidfile
178
 
                    fi
179
 
                    break
180
 
                fi
181
 
            done
182
 
            if test -f $pidfile ; then
183
 
                log_failure_msg "*** Error: $prog failed to stop"
184
 
            else
185
 
                log_success_msg " success"
186
 
                rm -f $pidfile
187
 
            fi
188
 
        fi
189
 
    fi
190
 
}
191
 
 
192
 
restart() {
193
 
    stop
194
 
    start
195
 
}
196
 
 
197
 
 
198
 
status() {
199
 
    if [ -f $pidfile ]; then
200
 
        pid=`cat $pidfile`
201
 
        if kill -0 $pid > /dev/null 2>&1 ; then
202
 
            log_daemon_msg "$prog (pid $pid) is running..." "dirsrv-admin"
203
 
        else
204
 
            log_daemon_msg "$prog dead but pid file exists" "dirsrv-admin"
205
 
        fi
206
 
    else
207
 
        echo "$prog is stopped"
208
 
    fi
209
 
}
210
 
 
211
 
case "$1" in
212
 
    start|stop|restart|reload|status|force-reload)
213
 
        $1
214
 
        ;;
215
 
    condrestart)
216
 
        [ ! -f $lockfile ] || restart
217
 
        ;;
218
 
    *)
219
 
        echo Unknown command $1
220
 
        echo "Usage: $0 {start|stop|status|restart|condrestart}"
221
 
        exit 2
222
 
esac