daemon-windows: unlink pidfile before stopping the service.
authorGurucharan Shetty <gshetty@nicira.com>
Wed, 28 May 2014 22:07:31 +0000 (15:07 -0700)
committerGurucharan Shetty <gshetty@nicira.com>
Tue, 24 Jun 2014 16:50:32 +0000 (09:50 -0700)
When a OVS daemon is configured to run as a Windows service,
when the service is stopped by calling service_stop(), the
windows services manager does not give enough time to do
everything in the atexit handler. So call the exit handler
directly from service_stop().

Also add a test case for Windows services which checks for
the termination of the service by looking at pidfile cleaned
by the exit handler.

Signed-off-by: Gurucharan Shetty <gshetty@nicira.com
Acked-by: Ben Pfaff <blp@nicira.com>
lib/daemon-windows.c
lib/fatal-signal.c
lib/fatal-signal.h
tests/daemon.at

index f94ad9b..a7d6566 100644 (file)
@@ -218,6 +218,11 @@ should_service_stop(void)
 void
 service_stop()
 {
+    if (!service_started) {
+        return;
+    }
+    fatal_signal_atexit_handler();
+
     ResetEvent(wevent);
     CloseHandle(wevent);
 
index 3ddff00..ebafc90 100644 (file)
@@ -64,7 +64,6 @@ static volatile sig_atomic_t stored_sig_nr = SIG_ATOMIC_MAX;
 
 static struct ovs_mutex mutex;
 
-static void atexit_handler(void);
 static void call_hooks(int sig_nr);
 #ifdef _WIN32
 static BOOL WINAPI ConsoleHandlerRoutine(DWORD dwCtrlType);
@@ -115,7 +114,7 @@ fatal_signal_init(void)
             }
 #endif
         }
-        atexit(atexit_handler);
+        atexit(fatal_signal_atexit_handler);
     }
 }
 
@@ -226,8 +225,8 @@ fatal_ignore_sigpipe(void)
 #endif
 }
 
-static void
-atexit_handler(void)
+void
+fatal_signal_atexit_handler(void)
 {
     call_hooks(0);
 }
index e50d14a..c362616 100644 (file)
@@ -31,6 +31,7 @@ void fatal_signal_fork(void);
 void fatal_signal_run(void);
 void fatal_signal_wait(void);
 void fatal_ignore_sigpipe(void);
+void fatal_signal_atexit_handler(void);
 
 /* Convenience functions for unlinking files upon termination.
  *
index e20abc2..4a6f341 100644 (file)
@@ -159,3 +159,28 @@ AT_CHECK([grep 'ovsdb-server: could not initialize control socket' stderr],
   [0], [ignore], [])
 AT_CHECK([test ! -s pid])
 AT_CLEANUP
+
+AT_SETUP([daemon --service])
+AT_SKIP_IF([test "$IS_WIN32" != "yes"])
+OVSDB_INIT([db])
+AT_CAPTURE_FILE([pid])
+# To create a Windows service, we need the absolute path for the executable.
+abs_path="$(cd $(dirname `which ovsdb-server`); pwd -W; cd $OLDPWD)"
+
+AT_CHECK([sc create ovsdb-server binpath="$abs_path/ovsdb-server `pwd`/db --log-file=`pwd`/ovsdb-server.log --pidfile=`pwd`/pid --remote=punix:`pwd`/socket --unixctl=`pwd`/unixctl --service"],
+[0], [[[SC]] CreateService SUCCESS
+])
+
+AT_CHECK([sc start ovsdb-server], [0], [ignore])
+OVS_WAIT_UNTIL([test -s pid])
+AT_CHECK([sc query ovsdb-server | grep STATE | grep RUNNING], [0], [ignore])
+AT_CHECK([kill -0 `cat pid`], [0], [ignore])
+AT_CHECK([ovs-appctl -t `pwd`/unixctl ovsdb-server/list-dbs], [0],
+[Open_vSwitch
+])
+AT_CHECK([sc stop ovsdb-server], [0], [ignore])
+OVS_WAIT_UNTIL([test ! -s pid])
+AT_CHECK([sc query ovsdb-server | grep STATE | grep STOPPED], [0], [ignore])
+AT_CHECK([sc delete ovsdb-server], [0], [[[SC]] DeleteService SUCCESS
+])
+AT_CLEANUP