View Issue Details

IDProjectCategoryView StatusLast Update
0001156SOGoPackaging (Debian)public2012-11-18 12:38
ReporterwsourdeauAssigned To 
PrioritynormalSeverityfeatureReproducibilityhave not tried
Status closedResolutionfixed 
Product Version 
Target VersionFixed in Version2.0.2 
Summary0001156: SOGo should rely on a configuration file in /etc/
DescriptionThis would provide a more standard "unix way" of configuring a server process. Also, it would enable sogo-tool and the OpenChange backend to make use of the same configuration file. Moreover, it would prevent the buggy code in NSUserDefaults from rewriting plist files in XML.

The case of having multiple instances running in parallel could be simply solved by leaving the user-based configuration take over in those cases.
TagsNo tags attached.

Activities

dekkers

dekkers

2012-04-04 12:33

reporter   ~0003687

I'm not sure that this is the correct approach, but I did some basic testing and it seems to work. When /etc/sogo/sogo.conf doesn't exist we fallback to the old code of using the user defaults, but when it does exists we read it and create a volatile sogod domain from it. Because the domain is volatile it isn't written back to the GNUstep Defaults directory. It will also try to read debconf.conf, the idea is that debconf generated configuration items such as the configured database will live in debconf.conf. This should probably be only included on Debian systems, but I added it because I'd feedback whether this is the right approach.

2012-04-04 12:33

 

0004-Read-configuration-from-etc.patch (3,819 bytes)
From: Jeroen Dekkers <jeroen@dekkers.ch>
Date: Sat, 24 Mar 2012 02:17:19 +0100
Subject: Read configuration from /etc

---
 SoObjects/SOGo/SOGoSystemDefaults.m |   61 ++++++++++++++++++++++++++++------
 Tools/sogo-tool.m                   |    8 ++++-
 2 files changed, 57 insertions(+), 12 deletions(-)

diff --git a/SoObjects/SOGo/SOGoSystemDefaults.m b/SoObjects/SOGo/SOGoSystemDefaults.m
index f617d6d..cb656ea 100644
--- a/SoObjects/SOGo/SOGoSystemDefaults.m
+++ b/SoObjects/SOGo/SOGoSystemDefaults.m
@@ -1,6 +1,7 @@
 /* SOGoSystemDefaults.m - this file is part of SOGo
  *
  * Copyright (C) 2009-2011 Inverse inc.
+ * Copyright (C) 2012 Jeroen Dekkers <jeroen@dekkers.ch>
  *
  * Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
  *         Francis Lachapelle <flachapelle@inverse.ca>
@@ -95,27 +96,65 @@ BootstrapNSUserDefaults ()
 + (void) prepareUserDefaults
 {
   NSString *redirectURL;
-  NSDictionary *domain;
   NSUserDefaults *ud;
   SOGoStartupLogger *logger;
 
   logger = [SOGoStartupLogger sharedLogger];
 
   ud = [NSUserDefaults standardUserDefaults];
-  domain = [ud persistentDomainForName: @"sogod"];
-  if (![domain count])
+  if ([[NSFileManager defaultManager] fileExistsAtPath: @"/etc/sogo/sogo.conf"])
     {
-      domain = [ud persistentDomainForName: @"sogod-0.9"];
-      if ([domain count])
+      NSMutableDictionary *domain;
+
+      domain = [[NSMutableDictionary alloc] initWithContentsOfFile: @"/etc/sogo/sogo.conf"];
+      if (domain)
 	{
-	  [logger logWithFormat: @"migrating user defaults from sogod-0.9"];
-	  [ud setPersistentDomain: domain forName: @"sogod"];
-	  [ud removePersistentDomainForName: @"sogod-0.9"];
-	  [ud synchronize];
+	  if ([[NSFileManager defaultManager] fileExistsAtPath: @"/etc/sogo/debconf.conf"])
+	    {
+	      NSMutableDictionary *dbconfig;
+
+	      dbconfig = [[NSMutableDictionary alloc] initWithContentsOfFile: @"/etc/sogo/debconf.conf"];
+	      if (dbconfig)
+		{
+		  [domain addEntriesFromDictionary: dbconfig];
+		  [dbconfig autorelease];
+		}
+	      else
+		{
+		  [logger warnWithFormat: @"Can't deserialize /etc/sogo/debconf.conf, exiting."];
+		  exit(1);
+		}
+	    }
+	  [ud removePersistentDomainForName: @"sogod"];
+	  [ud setVolatileDomain: domain forName: @"sogod"];
+	  [domain autorelease];
 	}
       else
-        [logger warnWithFormat: @"No configuration found."
-                @" SOGo will not work properly."];
+	{
+	  [logger errorWithFormat: @"Can't deserialize /etc/sogo/sogo.conf, exiting."];
+	  exit(1);
+	}
+    }
+  else
+    {
+      NSDictionary *domain;
+      domain = [ud persistentDomainForName: @"sogod"];
+      if (![domain count])
+	{
+	  domain = [ud persistentDomainForName: @"sogod-0.9"];
+	  if ([domain count])
+	    {
+	      [logger logWithFormat: @"migrating user defaults from sogod-0.9"];
+	      [ud setPersistentDomain: domain forName: @"sogod"];
+	      [ud removePersistentDomainForName: @"sogod-0.9"];
+	      [ud synchronize];
+	    }
+	  else
+	    {
+	      [logger warnWithFormat: @"No configuration found, exiting."];
+	      exit(1);
+	    }
+	}
     }
   [self injectSOGoDefaults: ud];
 
diff --git a/Tools/sogo-tool.m b/Tools/sogo-tool.m
index fc93456..3173d63 100644
--- a/Tools/sogo-tool.m
+++ b/Tools/sogo-tool.m
@@ -221,8 +221,14 @@ static void
 setupUserDefaults (NSUserDefaults *ud)
 {
   NSMutableDictionary *defaultsOverrides;
+  NSDictionary *domain;
 
-  [ud registerDefaults: [ud persistentDomainForName: @"sogod"]];
+  domain = [ud persistentDomainForName: @"sogod"];
+  if (![domain count])
+    {
+      domain = [ud volatileDomainForName: @"sogod"];
+    }
+  [ud registerDefaults: domain];
   defaultsOverrides = [NSMutableDictionary new];
   [defaultsOverrides setObject: [NSNumber numberWithInt: 0]
                         forKey: @"SOGoLDAPQueryLimit"];
ludovic

ludovic

2012-11-18 12:38

administrator   ~0004898

This is now possible in v2.0.2.

Issue History

Date Modified Username Field Change
2011-02-28 09:13 wsourdeau New Issue
2011-11-24 14:55 ludovic Severity minor => feature
2012-04-04 12:33 dekkers Note Added: 0003687
2012-04-04 12:33 dekkers File Added: 0004-Read-configuration-from-etc.patch
2012-04-04 12:34 wsourdeau Category Backend General => Packaging (Debian)
2012-11-18 12:38 ludovic Note Added: 0004898
2012-11-18 12:38 ludovic Status new => closed
2012-11-18 12:38 ludovic Resolution open => fixed
2012-11-18 12:38 ludovic Fixed in Version => 2.0.2