Ratan Gupta | 07a08c9 | 2018-09-03 08:41:52 +0530 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | set -x |
| 4 | |
| 5 | NAME="nslcd" |
| 6 | CONFIG="/etc/nslcd.conf" |
| 7 | DAEMON="/usr/sbin/nslcd" |
| 8 | DESC="LDAP connection daemon" |
| 9 | STATEDIR="/var/run/$NAME" |
| 10 | PIDFILE="$STATEDIR/$NAME.pid" |
| 11 | |
| 12 | start() |
| 13 | { |
| 14 | if [ -e $PIDFILE ]; then |
| 15 | PIDDIR=/proc/$(cat $PIDFILE) |
| 16 | if [ -d ${PIDDIR} ]; then |
| 17 | echo "$DESC already running." |
| 18 | exit 1 |
| 19 | else |
| 20 | echo "Removing stale PID file $PIDFILE" |
| 21 | rm -f $PIDFILE |
| 22 | fi |
| 23 | fi |
| 24 | |
| 25 | echo -n "Starting $DESC..." |
| 26 | |
| 27 | start-stop-daemon --start --oknodo \ |
| 28 | --pidfile $PIDFILE --startas $DAEMON |
| 29 | |
| 30 | if [ $? -eq 0 ]; then |
| 31 | echo "done." |
| 32 | else |
| 33 | echo "failed." |
| 34 | fi |
| 35 | } |
| 36 | |
| 37 | stop() |
| 38 | { |
| 39 | echo -n "Stopping $DESC..." |
| 40 | start-stop-daemon --stop --quiet --pidfile $PIDFILE \ |
| 41 | --name $NAME |
| 42 | if [ $? -eq 0 ]; then |
| 43 | echo "done." |
| 44 | else |
| 45 | echo "failed." |
| 46 | fi |
| 47 | rm -f $PIDFILE |
| 48 | } |
| 49 | |
| 50 | status() |
| 51 | { |
| 52 | if [ -f $PIDFILE ]; then |
| 53 | if $DAEMON --check |
| 54 | then |
| 55 | echo "$DESC is running (pid `cat $PIDFILE`" |
| 56 | else |
| 57 | echo "$DESC stopped" |
| 58 | fi |
| 59 | else |
| 60 | echo "$DESC stopped" |
| 61 | fi |
| 62 | } |
| 63 | |
| 64 | case "$1" in |
| 65 | start) |
| 66 | start |
| 67 | ;; |
| 68 | stop) |
| 69 | stop |
| 70 | ;; |
| 71 | restart|force-reload|reload) |
| 72 | stop |
| 73 | start |
| 74 | ;; |
| 75 | status) |
| 76 | status |
| 77 | ;; |
| 78 | *) |
| 79 | echo "Usage: $0 {start|stop|force-reload|restart|reload|status}" |
| 80 | exit 1 |
| 81 | ;; |
| 82 | esac |
| 83 | |
| 84 | exit 0 |