* [gentoo-commits] proj/eselect-php:master commit in: doc/
@ 2017-07-25 0:39 Michael Orlitzky
0 siblings, 0 replies; 3+ messages in thread
From: Michael Orlitzky @ 2017-07-25 0:39 UTC (permalink / raw
To: gentoo-commits
commit: 82305f92b39198151b4c3c5d48a2973dfd043ac9
Author: Michael Orlitzky <mjo <AT> gentoo <DOT> org>
AuthorDate: Tue Jul 25 00:27:21 2017 +0000
Commit: Michael Orlitzky <mjo <AT> gentoo <DOT> org>
CommitDate: Tue Jul 25 00:38:49 2017 +0000
URL: https://gitweb.gentoo.org/proj/eselect-php.git/commit/?id=82305f92
Rewrite the php-fpm init script to be more declarative.
Modern OpenRC can start/stop a well-behaved daemon on its own,
provided the right command and parameters. This commit updates the
init script to use those OpenRC variables like "command",
"command_args", and "pidfile", and the resulting init script is much
more concise.
doc/php-fpm.example.init.in.in | 97 +++++++++++++++++++-----------------------
1 file changed, 43 insertions(+), 54 deletions(-)
diff --git a/doc/php-fpm.example.init.in.in b/doc/php-fpm.example.init.in.in
index 912a5d8..add56b4 100644
--- a/doc/php-fpm.example.init.in.in
+++ b/doc/php-fpm.example.init.in.in
@@ -1,71 +1,60 @@
#!/sbin/openrc-run
+#
+# We support both slot-agnostic and slotted versions of the init
+# script. The slotted versions would be named something like
+# php-fpm-php7.1, and PHP_SLOT below would be set to "php7.1". But we
+# also support a general init script named "php-fpm" that uses
+# whatever the currently-eselected fpm implementation is. In that
+# case, PHP_SLOT winds up set to "php-fpm" and we need to get the
+# actual slot by querying eselect.
+#
+# An open question is, what should we do if the user has both a
+# slot-agnostic and slotted init script, which happen to point to the
+# same slot? In other words, if the user has a php-fpm init script and
+# slot php7.1 eselected, but also a php-fpm-php7.1 init script. Should
+# they manage the same instance? I think so...
+#
+PHP_SLOT="${SVCNAME#php-fpm-}"
+if [ "${PHP_SLOT}" = "php-fpm" ] ; then
+ PHP_SLOT="$(eselect php show fpm)"
+fi
+
+PHP_FPM_CONF="@SYSCONFDIR@/php/fpm-${PHP_SLOT}/php-fpm.conf"
+
+command="@LIBDIR@/${PHP_SLOT}/bin/php-fpm"
+pidfile="/run/php-fpm-${PHP_SLOT}.pid"
+
+# Force the daemon into the background and make it use our pid file,
+# regardless of what the config file says.
+command_args="--fpm-config ${PHP_FPM_CONF} --pid ${pidfile} --daemonize"
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 $?
-}
+# Wait five seconds after starting for the pidfile to show up.
+start_stop_daemon_args="--wait 5000 ${PHP_FPM_UMASK:+--umask ${PHP_FPM_UMASK}}"
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 )
+ OUTPUT=$( ${command} ${command_args} --test 2>&1 )
# Save this so `echo` doesn't clobber it.
local exit_code=$?
[ $exit_code -ne 0 ] && echo "${OUTPUT}" >&2
eend $exit_code
}
+
+start_pre() {
+ configtest || return $?
+}
+
+reload() {
+ configtest || return $?
+ ebegin "Reloading PHP FastCGI Process Manager"
+ start-stop-daemon --signal USR2 --pidfile "${pidfile}"
+ eend $?
+}
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [gentoo-commits] proj/eselect-php:master commit in: doc/
@ 2017-07-25 1:41 Brian Evans
0 siblings, 0 replies; 3+ messages in thread
From: Brian Evans @ 2017-07-25 1:41 UTC (permalink / raw
To: gentoo-commits
commit: 73f459d68b6c2a659511f2ab2ea085b3ca997f9d
Author: Brian Evans <grknight <AT> tuffmail <DOT> com>
AuthorDate: Tue Jul 25 01:40:55 2017 +0000
Commit: Brian Evans <grknight <AT> gentoo <DOT> org>
CommitDate: Tue Jul 25 01:40:55 2017 +0000
URL: https://gitweb.gentoo.org/proj/eselect-php.git/commit/?id=73f459d6
Don't allow restart with a bad config
doc/php-fpm.example.init.in.in | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/doc/php-fpm.example.init.in.in b/doc/php-fpm.example.init.in.in
index 04fb26f..859ee5a 100644
--- a/doc/php-fpm.example.init.in.in
+++ b/doc/php-fpm.example.init.in.in
@@ -49,7 +49,15 @@ configtest() {
}
start_pre() {
- configtest || return $?
+ if [ "${RC_CMD}" != "restart" ] ; then
+ configtest || return $?
+ fi
+}
+
+stop_pre() {
+ if [ "${RC_CMD}" = "restart" ] ; then
+ configtest || return $?
+ fi
}
reload() {
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [gentoo-commits] proj/eselect-php:master commit in: doc/
@ 2017-07-25 1:46 Michael Orlitzky
0 siblings, 0 replies; 3+ messages in thread
From: Michael Orlitzky @ 2017-07-25 1:46 UTC (permalink / raw
To: gentoo-commits
commit: 26a7928561a2d06f3a5eab6824430bf59f11753c
Author: Michael Orlitzky <mjo <AT> gentoo <DOT> org>
AuthorDate: Tue Jul 25 01:43:54 2017 +0000
Commit: Michael Orlitzky <mjo <AT> gentoo <DOT> org>
CommitDate: Tue Jul 25 01:43:54 2017 +0000
URL: https://gitweb.gentoo.org/proj/eselect-php.git/commit/?id=26a79285
Add comments to the php-fpm init script's start/stop_pre functions.
Had a mid-air collision with Brian there where we both tried to
implement exactly the same thing. I had some extra comments explaining
the RC_CMD tests that happily apply right on top of the last commit.
doc/php-fpm.example.init.in.in | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/doc/php-fpm.example.init.in.in b/doc/php-fpm.example.init.in.in
index 859ee5a..2eaa2c3 100644
--- a/doc/php-fpm.example.init.in.in
+++ b/doc/php-fpm.example.init.in.in
@@ -49,12 +49,21 @@ configtest() {
}
start_pre() {
+ # If this isn't a restart, make sure that the user's config isn't
+ # busted before we try to start the daemon (this will produce
+ # better error messages than if we just try to start it blindly).
+ #
+ # If, on the other hand, this *is* a restart, then the stop_pre
+ # action will have ensured that the config is usable and we don't
+ # need to do that again.
if [ "${RC_CMD}" != "restart" ] ; then
configtest || return $?
fi
}
stop_pre() {
+ # If this is a restart, check to make sure the user's config
+ # isn't busted before we stop the running daemon.
if [ "${RC_CMD}" = "restart" ] ; then
configtest || return $?
fi
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-07-25 1:46 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-07-25 1:41 [gentoo-commits] proj/eselect-php:master commit in: doc/ Brian Evans
-- strict thread matches above, loose matches on Subject: below --
2017-07-25 1:46 Michael Orlitzky
2017-07-25 0:39 Michael Orlitzky
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox