From 0bec69ebfa3bb7cf25eed5e2e9173b71ff4f07f3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Duchesneau?= <stephane.duchesneau@savoirfairelinux.com>
Date: Sat, 10 Sep 2011 07:38:08 -0400
Subject: [PATCH] Add support for RUN directory and LOG directory in setup.py.
 Also makes the init script now work!

---
 bin/default/shinken.in |   32 ++++++++++++++++++--------------
 setup.cfg              |    2 ++
 setup.py               |   32 +++++++++++++++++++++++++++++---
 3 files changed, 49 insertions(+), 17 deletions(-)

diff --git a/bin/default/shinken.in b/bin/default/shinken.in
index 29d45da..2046ddc 100644
--- a/bin/default/shinken.in
+++ b/bin/default/shinken.in
@@ -1,6 +1,8 @@
 # /etc/default/shinken
 #$ETC$ is where we put all configuration files
-#$VAR$ is where we put all variables files (pid, and all)
+#$VAR$ is where we put some variables files (replaced by $RUN$ and $LOG$ for now)
+#$RUN$ is where we put pid files
+#$LOG$ is where we put log files
 #$SCRIPTS_BIN$ is where the launch scripts will be send
 
 
@@ -8,6 +10,8 @@
 ETC=$ETC$
 VAR=$VAR$
 BIN=$SCRIPTS_BIN$
+RUN=$RUN$
+LOG=$LOG$
 
 
 ###ARBITER PART
@@ -25,12 +29,12 @@ ARBITERDAEMON=$BIN/shinken-arbiter
 #The ARBITER PID
 if [ -r $SHINKENCFG ] ; then
     tmppid=`grep 'lock_file=' $SHINKENCFG | grep -v '#' | tail -n 1 | awk -F '=' '{print $2}'`
-    ARBITERPID=${tmppid-$VAR/arbiterd.pid}
+    ARBITERPID=${tmppid-$RUN/arbiterd.pid}
 else
-    ARBITERPID="$VAR/arbiterd.pid"
+    ARBITERPID="$RUN/arbiterd.pid"
 fi
 
-ARBITERDEBUGFILE="$VAR/arbiter-debug.log"
+ARBITERDEBUGFILE="$LOG/arbiter-debug.log"
 
 
 ###SCHEDULER PART
@@ -41,9 +45,9 @@ SCHEDULERCFG="$ETC/schedulerd.ini"
 SCHEDULERDAEMON=$BIN/shinken-scheduler
 
 #The SCHEDULER PID
-SCHEDULERPID="$VAR/schedulerd.pid"
+SCHEDULERPID="$RUN/schedulerd.pid"
 
-SCHEDULERDEBUGFILE="$VAR/scheduler-debug.log"
+SCHEDULERDEBUGFILE="$LOG/scheduler-debug.log"
 
 ###POLLER PART
 # location of the poller daemon configuration
@@ -53,9 +57,9 @@ POLLERCFG="$ETC/pollerd.ini"
 POLLERDAEMON=$BIN/shinken-poller
 
 #The poller pid
-POLLERPID="$VAR/pollerd.pid"
+POLLERPID="$RUN/pollerd.pid"
 
-POLLERDEBUGFILE="$VAR/poller-debug.log"
+POLLERDEBUGFILE="$LOG/poller-debug.log"
 
 
 ###REACTIONNER PART
@@ -66,9 +70,9 @@ REACTIONNERCFG="$ETC/reactionnerd.ini"
 REACTIONNERDAEMON=$BIN/shinken-reactionner
 
 #The reactionner pid
-REACTIONNERPID="$VAR/reactionnerd.pid"
+REACTIONNERPID="$RUN/reactionnerd.pid"
 
-REACTIONNERDEBUGFILE="$VAR/reactionner-debug.log"
+REACTIONNERDEBUGFILE="$LOG/reactionner-debug.log"
 
 
 ###BROKER PART
@@ -79,9 +83,9 @@ BROKERCFG="$ETC/brokerd.ini"
 BROKERDAEMON=$BIN/shinken-broker
 
 #The broker pid
-BROKERPID="$VAR/brokerd.pid"
+BROKERPID="$RUN/brokerd.pid"
 
-BROKERDEBUGFILE="$VAR/broker-debug.log"
+BROKERDEBUGFILE="$LOG/broker-debug.log"
 
 
 ###RECEIVER PART
@@ -92,9 +96,9 @@ RECEIVERCFG="$ETC/receiverd.ini"
 RECEIVERDAEMON=$BIN/shinken-receiver
 
 #The broker pid
-RECEIVERPID="$VAR/receiverd.pid"
+RECEIVERPID="$RUN/receiverd.pid"
 
-RECEIVERDEBUGFILE="$VAR/receiver-debug.log"
+RECEIVERDEBUGFILE="$LOG/receiver-debug.log"
 
 
 # nicelevel to run nagios daemon with
diff --git a/setup.cfg b/setup.cfg
index 1f9a756..0714bd6 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -2,4 +2,6 @@
 #sysconfigdir = /etc
 etc-path=/etc/shinken
 var-path=/var/lib/shinken
+run-path=/var/run/shinken
+log-path=/var/log/shinken
 plugins-path=/usr/lib/nagios/plugins
diff --git a/setup.py b/setup.py
index 783311a..fd15171 100644
--- a/setup.py
+++ b/setup.py
@@ -79,13 +79,15 @@ class install(_install):
     user_options = _install.user_options + [
         ( 'etc-path=', None, 'read-only single-machine data' ),
         ( 'var-path=', None, 'modifiable single-machine data' ),
+        ( 'run-path=', None, 'PID files' ),
+        ( 'log-path=', None, 'LOG files' ),
         ( 'plugins-path=', None, 'program executables' ),
         ( 'owner=', None, ( 
-                'change owner for etc/* and var (default: %s)' % DEFAULT_OWNER
+                'change owner for etc/*, var, run and log folders (default: %s)' % DEFAULT_OWNER
             )
         ),
         ( 'group=', None, (
-                'change group for etc/* and var (default: %s)' % DEFAULT_GROUP
+                'change group for etc/*, var, run and log folders (default: %s)' % DEFAULT_GROUP
             )
         ),
     ]
@@ -94,6 +96,8 @@ class install(_install):
         _install.initialize_options(self)
         self.etc_path = None
         self.var_path = None
+        self.run_path = None
+        self.log_path = None
         self.plugins_path = None
         self.owner = None
         self.group = None
@@ -104,6 +108,10 @@ class install(_install):
             self.etc_path = default_paths['etc']
         if self.var_path is None:
             self.var_path = default_paths['var']
+        if self.run_path is None:
+            self.run_path = default_paths['run']
+        if self.log_path is None:
+            self.log_path = default_paths['log']
         if self.plugins_path is None:
             self.plugins_path = default_paths['libexec']
         if self.owner is None:
@@ -112,7 +120,7 @@ class install(_install):
             self.group = DEFAULT_GROUP
 
         if self.root:
-            for attr in ('etc_path', 'var_path', 'plugins_path'):
+            for attr in ('etc_path', 'var_path', 'plugins_path', 'run_path', 'log_path'):
                 setattr(self, attr, change_root(self.root, getattr(self, attr)))
             
 
@@ -128,6 +136,8 @@ class build_config(Command):
         self.build_base = None
         self.etc_path = None
         self.var_path = None
+        self.run_path = None
+        self.log_path = None
         self.plugins_path = None
 
         self._install_scripts = None
@@ -146,6 +156,8 @@ class build_config(Command):
         self.set_undefined_options('install_config',
                                    ('etc_path', 'etc_path'),
                                    ('var_path', 'var_path'),
+                                   ('run_path', 'run_path'),
+                                   ('log_path', 'log_path'),
                                    ('plugins_path', 'plugins_path'),
                                    ('owner', 'owner'),
                                    ('group', 'group')
@@ -176,6 +188,8 @@ class build_config(Command):
             # substitute
             buf = buf.replace("$ETC$", self.etc_path)
             buf = buf.replace("$VAR$", self.var_path)
+            buf = buf.replace("$RUN$", self.run_path)
+            buf = buf.replace("$LOG$", self.log_path)
             buf = buf.replace("$SCRIPTS_BIN$", self._install_scripts)
             # write out the new file
             f = open(outfile, "w")
@@ -261,6 +275,8 @@ class install_config(Command):
         self.root = None
         self.etc_path = None  # typically /etc on Posix systems 
         self.var_path = None # typically /var on Posix systems 
+        self.run_path = None  # typically /etc on Posix systems 
+        self.log_path = None # typically /var on Posix systems 
         self.plugins_path = None    # typically /libexec on Posix systems
 
     def finalize_options(self):
@@ -273,6 +289,8 @@ class install_config(Command):
                ('root', 'root'),
                ('etc_path', 'etc_path'),
                ('var_path', 'var_path'),
+               ('run_path', 'run_path'),
+               ('log_path', 'log_path'),
                ('plugins_path', 'plugins_path'),
                ('owner', 'owner'),
                ('group', 'group')
@@ -297,6 +315,8 @@ class install_config(Command):
             # recursivly changing permissions for etc/shinken and var/lib/shinken
             self.recursive_chown(self.etc_path, uid, gid, self.owner, self.group)
             self.recursive_chown(self.var_path, uid, gid, self.owner, self.group)
+            self.recursive_chown(self.run_path, uid, gid, self.owner, self.group)
+            self.recursive_chown(self.log_path, uid, gid, self.owner, self.group)
 
 
     def get_inputs (self):
@@ -357,16 +377,22 @@ def update_file_with_string(infilename, outfilename, match, new_string):
 if 'win' in sys.platform:
     default_paths = {'var':      "c:\\shinken\\var",
                      'etc':      "c:\\shinken\\etc",
+                     'log':      "c:\\shinken\\var",
+                     'run':      "c:\\shinken\\var",
                      'libexec':  "c:\\shinken\\libexec",
                      }
 elif 'linux' in sys.platform:
     default_paths = {'var': "/var/lib/shinken/",
                      'etc': "/etc/shinken",
+                     'run': "/var/run/shinken",
+                     'log': "/var/log/shinken",
                      'libexec': "/usr/lib/shinken/plugins",
                      }
 elif 'bsd' in sys.platform or 'dragonfly' in sys.platform:
     default_paths = {'var': "/var/lib/shinken",
                      'etc': "/usr/local/etc/shinken",
+                     'run': "/var/run/shinken",
+                     'log': "/var/log/shinken",
                      'libexec': "/usr/local/libexec/shinken",
                      }
 else:
-- 
1.7.5.4

