On 11-05-20 06:45 AM, Ondřej Surý wrote:
Hi Steven,

could you try attached init.d script?

I made some minor corrections.
 * Silenced pidofproc in do_start and try-restart
* Fix pidofproc return code handling in do_stop (otherwise /etc/init.d/cyrus-imapd stop always returned failed)

I'll have to so more testing of the sync_client. One thought is there is may be race condition with cyrmaster (or a user) starting a new sync_client process after sync_stop has run, but before the shutdown is finished.

Perhaps the touch "$SYNCSHUTDOWN" should be done regardless and rm -f $SYNCSHUTDOWN should be done after cyrmaster has stopped. I would assume if "$SYNCSHUTDOWN" exists, then no new sync_client will start.


--- cyrus-common.cyrus-imapd.init	2011-05-20 09:48:51.351117475 -0700
+++ /etc/init.d/cyrus-imapd	2011-05-20 09:29:33.831127422 -0700
@@ -138,7 +138,7 @@
 	|| return 2
 
     # cyrmaster is not running
-    pidofproc $DAEMON || return 2
+    pidofproc $DAEMON >/dev/null || return 2
 }
 
 sync_stop () {
@@ -176,11 +176,21 @@
     [ "$RETVAL" = 2 ] && return 2
 
     # cyrmaster is still running
-    pidofproc $DAEMON || return 2
-
-    # Many daemons don't delete their pidfiles when they exit.
-    rm -f $PIDFILE
-    return "$RETVAL"
+    # pidofproc will return:
+    # 0 is running
+    # 1 is $DAEMON isn't running
+    # 3 is $DAEMON isn't running
+    # 4 for other error
+    pidofproc $DAEMON 
+    RETVAL="$?"
+    [ "$RETVAL" = 0 ] && return 2
+    if [ "$RETVAL" = 1 ] || [ "$RETVAL" = 3 ]; then
+	# Many daemons don't delete their pidfiles when they exit.
+	rm -f $PIDFILE
+	return 0
+    else
+	return 2
+    fi
 }
 
 #
@@ -259,7 +269,7 @@
        status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
        ;;
   try-restart)
-  	pidofproc "$DAEMON" && exec $0 restart
+  	pidofproc "$DAEMON" >/dev/null && exec $0 restart
 	;;
   *)
 	echo "Usage: $0 {start|stop|status|restart|reload|force-reload|try-restart}" 1>&2

Reply via email to