summaryrefslogtreecommitdiffstats
path: root/source/n/openldap/rc.openldap
blob: d659d27a7b043b6aa8ad2ff5521ecbf0fba8fb57 (plain) (blame)
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
#!/bin/sh
# Start/stop/restart the OpenLDAP server (slapd).

# Source default settings:
if [ -r /etc/default/slapd ]; then
  . /etc/default/slapd
fi

# If needed, create run directory:
if [ ! -d /var/run/openldap ]; then
  mkdir -p /var/run/openldap
  chown ldap:ldap /var/run/openldap
fi

slapd_start() {
  if [ -e /var/run/openldap/slapd.pid ]; then
    echo "ERROR: Not starting OpenLDAP server because /var/run/openldap/slapd.pid exists."
  elif [ -x /usr/sbin/slapd ]; then
    echo "Starting OpenLDAP server:  /usr/sbin/slapd -u ldap -h "$SLAPD_URLS" $SLAPD_OPTIONS"
    /usr/sbin/slapd -u ldap -h "$SLAPD_URLS" $SLAPD_OPTIONS 1> /dev/null 2> /dev/null
  fi
}

slapd_stop() {
  if [ -e /var/run/openldap/slapd.pid ]; then
    echo "Stopping OpenLDAP server."
    kill -INT $(cat /var/run/openldap/slapd.pid)
  else
    echo "ERROR: Not stopping OpenLDAP server because /var/run/openldap/slapd.pid does not exist."
  fi
  rm -f /var/run/openldap/slapd.pid
}

slapd_restart() {
  slapd_stop
  sleep 1
  slapd_start
}

slapd_status() {
  if [ -e /var/run/openldap/slapd.pid ]; then
    if ps axc | grep slapd >/dev/null 2>&1; then
      echo "OpenLDAP is running."
      return 0
    fi
    echo "OpenLDAP PID file exists but the service is down."
    return 1
  else
    echo "OpenLDAP is stopped."
    return 0
  fi
}

case "$1" in
  'start')
    slapd_start
    ;;
  'stop')
    slapd_stop
    ;;
  'restart')
    slapd_restart
    ;;
  'status')
    slapd_status
    ;;
  *)
    echo "usage $0 start|stop|restart"
esac