chiark / gitweb /
automatically upgrade on startup if necessary
authorRichard Kettlewell <rjk@greenend.org.uk>
Thu, 22 Nov 2007 10:26:50 +0000 (10:26 +0000)
committerRichard Kettlewell <rjk@greenend.org.uk>
Thu, 22 Nov 2007 10:26:50 +0000 (10:26 +0000)
server/trackdb.c
tests/dbversion.py

index 1e643ef..15402ab 100644 (file)
@@ -217,7 +217,8 @@ static pid_t subprogram(ev_source *ev, const char *prog,
   /* If we're in the background then trap subprocess stdout/stderr */
   if(!(pid = xfork())) {
     exitfn = _exit;
-    ev_signal_atfork(ev);
+    if(ev)
+      ev_signal_atfork(ev);
     signal(SIGPIPE, SIG_DFL);
     if(outputfd != -1) {
       xdup2(outputfd, 1);
@@ -305,6 +306,7 @@ static DB *open_db(const char *path,
  */
 void trackdb_open(int flags) {
   int newdb, err;
+  pid_t pid;
 
   /* sanity checks */
   assert(opened == 0);
@@ -337,8 +339,15 @@ void trackdb_open(int flags) {
               oldversion, config->dbversion);
       case TRACKDB_CAN_UPGRADE:
         /* This database needs upgrading */
-        fatal(0, "database needs upgrading from %ld to %ld, which is not yet supported",
-              oldversion, config->dbversion);
+        info("invoking disorder-dbupgrade to upgrade from %ld to %ld",
+             oldversion, config->dbversion);
+        pid = subprogram(0, "disorder-dbupgrade", -1);
+        while(waitpid(pid, &err, 0) == -1 && errno == EINTR)
+          ;
+        if(err)
+          fatal(0, "disorder-dbupgrade %s", wstat(err));
+        info("disorder-dbupgrade succeeded");
+        break;
       case TRACKDB_OPEN_FOR_UPGRADE:
         break;
       default:
index 37e3b46..78788b1 100755 (executable)
@@ -31,34 +31,10 @@ def test():
     time.sleep(2)
     dtest.stop_daemon()
     # Revert to default configuration
-    print "Checking daemon won't start with an old database"
     dtest.copyfile(configsave, config)
+    print "Testing daemon manages to upgrade..."
     dtest.start_daemon()
-    time.sleep(2)
-    c = disorder.client()
-    try:
-        v = c.version()
-        print "unexpected success"
-        ok = False
-    except disorder.communicationError, e:
-        if re.search("connection refused", str(e)):
-            print "unexpected error: %s" % e
-            ok = False
-        else:
-            ok = True
-    dtest.stop_daemon()
-    if not ok:
-        sys.exit(1)
-    # Try running the upgrade tool
-    print "Attempting an upgrade..."
-    rc = subprocess.call(["disorder-dbupgrade",
-                          "--config", "%s/config" % dtest.testroot])
-    if rc != 0:
-        print "disorder-dbupgrade: FAILED: exit code %s" % rc
-        sys.exit(1)
-    print "Testing daemon after upgrade..."
-    dtest.start_daemon()
-    time.sleep(2)
+    time.sleep(4)
     assert dtest.check_files() == 0
 
 if __name__ == '__main__':