summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJerome Loyet <fat@php.net>2012-09-28 00:53:05 +0200
committerJerome Loyet <fat@php.net>2012-09-28 00:53:05 +0200
commit64a0e7cdc2a90a13dd238068a7ff3d357de284b4 (patch)
treea041fcfd922060582f1e3d2e2f5a8551e58f117f
parentb5eb1456aa17e83b7b734dfc2316d632c9adcc6c (diff)
downloadphp-git-64a0e7cdc2a90a13dd238068a7ff3d357de284b4.tar.gz
- Fixed bug #63085 (Systemd integration and daemonize)
-rw-r--r--NEWS1
-rw-r--r--sapi/fpm/config.m42
-rw-r--r--sapi/fpm/fpm/fpm.c4
-rw-r--r--sapi/fpm/fpm/fpm.h2
-rw-r--r--sapi/fpm/fpm/fpm_conf.c11
-rw-r--r--sapi/fpm/fpm/fpm_conf.h2
-rw-r--r--sapi/fpm/fpm/fpm_main.c18
-rw-r--r--sapi/fpm/init.d.php-fpm.in2
-rw-r--r--sapi/fpm/php-fpm.8.in23
-rw-r--r--sapi/fpm/php-fpm.service.in12
10 files changed, 65 insertions, 12 deletions
diff --git a/NEWS b/NEWS
index cb534a4853..65ccc9a0d3 100644
--- a/NEWS
+++ b/NEWS
@@ -33,6 +33,7 @@ PHP NEWS
- FPM:
. Fixed bug #62954 (startup problems fpm / php-fpm). (fat)
. Fixed bug #62886 (PHP-FPM may segfault/hang on startup). (fat)
+ . Fixed bug #63085 (Systemd integration and daemonize). (remi, fat)
- OpenSSL:
. Implemented FR #61421 (OpenSSL signature verification missing RMD160,
diff --git a/sapi/fpm/config.m4 b/sapi/fpm/config.m4
index ad46717acd..3a2690ee22 100644
--- a/sapi/fpm/config.m4
+++ b/sapi/fpm/config.m4
@@ -589,7 +589,7 @@ if test "$PHP_FPM" != "no"; then
PHP_ADD_BUILD_DIR(sapi/fpm/fpm)
PHP_ADD_BUILD_DIR(sapi/fpm/fpm/events)
- PHP_OUTPUT(sapi/fpm/php-fpm.conf sapi/fpm/init.d.php-fpm sapi/fpm/php-fpm.8 sapi/fpm/status.html)
+ PHP_OUTPUT(sapi/fpm/php-fpm.conf sapi/fpm/init.d.php-fpm sapi/fpm/php-fpm.service sapi/fpm/php-fpm.8 sapi/fpm/status.html)
PHP_ADD_MAKEFILE_FRAGMENT([$abs_srcdir/sapi/fpm/Makefile.frag])
SAPI_FPM_PATH=sapi/fpm/php-fpm
diff --git a/sapi/fpm/fpm/fpm.c b/sapi/fpm/fpm/fpm.c
index 2f42175d89..b866f37f2d 100644
--- a/sapi/fpm/fpm/fpm.c
+++ b/sapi/fpm/fpm/fpm.c
@@ -42,7 +42,7 @@ struct fpm_globals_s fpm_globals = {
.send_config_pipe = {0, 0},
};
-int fpm_init(int argc, char **argv, char *config, char *prefix, char *pid, int test_conf, int run_as_root) /* {{{ */
+int fpm_init(int argc, char **argv, char *config, char *prefix, char *pid, int test_conf, int run_as_root, int force_daemon) /* {{{ */
{
fpm_globals.argc = argc;
fpm_globals.argv = argv;
@@ -55,7 +55,7 @@ int fpm_init(int argc, char **argv, char *config, char *prefix, char *pid, int t
if (0 > fpm_php_init_main() ||
0 > fpm_stdio_init_main() ||
- 0 > fpm_conf_init_main(test_conf) ||
+ 0 > fpm_conf_init_main(test_conf, force_daemon) ||
0 > fpm_unix_init_main() ||
0 > fpm_scoreboard_init_main() ||
0 > fpm_pctl_init_main() ||
diff --git a/sapi/fpm/fpm/fpm.h b/sapi/fpm/fpm/fpm.h
index c576876386..65d0e0d691 100644
--- a/sapi/fpm/fpm/fpm.h
+++ b/sapi/fpm/fpm/fpm.h
@@ -37,7 +37,7 @@
int fpm_run(int *max_requests);
-int fpm_init(int argc, char **argv, char *config, char *prefix, char *pid, int test_conf, int run_as_root);
+int fpm_init(int argc, char **argv, char *config, char *prefix, char *pid, int test_conf, int run_as_root, int force_daemon);
struct fpm_globals_s {
pid_t parent_pid;
diff --git a/sapi/fpm/fpm/fpm_conf.c b/sapi/fpm/fpm/fpm_conf.c
index dfe6792c05..25e2cc43a1 100644
--- a/sapi/fpm/fpm/fpm_conf.c
+++ b/sapi/fpm/fpm/fpm_conf.c
@@ -1115,7 +1115,7 @@ int fpm_conf_write_pid() /* {{{ */
}
/* }}} */
-static int fpm_conf_post_process(TSRMLS_D) /* {{{ */
+static int fpm_conf_post_process(int force_daemon TSRMLS_DC) /* {{{ */
{
struct fpm_worker_pool_s *wp;
@@ -1123,6 +1123,11 @@ static int fpm_conf_post_process(TSRMLS_D) /* {{{ */
fpm_evaluate_full_path(&fpm_global_config.pid_file, NULL, PHP_LOCALSTATEDIR, 0);
}
+ if (force_daemon >= 0) {
+ /* forced from command line options */
+ fpm_global_config.daemonize = force_daemon;
+ }
+
fpm_globals.log_level = fpm_global_config.log_level;
if (fpm_global_config.process_max < 0) {
@@ -1584,7 +1589,7 @@ static void fpm_conf_dump() /* {{{ */
}
/* }}} */
-int fpm_conf_init_main(int test_conf) /* {{{ */
+int fpm_conf_init_main(int test_conf, int force_daemon) /* {{{ */
{
int ret;
TSRMLS_FETCH();
@@ -1630,7 +1635,7 @@ int fpm_conf_init_main(int test_conf) /* {{{ */
return -1;
}
- if (0 > fpm_conf_post_process(TSRMLS_C)) {
+ if (0 > fpm_conf_post_process(force_daemon TSRMLS_CC)) {
zlog(ZLOG_ERROR, "failed to post process the configuration");
return -1;
}
diff --git a/sapi/fpm/fpm/fpm_conf.h b/sapi/fpm/fpm/fpm_conf.h
index f780f03891..dc54133d43 100644
--- a/sapi/fpm/fpm/fpm_conf.h
+++ b/sapi/fpm/fpm/fpm_conf.h
@@ -97,7 +97,7 @@ enum {
PM_STYLE_ONDEMAND = 3
};
-int fpm_conf_init_main(int test_conf);
+int fpm_conf_init_main(int test_conf, int force_daemon);
int fpm_worker_pool_config_free(struct fpm_worker_pool_config_s *wpc);
int fpm_conf_write_pid();
int fpm_conf_unlink_pid();
diff --git a/sapi/fpm/fpm/fpm_main.c b/sapi/fpm/fpm/fpm_main.c
index 925cbc1b74..edd75be5ae 100644
--- a/sapi/fpm/fpm/fpm_main.c
+++ b/sapi/fpm/fpm/fpm_main.c
@@ -155,6 +155,8 @@ static const opt_struct OPTIONS[] = {
{'p', 1, "prefix"},
{'g', 1, "pid"},
{'R', 0, "allow-to-run-as-root"},
+ {'D', 0, "daemonize"},
+ {'F', 0, "nodaemonize"},
{'-', 0, NULL} /* end of args */
};
@@ -912,7 +914,7 @@ static void php_cgi_usage(char *argv0)
prog = "php";
}
- php_printf( "Usage: %s [-n] [-e] [-h] [-i] [-m] [-v] [-t] [-p <prefix>] [-g <pid>] [-c <file>] [-d foo[=bar]] [-y <file>]\n"
+ php_printf( "Usage: %s [-n] [-e] [-h] [-i] [-m] [-v] [-t] [-p <prefix>] [-g <pid>] [-c <file>] [-d foo[=bar]] [-y <file>] [-D] [-F]\n"
" -c <path>|<file> Look for php.ini file in this directory\n"
" -n No php.ini file will be used\n"
" -d foo[=bar] Define INI entry foo with value 'bar'\n"
@@ -928,6 +930,9 @@ static void php_cgi_usage(char *argv0)
" -y, --fpm-config <file>\n"
" Specify alternative path to FastCGI process manager config file.\n"
" -t, --test Test FPM configuration and exit\n"
+ " -D, --daemonize force to run in background, and ignore daemonize option from config file\n"
+ " -F, --nodaemonize\n"
+ " force to stay in foreground, and ignore daemonize option from config file\n"
" -R, --allow-to-run-as-root\n"
" Allow pool to run as root (disabled by default)\n",
prog, PHP_PREFIX);
@@ -1550,6 +1555,7 @@ int main(int argc, char *argv[])
char *fpm_prefix = NULL;
char *fpm_pid = NULL;
int test_conf = 0;
+ int force_daemon = -1;
int php_information = 0;
int php_allow_to_run_as_root = 0;
@@ -1670,6 +1676,14 @@ int main(int argc, char *argv[])
php_allow_to_run_as_root = 1;
break;
+ case 'D': /* daemonize */
+ force_daemon = 1;
+ break;
+
+ case 'F': /* nodaemonize */
+ force_daemon = 0;
+ break;
+
default:
case 'h':
case '?':
@@ -1797,7 +1811,7 @@ consult the installation file that came with this distribution, or visit \n\
}
}
- if (0 > fpm_init(argc, argv, fpm_config ? fpm_config : CGIG(fpm_config), fpm_prefix, fpm_pid, test_conf, php_allow_to_run_as_root)) {
+ if (0 > fpm_init(argc, argv, fpm_config ? fpm_config : CGIG(fpm_config), fpm_prefix, fpm_pid, test_conf, php_allow_to_run_as_root, force_daemon)) {
if (fpm_globals.send_config_pipe[1]) {
int writeval = 0;
diff --git a/sapi/fpm/init.d.php-fpm.in b/sapi/fpm/init.d.php-fpm.in
index dc66310c3d..3edd64fe19 100644
--- a/sapi/fpm/init.d.php-fpm.in
+++ b/sapi/fpm/init.d.php-fpm.in
@@ -54,7 +54,7 @@ case "$1" in
start)
echo -n "Starting php-fpm "
- $php_fpm_BIN $php_opts
+ $php_fpm_BIN --daemonize $php_opts
if [ "$?" != 0 ] ; then
echo " failed"
diff --git a/sapi/fpm/php-fpm.8.in b/sapi/fpm/php-fpm.8.in
index 6c9c6d6274..a4e7e74e20 100644
--- a/sapi/fpm/php-fpm.8.in
+++ b/sapi/fpm/php-fpm.8.in
@@ -99,6 +99,20 @@ Test FPM configuration file and exit
If called twice (-tt), the configuration is dumped before exiting.
.TP
.PD 0
+.B \-\-daemonize
+.TP
+.PD 1
+.B \-D
+Force to run in background and ignore daemonize option from configuration file.
+.TP
+.PD 0
+.B \-\-nodaemonize
+.TP
+.PD 1
+.B \-F
+Force to stay in foreground and ignore daemonize option from configuration file.
+.TP
+.PD 0
.B \-\-zend\-extension \fIfile\fP
.TP
.PD 1
@@ -113,13 +127,20 @@ The configuration file for the php-fpm daemon.
.B php.ini
The standard php configuration file.
.SH EXAMPLES
-You should use the init script provided to start and stop the php-fpm daemon. This situation applies for any unix systems which use init.d for their main process manager.
+For any unix systems which use init.d for their main process manager, you should use the init script provided to start and stop the php-fpm daemon.
.P
.PD 1
.RS
sudo /etc/init.d/php-fpm start
.RE
.TP
+For any unix systems which use systemd for their main process manager, you should use the unit file provided to start and stop the php-fpm daemon.
+.P
+.PD 1
+.RS
+sudo systemctl start php-fpm.service
+.RE
+.TP
If your installation has no appropriate init script, launch php-fpm with no arguments. It will launch as a daemon (background process) by default. The file @php_fpm_localstatedir@/run/php-fpm.pid determines whether php-fpm is already up and running. Once started, php-fpm then responds to several POSIX signals:
.P
.PD 0
diff --git a/sapi/fpm/php-fpm.service.in b/sapi/fpm/php-fpm.service.in
new file mode 100644
index 0000000000..396a88d66f
--- /dev/null
+++ b/sapi/fpm/php-fpm.service.in
@@ -0,0 +1,12 @@
+[Unit]
+Description=The PHP FastCGI Process Manager
+After=syslog.target network.target
+
+[Service]
+PIDFile=@localstatedir@/run/php-fpm.pid
+ExecStart=@sbindir@/php-fpm --nodaemonize --fpm-config @sysconfdir@/php-fpm.conf
+ExecReload=/bin/kill -USR2 $MAINPID
+
+[Install]
+WantedBy=multi-user.target
+