From 41fa94bb1977c31b3a280005585187d00df2424e Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Wed, 19 Jul 2017 10:02:44 -0400 Subject: Rename the init script input file to facilitate the two-phase replacement. We perform variable substitution twice in the main eselect script -- once through autotools, and the other manually in the resulting Makefile. As a result, the script has a double "in.in" suffix. To make substitution work the same way in the init script, this commit renames it with an "in.in" suffix, and mentions it in configure.ac. --- configure.ac | 2 +- doc/php-fpm.example.init.in | 71 ------------------------------------------ doc/php-fpm.example.init.in.in | 71 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+), 72 deletions(-) delete mode 100644 doc/php-fpm.example.init.in create mode 100644 doc/php-fpm.example.init.in.in diff --git a/configure.ac b/configure.ac index d642dbd..9f8b4eb 100644 --- a/configure.ac +++ b/configure.ac @@ -22,6 +22,6 @@ AC_ARG_ENABLE( # List of output files. -AC_CONFIG_FILES([Makefile src/php.eselect.in]) +AC_CONFIG_FILES([Makefile src/php.eselect.in doc/php-fpm.example.init.in]) AC_OUTPUT diff --git a/doc/php-fpm.example.init.in b/doc/php-fpm.example.init.in deleted file mode 100644 index 912a5d8..0000000 --- a/doc/php-fpm.example.init.in +++ /dev/null @@ -1,71 +0,0 @@ -#!/sbin/openrc-run - -extra_started_commands="reload" -extra_commands="configtest" - -set_phpvars() { - PHPSLOT="${SVCNAME#php-fpm-}" - PHP_FPM_PID="/run/php-fpm-${PHPSLOT}.pid" - if [ "${PHPSLOT}" = "php-fpm" ] ; then - PHPSLOT="$(eselect php show fpm)" - PHP_FPM_PID="/run/php-fpm.pid" - fi - - PHP_FPM_CONF="@SYSCONFDIR@/php/fpm-${PHPSLOT}/php-fpm.conf" - PHP_FPM_BIN="@LIBDIR@/${PHPSLOT}/bin/php-fpm" -} - -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}" \ - --exec "${PHP_FPM_BIN}" \ - ${PHP_FPM_UMASK:+--umask ${PHP_FPM_UMASK}} \ - -- \ - --fpm-config "${PHP_FPM_CONF}" \ - --pid "${PHP_FPM_PID}" - local i=0 - local timeout=5 - while [ ! -f "${PHP_FPM_PID}" ] && [ $i -le $timeout ]; do - sleep 1 - i=$(($i + 1)) - done - - [ $timeout -gt $i ] - eend $? -} - -stop() { - ebegin "Stopping PHP FastCGI Process Manager" - set_phpvars - start-stop-daemon --signal QUIT \ - --stop \ - --exec "${PHP_FPM_BIN}" \ - --pidfile "${PHP_FPM_PID}" - eend $? -} - -reload() { - configtest || return $? - ebegin "Reloading PHP FastCGI Process Manager" - set_phpvars - [ -f "${PHP_FPM_PID}" ] && kill -USR2 $(cat "${PHP_FPM_PID}") - eend $? -} - -configtest() { - ebegin "Testing PHP FastCGI Process Manager configuration" - set_phpvars - # 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 -} diff --git a/doc/php-fpm.example.init.in.in b/doc/php-fpm.example.init.in.in new file mode 100644 index 0000000..912a5d8 --- /dev/null +++ b/doc/php-fpm.example.init.in.in @@ -0,0 +1,71 @@ +#!/sbin/openrc-run + +extra_started_commands="reload" +extra_commands="configtest" + +set_phpvars() { + PHPSLOT="${SVCNAME#php-fpm-}" + PHP_FPM_PID="/run/php-fpm-${PHPSLOT}.pid" + if [ "${PHPSLOT}" = "php-fpm" ] ; then + PHPSLOT="$(eselect php show fpm)" + PHP_FPM_PID="/run/php-fpm.pid" + fi + + PHP_FPM_CONF="@SYSCONFDIR@/php/fpm-${PHPSLOT}/php-fpm.conf" + PHP_FPM_BIN="@LIBDIR@/${PHPSLOT}/bin/php-fpm" +} + +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}" \ + --exec "${PHP_FPM_BIN}" \ + ${PHP_FPM_UMASK:+--umask ${PHP_FPM_UMASK}} \ + -- \ + --fpm-config "${PHP_FPM_CONF}" \ + --pid "${PHP_FPM_PID}" + local i=0 + local timeout=5 + while [ ! -f "${PHP_FPM_PID}" ] && [ $i -le $timeout ]; do + sleep 1 + i=$(($i + 1)) + done + + [ $timeout -gt $i ] + eend $? +} + +stop() { + ebegin "Stopping PHP FastCGI Process Manager" + set_phpvars + start-stop-daemon --signal QUIT \ + --stop \ + --exec "${PHP_FPM_BIN}" \ + --pidfile "${PHP_FPM_PID}" + eend $? +} + +reload() { + configtest || return $? + ebegin "Reloading PHP FastCGI Process Manager" + set_phpvars + [ -f "${PHP_FPM_PID}" ] && kill -USR2 $(cat "${PHP_FPM_PID}") + eend $? +} + +configtest() { + ebegin "Testing PHP FastCGI Process Manager configuration" + set_phpvars + # 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 +} -- cgit v1.2.3-65-gdbad