aboutsummaryrefslogtreecommitdiff
path: root/network/openldap-server/rc.openldap
blob: 0e64c219fc040c6e49b6df00e0063a0e6d5dc1ba (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
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
#!/bin/sh

# OpenLDAP Server start/stop script


. /etc/default/slapd

PID_FILE=/var/run/openldap/slapd.pid
EXEC=/usr/sbin/slapd


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


slapd_start() {

  echo -n "Starting OpenLDAP server..."

  if [ -e $PID_FILE ]; then

    if ps axc | grep slapd >/dev/null 2>&1 ; then
      echo "already running!"
      return 1
    else
      rm $PID_FILE
    fi

  fi

  $EXEC -u ldap -h "$SLAPD_URLS" $SLAPD_OPTIONS > /dev/null 2>&1
  echo "done!"

}


slapd_stop() {

  echo -n "Stopping OpenLDAP server..."

  if [ -e $PID_FILE ]; then
    if ps axc | grep slapd >/dev/null 2>&1; then
      kill -INT $(cat $PID_FILE)
    else
      echo "already stopped!"
    fi
  fi

  rm $PID_FILE >/dev/null 2>&1
  echo "done!"

}


slapd_restart() {
  slapd_stop
  sleep 1
  slapd_start
}


slapd_status() {

  if [ -e $PID_FILE ]; 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