summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Evans <grknight@gentoo.org>2017-07-11 09:50:53 -0400
committerBrian Evans <grknight@gentoo.org>2017-07-11 09:50:53 -0400
commit77dbce75a224125eb6a6540e93367294b4b5331d (patch)
tree1fc01ca284b4500ae228cc23987fd5585b81f8b3 /doc/php-fpm.example.init.in
parentBump version to 0.9.2 in configure.ac. (diff)
downloadeselect-php-77dbce75a224125eb6a6540e93367294b4b5331d.tar.gz
eselect-php-77dbce75a224125eb6a6540e93367294b4b5331d.tar.bz2
eselect-php-77dbce75a224125eb6a6540e93367294b4b5331d.zip
Make the init script directory depend on LIBDIR
We cannot rely on the assumption that /usr/lib will always point to the right location, Bug 624528 demonstrates this. There is talk in Bug 506276 of making /usr/lib a generic target for all arches and stop supporting the symlink.
Diffstat (limited to 'doc/php-fpm.example.init.in')
-rw-r--r--doc/php-fpm.example.init.in71
1 files changed, 71 insertions, 0 deletions
diff --git a/doc/php-fpm.example.init.in b/doc/php-fpm.example.init.in
new file mode 100644
index 0000000..7969b71
--- /dev/null
+++ b/doc/php-fpm.example.init.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="/etc/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
+}