app-eselect/eselect-php: new revision to test config before FPM start/reload.
authorMichael Orlitzky <mjo@gentoo.org>
Tue, 24 Nov 2015 20:11:36 +0000 (15:11 -0500)
committerMichael Orlitzky <mjo@gentoo.org>
Tue, 24 Nov 2015 20:12:00 +0000 (15:12 -0500)
Now that we have a configtest() command for the php-fpm daemon, we
should run it before attempting to reload the daemon. This prevents
the (working) daemon from crashing if the new config has a typo in it.

Performing the same check before start() avoids a five-second wait if
there is an error in the config.

Gentoo-Bug: 487642

Package-Manager: portage-2.2.20.1

app-eselect/eselect-php/eselect-php-0.7.1-r7.ebuild [moved from app-eselect/eselect-php/eselect-php-0.7.1-r6.ebuild with 95% similarity]
app-eselect/eselect-php/files/php-fpm.init-r4 [moved from app-eselect/eselect-php/files/php-fpm.init-r3 with 67% similarity]

similarity index 95%
rename from app-eselect/eselect-php/eselect-php-0.7.1-r6.ebuild
rename to app-eselect/eselect-php/eselect-php-0.7.1-r7.ebuild
index cd210279e6b8b2cdde8dd61b95f16bfcaf49245e..6937b4ad008160afdc3e97e33965e984316efd93 100644 (file)
@@ -33,7 +33,7 @@ src_install() {
        fi
 
        if use fpm ; then
-               newinitd "${FILESDIR}/php-fpm.init-r3" "php-fpm"
+               newinitd "${FILESDIR}/php-fpm.init-r4" "php-fpm"
                systemd_dotmpfilesd "${FILESDIR}/php-fpm.conf"
                exeinto /usr/libexec
                doexe "${FILESDIR}/php-fpm-launcher"
similarity index 67%
rename from app-eselect/eselect-php/files/php-fpm.init-r3
rename to app-eselect/eselect-php/files/php-fpm.init-r4
index a1b956ea78e48b5331d0f4f24cca302a80f86d62..6502ab9b7d0f0d8539a6958aa463b90327982f92 100644 (file)
@@ -6,7 +6,7 @@ extra_commands="configtest"
 set_phpvars() {
        PHPSLOT="${SVCNAME#php-fpm-}"
        PHP_FPM_PID="/run/php-fpm-${PHPSLOT}.pid"
-       if [ ${PHPSLOT} = 'php-fpm' ] ; then
+       if [ "${PHPSLOT}" = "php-fpm" ] ; then
                PHPSLOT="$(eselect php show fpm)"
                PHP_FPM_PID="/run/php-fpm.pid"
        fi
@@ -16,6 +16,9 @@ set_phpvars() {
 }
 
 start() {
+        # If configtest fails, we don't have to sit around for five
+        # seconds waiting for a pid to show up.
+        configtest || return $?
         ebegin "Starting PHP FastCGI Process Manager"
        set_phpvars
         start-stop-daemon --start --pidfile "${PHP_FPM_PID}" \
@@ -45,6 +48,7 @@ stop() {
 }
 
 reload() {
+    configtest || return $?
     ebegin "Reloading PHP FastCGI Process Manager"
     set_phpvars
     [ -f "${PHP_FPM_PID}" ] && kill -USR2 $(cat "${PHP_FPM_PID}")
@@ -54,6 +58,13 @@ reload() {
 configtest() {
     ebegin "Testing PHP FastCGI Process Manager configuration"
     set_phpvars
-    "${PHP_FPM_BIN}" --fpm-config "${PHP_FPM_CONF}" --test
-    eend $?
+    # Hide the "test is successful" message (which goes to stderr) if
+    # the test passed, but show the entire output if the test failed
+    # because it may contain hints about the problem.
+    OUTPUT=$( "${PHP_FPM_BIN}" --fpm-config "${PHP_FPM_CONF}" --test 2>&1 )
+
+    # Save this so `echo` doesn't clobber it.
+    local exit_code=$?
+    [ $exit_code -ne 0 ] && echo "${OUTPUT}" >&2
+    eend $exit_code
 }