]> git.pld-linux.org Git - packages/postfix.git/blobdiff - postfix.init
- nice service fixed
[packages/postfix.git] / postfix.init
index 977707f7ca4187c0857b40848ef56da2da84a382..fe1a1a61801212e94118cd5e6c27804c691eb343 100644 (file)
@@ -1,11 +1,11 @@
 #!/bin/sh
 #
-# postfix       This shell script takes care of starting and stopping
-#               postfix.
+# postfix      This shell script takes care of starting and stopping
+#              postfix.
 #
-# chkconfig:   2345 80 30
+# chkconfig:   345 80 20
 #
-# description: Postfix is a Mail Transport Agent, which is the program
+# description: Postfix is a Mail Transport Agent, which is the program \
 #              that moves mail from one machine to another.
 
 
 [ -f /etc/sysconfig/postfix ] && . /etc/sysconfig/postfix
 
 # Check that networking is up.
-if is_no "${NETWORKING}"; then
-        msg_Network_Down Postfix
-        exit 1
-fi
+networking_check() {
+       if is_yes "${NETWORKING}"; then
+               if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then
+                       msg_network_down "Postfix"
+                       exit 1
+               fi
+       else
+               exit 0
+       fi
+}
+
+start() {
+       local msg
 
-# See how we were called.
-case "$1" in
-  start)
-       # Check if the service is already running?
        if [ ! -f /var/lock/subsys/postfix ]; then
-               msg_starting Postfix
+               msg_starting "Postfix"
                busy
-               newaliases
-               $0 rebuilddb
-               MSG="`/usr/sbin/postfix start 2>&1`"
-               if [ "$?" = "0" ] ; then
-                       deltext; ok
+               msg=$(nice -n ${SERVICE_RUN_NICE_LEVEL:-${DEFAULT_SERVICE_RUN_NICE_LEVEL:-0}} /usr/sbin/postfix start 2>&1)
+               RETVAL=$?
+               if [ $RETVAL -eq 0 ]; then
+                       ok
                        touch /var/lock/subsys/postfix
                else
-                       deltext; fail
-                       echo "$MSG"
+                       fail
+                       echo >&2 "$msg"
                fi
        else
-               msg_Already_Running Postfix
+               msg_already_running "Postfix"
        fi
-       ;;
-  stop)
-       # Stop daemons.
-        if [ -f /var/lock/subsys/postfix ]; then
-                msg_stopping Postfix
+}
+
+stop() {
+       local msg
+       if [ -f /var/lock/subsys/postfix ]; then
+               msg_stopping "Postfix"
                busy
-               MSG="`/usr/sbin/postfix stop 2>&1`"
-               if [ "$?" = "0" ]; then
-                       deltext; ok
+               msg=$(/usr/sbin/postfix stop 2>&1)
+               if [ $? -eq 0 ]; then
+                       ok
                else
-                       deltext; fail
-                       echo "$MSG"
+                       fail
+                       echo >&2 "$msg"
                fi
                rm -f /var/lock/subsys/postfix
-        else
-                msg_Not_Running Postfix
-                exit 1
+       else
+               msg_not_running "Postfix"
+       fi
+}
+
+reload() {
+       local msg
+       if [ -f /var/lock/subsys/postfix ]; then
+               msg_reloading "Postfix"
+               busy
+               msg=$(/usr/sbin/postfix reload 2>&1)
+               RETVAL=$?
+               if [ $RETVAL -eq 0 ]; then
+                       ok
+               else
+                       fail
+                       echo >&2 "$msg"
+                       RETVAL=7
+               fi
+       else
+               msg_not_running "Postfix"
+               RETVAL=7
        fi
+}
+
+RETVAL=0
+# See how we were called.
+case "$1" in
+  start)
+       networking_check
+       start
        ;;
-  restart)
-       $0 stop
-       $0 start
+  stop)
+       stop
        ;;
-  reload)
-       /usr/sbin/postfix reload
+  restart)
+       networking_check
+       stop
+       start
        ;;
-  status)
-       status postfix
-       exit $?
+  reload|force-reload)
+       networking_check
+       reload
        ;;
   rebuilddb)
-        for I in access canonical relocated transport virtual; do
-               if [ -f /etc/mail/$I ] ; then
-                       /usr/sbin/postmap hash:/etc/mail/$I < /etc/mail/$I
+       standard_db="access canonical relocated transport virtual"
+       extra_db=$(ls -1 /etc/mail/*.db 2> /dev/null | egrep -v '/(access|canonical|relocated|transport|virtual|aliases)\.db$')
+
+       echo -n "Rebuilding databases: "
+       for base in $standard_db $extra_db; do
+               db=$(basename "$base" .db)
+
+               if [ -f /etc/mail/$db ]; then
+                       echo -n "$db "
+                       /usr/sbin/postmap hash:/etc/mail/$db < /etc/mail/$db
                fi
        done
-       ;;
+       echo "...DONE"
+
+       echo -n "Rebuilding aliases database"
+       /usr/bin/newaliases
+       echo "...DONE"
+       ;;
+  status)
+       status master
+       exit $?
+       ;;
   *)
-       msg_Usage "$0 {start|stop|status|restart|reload|rebuilddb}"
-       exit 1
+       msg_usage "$0 {start|stop|restart|reload|force-reload|rebuilddb|status}"
+       exit 3
 esac
 
 exit $RETVAL
This page took 0.08075 seconds and 4 git commands to generate.