Date: Saturday, April 9, 2011 @ 16:51:34
  Author: pierre
Revision: 118966

check config before starting php-fpm

Modified:
  php/trunk/PKGBUILD
  php/trunk/rc.d.php-fpm

--------------+
 PKGBUILD     |    4 ++--
 rc.d.php-fpm |   34 ++++++++++++++++++++++++++++------
 2 files changed, 30 insertions(+), 8 deletions(-)

Modified: PKGBUILD
===================================================================
--- PKGBUILD    2011-04-09 20:28:26 UTC (rev 118965)
+++ PKGBUILD    2011-04-09 20:51:34 UTC (rev 118966)
@@ -24,7 +24,7 @@
          'php-tidy'
          'php-xsl')
 pkgver=5.3.6
-pkgrel=1
+pkgrel=2
 _suhosinver=${pkgver}-0.9.10
 arch=('i686' 'x86_64')
 license=('PHP')
@@ -41,7 +41,7 @@
          'fff1a38877142f3ae6036dbe5a85d0a6'
          '39eaa70d276fc3d45d6bcf6cd5ae1106'
          '96ca078be6729b665be8a865535a97bf'
-         'b136a184dd055c559a03eb8bac562a3c'
+         'b01be5f816988fcee7e78225836e5e27'
          'd50ff349da08110a7cc8c691ce2d0423'
          '07c4e412909ac65a44ec90e7a2c4bade')
 

Modified: rc.d.php-fpm
===================================================================
--- rc.d.php-fpm        2011-04-09 20:28:26 UTC (rev 118965)
+++ rc.d.php-fpm        2011-04-09 20:51:34 UTC (rev 118966)
@@ -6,9 +6,7 @@
 
 wait_for_pid () {
        try=0
-
        while test $try -lt 35 ; do
-
                case "$1" in
                        'created')
                        if [ -f "$2" ] ; then
@@ -16,7 +14,6 @@
                                break
                        fi
                        ;;
-
                        'removed')
                        if [ ! -f "$2" ] ; then
                                try=''
@@ -28,15 +25,38 @@
                stat_append '.'
                try=`expr $try + 1`
                sleep 1
-
        done
+}
 
+test_config() {
+       stat_busy 'Checking configuration'
+       if [ $(id -u) -ne 0 ]; then
+               stat_append '(This script must be run as root)'
+               stat_die
+       fi
+
+       if [ ! -r /etc/php/php-fpm.conf ]; then
+               stat_append '(/etc/php/php-fpm.conf not found)'
+               stat_die
+       fi
+
+       local test=$(/usr/sbin/php-fpm -t 2>&1)
+       if [ $? -gt 0 ]; then
+               stat_append '(error in /etc/php/php-fpm.conf)'
+               stat_die
+       elif echo $test | grep -qi 'error'; then
+               stat_append '(error in /etc/php/php.ini)'
+               stat_die
+       fi
+
+       [ -d /var/run/php-fpm ] || install -d -m755 /var/run/php-fpm
+
+       stat_done
 }
 
-[ -d /var/run/php-fpm ] || install -d -m755 /var/run/php-fpm
-
 case "$1" in
        start)
+               test_config
                stat_busy 'Starting php-fpm'
 
                /usr/sbin/php-fpm
@@ -58,6 +78,7 @@
        ;;
 
        stop)
+               test_config
                stat_busy 'Gracefully shutting down php-fpm'
 
                if [ ! -r /var/run/php-fpm/php-fpm.pid ] ; then
@@ -105,6 +126,7 @@
        ;;
 
        reload)
+               test_config
                stat_busy 'Reload service php-fpm'
 
                if [ ! -r /var/run/php-fpm/php-fpm.pid ] ; then

Reply via email to