3
# vi:si:et:sw=4:sts=4:ts=4
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
13
# Short-Description: Start and stop 389 Directory Admin Server
14
# Description: dirsrv is the Admin server for 389 LDAP Directory
17
PATH=/sbin:/bin:/usr/sbin:/usr/bin
18
test -f /etc/default/dirsrv-admin && . /etc/default/dirsrv-admin
20
. /lib/lsb/init-functions
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"
27
PIDDIR="/var/run/dirsrv-admin"
28
ADMCONF="$CONFIG_DIR/admin-serv/adm.conf"
31
if [ -z "$(/sbin/ifconfig)" ]; then
32
log_action_msg "No networks configured."
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()
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
54
if [ $rc -eq 0 ]; then
57
log_failure_msg "$piddir is not writable for $owner"
63
owner=`grep \^nsslapd-localuser $1/dse.ldif | awk '{print $2}'`
64
if [ -n "$owner" ] ; then
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}'`
77
piddir="/var/run/dirsrv"
79
pidfile=$piddir/admin-serv.pid
81
[ -f $exec ] || exit 0
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
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
96
#[ -f /etc/default/dirsrv-admin ] && . /etc/default/dirsrv-admin
99
if [ ! -f $start_script ]; then
100
log_failure_msg "*** Error: $start_script does not exist"
103
echo "Starting $prog: "
105
# the server creates pidfile and writes the pid to it when it is fully
106
# started and available to serve clients
108
if [ -f $pidfile ]; then
110
if kill -0 $pid > /dev/null 2>&1 ; then
111
log_success_msg " already running"
114
log_warning_msg " not running, but pid file exists - attempt to start anyway..."
119
if [ $server_running -eq 0 ] ; then
121
fix_pid_dir_ownership
123
if [ $? -eq 0 ]; then
124
server_started=1 # well, perhaps not running, but started ok
129
if [ $server_started -eq 1 ] ; then
131
# wait for 10 minutes (600 times 1 seconds)
133
while test $loop_counter -le $max_count ; do
134
loop_counter=`expr $loop_counter + 1`
135
if test ! -f $pidfile ; then
142
if kill -0 $pid > /dev/null 2>&1 && test -f $pidfile ; then
143
log_success_msg " success"
145
log_failure_msg "*** Error: $prog failed to start"
151
if [ ! -f $stop_script ]; then
152
log_failure_msg "$stop_script does not exist"
155
echo "Shutting down $prog: "
156
if [ -f $pidfile ]; then
159
if kill -0 $pid > /dev/null 2>&1 ; then
161
if [ $? -eq 0 ]; then
167
if [ $server_stopped -eq 1 ] ; then
169
# wait for 10 minutes (600 times 1 second)
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
176
if test -f $pidfile ; then
182
if test -f $pidfile ; then
183
log_failure_msg "*** Error: $prog failed to stop"
185
log_success_msg " success"
199
if [ -f $pidfile ]; then
201
if kill -0 $pid > /dev/null 2>&1 ; then
202
log_daemon_msg "$prog (pid $pid) is running..." "dirsrv-admin"
204
log_daemon_msg "$prog dead but pid file exists" "dirsrv-admin"
207
echo "$prog is stopped"
212
start|stop|restart|reload|status|force-reload)
216
[ ! -f $lockfile ] || restart
219
echo Unknown command $1
220
echo "Usage: $0 {start|stop|status|restart|condrestart}"