This file is indexed.

/etc/init.d/dirsrv is in 389-ds-base 1.3.2.16-0ubuntu1.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  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
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#!/bin/sh

### BEGIN INIT INFO
# Provides:          dirsrv
# Required-Start:    $remote_fs
# Required-Stop:     $remote_fs
# Should-Start:      $network
# Should-Stop:       $network
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start and stop 389 Directory Server
# Description:       dirsrv is the 389 LDAP Directory Server
### END INIT INFO

PATH=/sbin:/bin:/usr/sbin:/usr/bin
test -f /etc/default/dirsrv && . /etc/default/dirsrv

. /lib/lsb/init-functions

DISTRO=$(lsb_release -is 2>/dev/null || echo Debian)
CONFDIR="/etc/dirsrv"
BASEEXEC="ns-slapd"
EXEC="/usr/sbin/$BASEEXEC"
PROG="dirsrv"
PIDDIR="/var/run/dirsrv"
LOCKDIR="/var/lock/dirsrv"

check_network() {
    if [ -z "$(/sbin/ifconfig)" ]; then
        log_action_msg "No networks configured."
        return 1 
    fi
    return 0
}

fix_pid_dir_ownership()
{
    if [ ! -d $PIDDIR ] ; then
        mkdir -p $PIDDIR
        owner=`grep \^nsslapd-localuser $1/dse.ldif | awk '{print $2}'`
        if [ -n "$owner" ] ; then
            chown $owner $PIDDIR 2>&1 > /dev/null
            chmod 700 $PIDDIR 2>&1 > /dev/null
        fi
    fi
}

fix_lock_dir_ownership()
{
    if [ ! -d $LOCKDIR/slapd-$2 ] ; then
        mkdir -p $LOCKDIR/slapd-$2
        owner=`grep \^nsslapd-localuser $1/dse.ldif | awk '{print $2}'`
        if [ -n "$owner" ] ; then
            chown -R $owner $LOCKDIR/slapd-$2 2>&1 > /dev/null
            chmod -R 700 $LOCKDIR/slapd-$2 2>&1 > /dev/null
        fi
    fi
}

INSTANCES=""

# Ignore instances that have been removed
for FILE in `/bin/ls -d $CONFDIR/slapd-* 2>/dev/null | sed -n '/\.removed$/!p'`; do
    if [ -d "$FILE" ] ; then
        inst=`echo "$FILE" | sed -e "s|$CONFDIR/slapd-||"`
        INSTANCES="$INSTANCES $inst"
    fi
done

if [ -z "$INSTANCES" ]; then
    log_action_msg "no $PROG instances configured so not starting 389 DS"
    exit 0
fi

if [ -n "$2" ]; then
   for I in $INSTANCES; do
      if [ "$2" = "$I" ]; then
         INSTANCES="$2"
      fi
   done
   if [ "$2" != "$INSTANCES" ]; then
      echo -n "$2 is an invalid dirsrv instance"
      log_action_msg "$2 is an invalid dirsrv instance"
      log_end_msg 1
      exit 1
   fi
fi

if [ ! -x $EXEC ]; then
    log_action_msg "$EXEC binary missing - not doing anything"
    log_end_msg 1
    exit 1
fi

start() {
    for INSTANCE in $INSTANCES; do
        log_action_begin_msg "Starting 389 DS instance $INSTANCE: "
        PIDFILE=$PIDDIR/slapd-$INSTANCE.pid
        fix_pid_dir_ownership $CONFDIR/slapd-$INSTANCE
        fix_lock_dir_ownership $CONFDIR/slapd-$INSTANCE $INSTANCE
        # start the directory server in a subshell so that the instance specific
        # init config environment will not apply to any other instance
        (
            [ -f /etc/default/dirsrv-$INSTANCE ] && . /etc/default/dirsrv-$INSTANCE
            start-stop-daemon -S --oknodo -x $EXEC -p $PIDFILE -b -- \
		-D $CONFIG_DIR -i $PIDFILE
        )
        log_end_msg $?
    done
}

stop() {
    for INSTANCE in $INSTANCES; do
        PIDFILE=$PIDDIR/slapd-$INSTANCE.pid
        if [ -f $PIDFILE ]; then
	    log_action_begin_msg "Shutting down 389 DS instance $INSTANCE: "
	    start-stop-daemon -K -p $PIDFILE -x $EXEC
            PID=`cat $PIDFILE`
            RETVAL=0
            while [ $RETVAL -eq 0 ]; do
                sleep 0.5
                kill -0 $PID > /dev/null 2>&1
                RETVAL=$?
            done
            rm -f $PIDFILE
            log_end_msg $?
	fi
    done
}

restart() {
    stop
    start
}

status() {
     ret=0
     for instance in $INSTANCES; do
         if [ -f $PIDDIR/slapd-$instance.pid ]; then
             pid=`cat $PIDDIR/slapd-$instance.pid`
             if kill -0 $pid > /dev/null 2>&1 ; then
                 log_action_msg "$PROG $instance (pid $pid) is running..."
             else
                 log_action_msg "$PROG $instance dead but pid file exists"
                 ret=1
             fi
         else
             log_action_msg "$PROG $instance is stopped"
             ret=0
         fi
     done
     exit $ret
}


case "$1" in
    start|stop|restart|status)
	$1
    ;;

    # FIXME: implement proper force-reload
    force-reload)
        if ! check_network; then
            exit 1
        fi

	stop
	sleep 2
	start
    ;;
    
    *)
        log_action_msg "Usage: /etc/init.d/dirsrv {start|stop|restart|force-reload} [instance-name]"
        exit 1
    ;;
esac

exit 0