Commits

Zhang Huangbin  committed 132e956

Improve rc script.

  • Participants
  • Parent commits 6143b46

Comments (0)

Files changed (4)

 - Requirements:
 
-    # Python 2.4+: http://www.python.org/
-    # python-daemon:
+    # Python >= 2.4: http://www.python.org/
     # python-ldap: http://www.python-ldap.org/
 
 - Install iredapd.
 
     - Install required python modules:
 
-        # easy_install daemon python-ldap
+        # easy_install python-ldap
 
     - Copy iredapd to /opt:
 
-        # cp rc_scripts/iredapd.rhel /etc/init.d/iredapd
+        # cp -rf iredapd-x.y.z /opt/
+        # ln -s /opt/iredapd-x.y.z /opt/iredapd
+        # chmod +x /opt/iredapd/src/iredapd.py
+
+    - Copy necessary rc script:
+
+        # cp /opt/iredapd/rc_scripts/iredapd /etc/init.d/iredapd
+        # chmod +x /etc/init.d/iredapd
 
 - Run iredapd:
 
-    # bash bin/iredapd etc/iredapd.ini
+    # /etc/init.d/iredapd start
 
 - Postfix configuration:
 

File rc_scripts/iredapd

+#!/usr/bin/env bash
+
+# Author: Zhang Huangbin (michaelbibby@gmail.com)
+
+### BEGIN RHEL/CentOS INIT INFO
+# chkconfig: - 27 73
+# description: iredapd is a mail list access policy daemon.
+# processname: iredapd
+### END RHEL/CentOS INIT INFO
+
+### BEGIN Debian/Ubuntu INIT INFO
+# Provides:          iredapd 
+# Required-Start:    $network $syslog
+# Required-Stop:     $network $syslog
+# Default-Start:     2 3 4 5
+# Default-Stop:      0 1 6
+# Short-Description: Control iredapd daemon.
+### BEGIN Debian/Ubuntu INIT INFO
+
+PROG='iredapd'
+BINPATH='/opt/iredapd/src/iredapd.py'
+CONFIG='/opt/iredapd/etc/iredapd.ini'
+PIDFILE='/var/run/iredapd.pid'
+
+check_status() {
+    # Usage: check_status pid_number
+    PID="${1}"
+    l=$(ps --pid ${PID} | wc -l)
+    if [ X"$l" == X"2" ]; then
+        echo "running"
+    else
+        echo "stopped"
+    fi
+}
+
+start() {
+    if [ -f ${PIDFILE} ]; then
+        PID="$(cat ${PIDFILE})"
+        s="$(check_status ${PID})"
+
+        if [ X"$s" == X"running" ]; then
+            echo "${PROG} is already running."
+        else
+            rm -f ${PIDFILE} >/dev/null 2>&1
+            echo "Starting ${PROG} ..."
+            python ${BINPATH} ${CONFIG}
+        fi
+    else
+        echo "Starting ${PROG} ..."
+        python ${BINPATH} ${CONFIG}
+    fi
+    unset s
+}
+
+stop() {
+    if [ -f ${PIDFILE} ]; then
+        PID="$(cat ${PIDFILE})"
+        s="$(check_status ${PID})"
+
+        if [ X"$s" == X"running" ]; then
+            echo "Stopping ${PROG} ..."
+            kill -9 ${PID}
+            if [ X"$?" == X"0" ]; then
+                rm -f ${PIDFILE} >/dev/null 2>&1
+            else
+                echo -e "\t\t[ FAILED ]"
+            fi
+        else
+            echo "${PROG} is already stopped."
+            rm -f ${PIDFILE} >/dev/null 2>&1
+        fi
+    else
+        echo "${PROG} is already stopped."
+    fi
+    unset s
+}
+
+status() {
+    if [ -f ${PIDFILE} ]; then
+        PID="$(cat ${PIDFILE})"
+        s="$(check_status ${PID})"
+
+        if [ X"$s" == X"running" ]; then
+            echo "${PROG} is running."
+        else
+            echo "${PROG} is stopped."
+        fi
+    else
+        echo "${PROG} is stopped."
+    fi
+    unset s
+}
+
+case "$1" in
+    start) start ;;
+    stop) stop ;;
+    status) status ;;
+    restart) stop && start ;;
+    *)
+        echo $"Usage: $0 {start|stop|restart|status}"
+        RETVAL=1
+        ;;
+esac

File rc_scripts/iredapd.rhel

-#!/usr/bin/env bash
-
-# chkconfig: - 27 73
-# description: LDAP stands for Lightweight Directory Access Protocol, used \
-#              for implementing the industry standard directory services.
-# processname: slapd
-# config: /etc/openldap/slapd.conf
-# pidfile: /var/run/openldap/slapd.pid
-
-PROG='iredapd'
-BINPATH='/opt/iredapd/src/iredapd.py'
-CONFIG='/opt/iredapd/etc/iredapd.ini'
-PIDFILE='/var/run/iredapd.pid'
-
-. /etc/rc.d/init.d/functions
-
-# Source networking configuration and check that networking is up.
-if [ -r /etc/sysconfig/network ] ; then
-    . /etc/sysconfig/network
-    [ X"${NETWORKING}" == X"no" ] && exit 1
-fi
-
-start() {
-    if [ -f ${PIDFILE} ]; then
-        status -p ${PIDFILE} ${PROG} > /dev/null
-
-        if [ X"$?" == X"0" ]; then
-            echo -n "${PROG} is already running: "
-            echo -n "$(pidof ${PROG})" && success && echo
-        else
-            rm -f ${PIDFILE} >/dev/null 2>&1
-            echo -n "Starting ${PROG}:"
-            python ${BINPATH} ${CONFIG} && success || failure
-            echo
-        fi
-    else
-        echo -n "Starting ${PROG}:"
-        python ${BINPATH} ${CONFIG} && success || failure
-        echo
-    fi
-}
-
-stop() {
-    if [ -e ${PIDFILE} ]; then
-        status -p ${PIDFILE} ${PROG} > /dev/null
-
-        if [ X"$?" == X"0" ]; then
-            echo -n "Stopping ${PROG}:"
-            kill $(cat ${PIDFILE}) && success || failure
-            echo
-            rm -f ${PIDFILE} >/dev/null 2>&1
-        else
-            echo -n "${PROG} is already stopped." && success
-            echo
-            rm -f ${PIDFILE} >/dev/null 2>&1
-        fi
-    else
-        echo -n "${PROG} is already stopped." && success
-        echo
-    fi
-}
-
-case "$1" in
-    start)
-        start
-        RETVAL=$?
-        ;;
-    stop)
-        stop
-        RETVAL=$?
-        ;;
-    status) status -p ${PIDFILE} ${PROG};;
-    restart)
-        stop
-        start
-        ;;
-    *)
-        echo $"Usage: $0 {start|stop|restart|status}"
-        RETVAL=1
-        ;;
-esac
-
-exit $RETVAL

File rc_scripts/iredapd.ubuntu

-#!/usr/bin/env bash
-
-#
-### BEGIN INIT INFO
-# Provides:          iredapd 
-# Required-Start:    $network $syslog
-# Required-Stop:     $network $syslog
-# Default-Start:     2 3 4 5
-# Default-Stop:      0 1 6
-# Short-Description: Control iredapd daemon.
-### END INIT INFO
-#
-
-PROG='iredapd'
-BINPATH='/opt/iredapd/src/iredapd.py'
-CONFIG='/opt/iredapd/etc/iredapd.ini'
-PIDFILE='/var/run/iredapd.pid'
-
-# Source function library.
-. /lib/lsb/init-functions
-
-start() {
-    start-stop-daemon --start --quiet --pidfile ${PIDFILE} --exec ${BINPATH} -- ${CONFIG} || return 2
-}
-
-stop() {
-    start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile ${PIDFILE} --name ${PROG}
-    RETVAL="$?"
-    [ X"${RETVAL}" == X"2" ] && return 2
-
-    start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --pidfile ${PIDFILE} --name ${PROG}
-    [ "$?" = 2 ] && return 2
-
-    # Many daemons don't delete their pidfiles when they exit.
-    rm -f $PIDFILE
-    return "$RETVAL"
-}
-
-case "$1" in
-    start)
-        start
-        RETVAL=$?
-        ;;
-    stop)
-        stop
-        RETVAL=$?
-        ;;
-    status)
-        status_of_proc -p ${PIDFILE} ${PROG} ${PROG} && exit 0 || exit $?
-        ;;
-    restart)
-        stop
-        start
-        ;;
-    *)
-        echo $"Usage: $0 {start|stop|restart|status}"
-        RETVAL=1
-        ;;
-esac
-
-exit $RETVAL