On 10/21/2010 05:49 PM, Asaf wrote:
On 10/21/2010 03:31 PM, Asaf wrote:
 On 10/21/2010 02:47 PM, Asaf wrote:
this patch adds select box in the status page, enables to use /etc/init.d/pgpool. this requires sudo with no password for apache user on /etc/init.d/pgpool to work.

for me this solves couple of problems:

* pgpool will run as postgres normally (and not as apache)
* the -n option doesn't work for me, and I need it


more complete and correct patch
(after looking a bit more into the code)


_______________________________________________
Pgpool-hackers mailing list
[email protected]  <mailto:[email protected]>
http://pgfoundry.org/mailman/listinfo/pgpool-hackers

one more small fix

--
Asaf Ohaion
Lingnu Open Source Consulting Ltd.
http://www.lingnu.com


_______________________________________________
Pgpool-hackers mailing list
[email protected]
http://pgfoundry.org/mailman/listinfo/pgpool-hackers
and another fix

--
Asaf Ohaion
Lingnu Open Source Consulting Ltd.
http://www.lingnu.com

diff -uNr pgpoolAdmin-3.0.1/command.php pgpoolAdmin-3.0.1_initd_patch/command.php
--- pgpoolAdmin-3.0.1/command.php	2009-01-25 10:16:30.000000000 +0200
+++ pgpoolAdmin-3.0.1_initd_patch/command.php	2010-10-21 14:32:44.000000000 +0200
@@ -89,22 +89,27 @@
             break;
             
         case 'PCP_START_PGPOOL':
-			$configOption = ' -f ' . _PGPOOL2_CONFIG_FILE . ' -F ' . _PGPOOL2_PASSWORD_FILE;
+	    $configOption = ' -f ' . _PGPOOL2_CONFIG_FILE . ' -F ' . _PGPOOL2_PASSWORD_FILE;	    
 			
-			if(isPipe($num)) {
-				$cmdOption = $configOption . $num . ' > /dev/null &';
-			} else {
-				$cmdOption = $configOption . $num . ' 2>&1 &';
-			}
+	    if(isPipe($num)) {
+		$cmdOption = $configOption . $num . ' > /dev/null &';
+	    } else {
+		$cmdOption = $configOption . $num . ' 2>&1 &';
+	    }
 
-			/* we should not check pid file here.
-			 * let pgpool handle bogus pid file
+	    /* we should not check pid file here.
+	     * let pgpool handle bogus pid file
              * if(DoesPgpoolPidExist()) {
              *   return array('FAIL'=> '');
              * }
-			 */
-            $cmd = _PGPOOL2_COMMAND . $cmdOption;
-			//var_dump($cmd);exit;
+	     */
+	    if ($num == "initd") {
+		$cmd = "sudo /etc/init.d/pgpool start 2>&1";
+	    } else {
+		$cmd = _PGPOOL2_COMMAND . $cmdOption;
+	    }
+            //	     var_dump($cmd);exit;
+    
             $ret = exec($cmd, $output, $return_var);
             if($return_var == 0) {
                 return array($pcpStatus[$return_var] => $output);
diff -uNr pgpoolAdmin-3.0.1/conf/pgmgt.conf.php pgpoolAdmin-3.0.1_initd_patch/conf/pgmgt.conf.php
--- pgpoolAdmin-3.0.1/conf/pgmgt.conf.php	2010-07-22 08:19:36.000000000 +0300
+++ pgpoolAdmin-3.0.1_initd_patch/conf/pgmgt.conf.php	2010-10-21 17:30:22.000000000 +0200
@@ -8,6 +8,7 @@
 define('_PGPOOL2_CMD_OPTION_D', '0');
 define('_PGPOOL2_CMD_OPTION_M', 's');
 define('_PGPOOL2_CMD_OPTION_N', '0');
+define('_PGPOOL2_CMD_USE_INITD', '0');
 define('_PGPOOL2_LOG_FILE', '/tmp/pgpool.log');
 define('_PGPOOL2_PCP_DIR', '/usr/local/bin');
 define('_PGPOOL2_PCP_HOSTNAME', 'localhost');
diff -uNr pgpoolAdmin-3.0.1/config.php pgpoolAdmin-3.0.1_initd_patch/config.php
--- pgpoolAdmin-3.0.1/config.php	2010-07-22 08:17:47.000000000 +0300
+++ pgpoolAdmin-3.0.1_initd_patch/config.php	2010-10-21 17:41:42.000000000 +0200
@@ -88,6 +88,11 @@
 else
     $errors['n'] = $message['errNoDefined'];
 
+if( defined('_PGPOOL2_CMD_USE_INITD'))
+    $params['initd'] = _PGPOOL2_CMD_USE_INITD;
+else
+    $errors['initd'] = $message['errNoDefined'];
+
 if( defined('_PGPOOL2_LOG_FILE'))
     $params['pgpool_logfile'] = _PGPOOL2_LOG_FILE;
 else
@@ -280,6 +285,9 @@
             $str = 'define(\'_PGPOOL2_CMD_OPTION_N\', \'' .  $params['n'] . '\');' . "\n";
             fputs($fp, $str);
 
+            $str = 'define(\'_PGPOOL2_CMD_USE_INITD\', \'' .  $params['initd'] . '\');' . "\n";
+            fputs($fp, $str);
+
             $str = 'define(\'_PGPOOL2_LOG_FILE\', \'' .  $params['pgpool_logfile'] . '\');' . "\n";
             fputs($fp, $str);
 
diff -uNr pgpoolAdmin-3.0.1/lang/en.lang.php pgpoolAdmin-3.0.1_initd_patch/lang/en.lang.php
--- pgpoolAdmin-3.0.1/lang/en.lang.php	2010-08-16 13:06:42.000000000 +0300
+++ pgpoolAdmin-3.0.1_initd_patch/lang/en.lang.php	2010-10-21 16:41:27.000000000 +0200
@@ -140,6 +140,7 @@
     'strCmdN' => 'Don\'t run in daemon mode',
     'strCmdPcpFile' => 'pcp.conf',
     'strCmdPgpoolFile' => 'pgpool.conf',
+    'strCmdSudoInitd' => 'Use sudo /etc/init.d/pgpool Instead',
     'strColList' => 'Column list',
     'strColName' => 'Column name of distributed key',
     'strCommon' => 'Common',
diff -uNr pgpoolAdmin-3.0.1/lang/fr.lang.php pgpoolAdmin-3.0.1_initd_patch/lang/fr.lang.php
--- pgpoolAdmin-3.0.1/lang/fr.lang.php	2010-08-17 10:36:44.000000000 +0300
+++ pgpoolAdmin-3.0.1_initd_patch/lang/fr.lang.php	2010-10-21 16:41:27.000000000 +0200
@@ -140,6 +140,7 @@
     'strCmdN' => 'Ne pas exécuter en mode démon',
     'strCmdPcpFile' => 'pcp.conf',
     'strCmdPgpoolFile' => 'pgpool.conf',
+    'strCmdSudoInitd' => 'Use sudo /etc/init.d/pgpool Instead',
     'strColList' => 'Liste de colonnes',
     'strColName' => 'Nom de la colonne de la clé distribuée',
     'strCommon' => 'Commun',
diff -uNr pgpoolAdmin-3.0.1/lang/ja.lang.php pgpoolAdmin-3.0.1_initd_patch/lang/ja.lang.php
--- pgpoolAdmin-3.0.1/lang/ja.lang.php	2010-08-16 13:06:42.000000000 +0300
+++ pgpoolAdmin-3.0.1_initd_patch/lang/ja.lang.php	2010-10-21 16:41:27.000000000 +0200
@@ -140,6 +140,7 @@
     'strCmdN' => '非デーモンモード',
     'strCmdPcpFile' => 'pcp.conf',
     'strCmdPgpoolFile' => 'pgpool.conf',
+    'strCmdSudoInitd' => 'Use sudo /etc/init.d/pgpool Instead',
     'strColList' => '列名リスト',
     'strColName' => '分散キー列名',
     'strCommon' => '共通',
diff -uNr pgpoolAdmin-3.0.1/login.php pgpoolAdmin-3.0.1_initd_patch/login.php
--- pgpoolAdmin-3.0.1/login.php	2010-07-22 08:17:47.000000000 +0300
+++ pgpoolAdmin-3.0.1_initd_patch/login.php	2010-10-21 17:46:39.000000000 +0200
@@ -92,6 +92,7 @@
 $tpl->assign('d', _PGPOOL2_CMD_OPTION_D);
 $tpl->assign('m', _PGPOOL2_CMD_OPTION_M);
 $tpl->assign('n', _PGPOOL2_CMD_OPTION_N);
+$tpl->assign('initd', _PGPOOL2_CMD_USE_INITD);
 
 $tpl->assign('pgpoolConf', _PGPOOL2_CONFIG_FILE);
 $tpl->assign('pcpConf', _PGPOOL2_PASSWORD_FILE);
diff -uNr pgpoolAdmin-3.0.1/status.php pgpoolAdmin-3.0.1_initd_patch/status.php
--- pgpoolAdmin-3.0.1/status.php	2010-07-22 08:17:47.000000000 +0300
+++ pgpoolAdmin-3.0.1_initd_patch/status.php	2010-10-21 17:55:12.000000000 +0200
@@ -56,6 +56,7 @@
 $tpl->assign('d', _PGPOOL2_CMD_OPTION_D);
 $tpl->assign('m', _PGPOOL2_CMD_OPTION_M);
 $tpl->assign('n', _PGPOOL2_CMD_OPTION_N);
+$tpl->assign('initd', _PGPOOL2_CMD_USE_INITD);
 if(isPipe(_PGPOOL2_LOG_FILE)) 
 	$tpl->assign('pipe', 1);
 else
@@ -65,26 +66,32 @@
     case 'start':
         $args = ' ';
 
-        if(isset($_POST['c'])) {
-            $args = $args . "-c ";
-        }
-        if(isset($_POST['D'])) {
-            $args = $args . "-D ";
-        }
-        if(isset($_POST['d'])) {
-            $args = $args . "-d ";
-        }
-        if(isset($_POST['n'])) {
-            $pgpoolLog = _PGPOOL2_LOG_FILE;
-            if($pgpoolLog == '') {
-                $logDir = readLogDir();
-                $pgpoolLog = "$logDir/pgpool.log";
-            }
-			if(isPipe($pgpoolLog))
-				$args = "$args -n 2>&1 $pgpoolLog ";
-			else
-				$args = "$args -n > $pgpoolLog ";
-        }
+        if(isset($_POST['initd'])) // use /etc/init.d/pgpool
+	    {
+		$args = "initd";
+	    } else
+	    {
+		if(isset($_POST['c'])) {
+		    $args = $args . "-c ";
+		}
+		if(isset($_POST['D'])) {
+		    $args = $args . "-D ";
+		}
+		if(isset($_POST['d'])) {
+		    $args = $args . "-d ";
+		}
+		if(isset($_POST['n'])) {
+		    $pgpoolLog = _PGPOOL2_LOG_FILE;
+		    if($pgpoolLog == '') {
+			$logDir = readLogDir();
+			$pgpoolLog = "$logDir/pgpool.log";
+		    }
+		    if(isPipe($pgpoolLog))
+			$args = "$args -n 2>&1 $pgpoolLog ";
+		    else
+			$args = "$args -n > $pgpoolLog ";
+		}
+	    }
         $ret = execPcp('PCP_START_PGPOOL', $args);
         if(!array_key_exists('SUCCESS', $ret)) {
             $tpl->assign('pgpoolStatus', 'pgpool start failed.');
@@ -165,26 +172,32 @@
          */
         $args = ' ';
 
-        if(isset($_POST['c'])) {
-            $args = $args . "-c ";
-        }
-        if(isset($_POST['D'])) {
-            $args = $args . "-D ";
-        }
-        if(isset($_POST['d'])) {
-            $args = $args . "-d ";
-        }
+        if(isset($_POST['initd'])) // use /etc/init.d/pgpool
+	    {
+		$args = "initd";
+	    } else
+	    {
+		if(isset($_POST['c'])) {
+		    $args = $args . "-c ";
+		}
+		if(isset($_POST['D'])) {
+		    $args = $args . "-D ";
+		}
+		if(isset($_POST['d'])) {
+		    $args = $args . "-d ";
+		}
 		if(isset($_POST['n'])) {
-            $pgpoolLog = _PGPOOL2_LOG_FILE;
-            if($pgpoolLog == '') {
-                $logDir = readLogDir();
-                $pgpoolLog = "$logDir/pgpool.log";
-            }
-			if(isPipe($pgpoolLog)) 
-				$args = "$args -n 2>&1 $pgpoolLog ";
-			else
-				$args = "$args -n > $pgpoolLog ";
+		    $pgpoolLog = _PGPOOL2_LOG_FILE;
+		    if($pgpoolLog == '') {
+			$logDir = readLogDir();
+			$pgpoolLog = "$logDir/pgpool.log";
+		    }
+		    if(isPipe($pgpoolLog)) 
+			$args = "$args -n 2>&1 $pgpoolLog ";
+		    else
+			$args = "$args -n > $pgpoolLog ";
 		}
+	    }
         $ret = execPcp('PCP_START_PGPOOL', $args);
         if(!array_key_exists('SUCCESS', $ret)) {
             $tpl->assign('pgpoolStatus', 'pgpool restart failed.');
diff -uNr pgpoolAdmin-3.0.1/templates/config.tpl pgpoolAdmin-3.0.1_initd_patch/templates/config.tpl
--- pgpoolAdmin-3.0.1/templates/config.tpl	2010-07-22 08:17:47.000000000 +0300
+++ pgpoolAdmin-3.0.1_initd_patch/templates/config.tpl	2010-10-21 17:26:43.000000000 +0200
@@ -126,6 +126,17 @@
           <br />{$errors.d|escape}
           {/if}
           </td></tr>
+        <tr><td>{$message.strCmdSudoInitd|escape}</td>
+          <td>
+          {if $params.initd == 1}
+          <input type="checkbox" name="i" checked="checked" />
+          {else}
+          <input type="checkbox" name="i" />
+          {/if}
+          {if $errors.i != ''}
+          <br />{$errors.d|escape}
+          {/if}
+          </td></tr>
         <tr><td>{$message.strCmdM|escape}(-m)</td><td><select name="m">
           {if $params.m == 's'}
                <option value="s" selected="selected">smart</option>
diff -uNr pgpoolAdmin-3.0.1/templates/status.tpl pgpoolAdmin-3.0.1_initd_patch/templates/status.tpl
--- pgpoolAdmin-3.0.1/templates/status.tpl	2010-07-22 08:17:48.000000000 +0300
+++ pgpoolAdmin-3.0.1_initd_patch/templates/status.tpl	2010-10-21 17:26:43.000000000 +0200
@@ -237,6 +237,13 @@
           <tr><td>{$message.strCmdPcpFile|escape}(-F)</td>
           <td>{$pcpConf|escape}</td>
           </tr>
+          <tr><td>{$message.strCmdSudoInitd|escape}</td>
+          {if $initd == 1}
+          <td><input type="checkbox" name="initd" checked="checked" /></td>
+          {else}
+          <td><input type="checkbox" name="initd" /></td>
+	  {/if}
+          </tr>
     </tbody>
     </table>
     {else}
@@ -314,6 +321,13 @@
           <td><input type="checkbox" name="d" /></td>
           {/if}
           </tr>
+          <tr><td>{$message.strCmdSudoInitd|escape}</td>
+          {if $initd == 1}
+          <td><input type="checkbox" name="initd" checked="checked" /></td>
+          {else}
+          <td><input type="checkbox" name="initd" /></td>
+	  {/if}
+          </tr>
           <tr><td>{$message.strCmdM|escape}(-m)</td><td><select name="restart_mode">
           {if $m == 's'}
                <option value="s" selected="selected">smart</option>
_______________________________________________
Pgpool-hackers mailing list
[email protected]
http://pgfoundry.org/mailman/listinfo/pgpool-hackers

Reply via email to