mirror of
https://github.com/php/php-src.git
synced 2024-11-24 10:24:11 +08:00
- Fixed bug #63085 (Systemd integration and daemonize)
This commit is contained in:
parent
b5eb1456aa
commit
64a0e7cdc2
1
NEWS
1
NEWS
@ -33,6 +33,7 @@ PHP NEWS
|
|||||||
- FPM:
|
- FPM:
|
||||||
. Fixed bug #62954 (startup problems fpm / php-fpm). (fat)
|
. Fixed bug #62954 (startup problems fpm / php-fpm). (fat)
|
||||||
. Fixed bug #62886 (PHP-FPM may segfault/hang on startup). (fat)
|
. Fixed bug #62886 (PHP-FPM may segfault/hang on startup). (fat)
|
||||||
|
. Fixed bug #63085 (Systemd integration and daemonize). (remi, fat)
|
||||||
|
|
||||||
- OpenSSL:
|
- OpenSSL:
|
||||||
. Implemented FR #61421 (OpenSSL signature verification missing RMD160,
|
. Implemented FR #61421 (OpenSSL signature verification missing RMD160,
|
||||||
|
@ -589,7 +589,7 @@ if test "$PHP_FPM" != "no"; then
|
|||||||
|
|
||||||
PHP_ADD_BUILD_DIR(sapi/fpm/fpm)
|
PHP_ADD_BUILD_DIR(sapi/fpm/fpm)
|
||||||
PHP_ADD_BUILD_DIR(sapi/fpm/fpm/events)
|
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])
|
PHP_ADD_MAKEFILE_FRAGMENT([$abs_srcdir/sapi/fpm/Makefile.frag])
|
||||||
|
|
||||||
SAPI_FPM_PATH=sapi/fpm/php-fpm
|
SAPI_FPM_PATH=sapi/fpm/php-fpm
|
||||||
|
@ -42,7 +42,7 @@ struct fpm_globals_s fpm_globals = {
|
|||||||
.send_config_pipe = {0, 0},
|
.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.argc = argc;
|
||||||
fpm_globals.argv = argv;
|
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() ||
|
if (0 > fpm_php_init_main() ||
|
||||||
0 > fpm_stdio_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_unix_init_main() ||
|
||||||
0 > fpm_scoreboard_init_main() ||
|
0 > fpm_scoreboard_init_main() ||
|
||||||
0 > fpm_pctl_init_main() ||
|
0 > fpm_pctl_init_main() ||
|
||||||
|
@ -37,7 +37,7 @@
|
|||||||
|
|
||||||
|
|
||||||
int fpm_run(int *max_requests);
|
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 {
|
struct fpm_globals_s {
|
||||||
pid_t parent_pid;
|
pid_t parent_pid;
|
||||||
|
@ -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;
|
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);
|
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;
|
fpm_globals.log_level = fpm_global_config.log_level;
|
||||||
|
|
||||||
if (fpm_global_config.process_max < 0) {
|
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;
|
int ret;
|
||||||
TSRMLS_FETCH();
|
TSRMLS_FETCH();
|
||||||
@ -1630,7 +1635,7 @@ int fpm_conf_init_main(int test_conf) /* {{{ */
|
|||||||
return -1;
|
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");
|
zlog(ZLOG_ERROR, "failed to post process the configuration");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -97,7 +97,7 @@ enum {
|
|||||||
PM_STYLE_ONDEMAND = 3
|
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_worker_pool_config_free(struct fpm_worker_pool_config_s *wpc);
|
||||||
int fpm_conf_write_pid();
|
int fpm_conf_write_pid();
|
||||||
int fpm_conf_unlink_pid();
|
int fpm_conf_unlink_pid();
|
||||||
|
@ -155,6 +155,8 @@ static const opt_struct OPTIONS[] = {
|
|||||||
{'p', 1, "prefix"},
|
{'p', 1, "prefix"},
|
||||||
{'g', 1, "pid"},
|
{'g', 1, "pid"},
|
||||||
{'R', 0, "allow-to-run-as-root"},
|
{'R', 0, "allow-to-run-as-root"},
|
||||||
|
{'D', 0, "daemonize"},
|
||||||
|
{'F', 0, "nodaemonize"},
|
||||||
{'-', 0, NULL} /* end of args */
|
{'-', 0, NULL} /* end of args */
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -912,7 +914,7 @@ static void php_cgi_usage(char *argv0)
|
|||||||
prog = "php";
|
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"
|
" -c <path>|<file> Look for php.ini file in this directory\n"
|
||||||
" -n No php.ini file will be used\n"
|
" -n No php.ini file will be used\n"
|
||||||
" -d foo[=bar] Define INI entry foo with value 'bar'\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"
|
" -y, --fpm-config <file>\n"
|
||||||
" Specify alternative path to FastCGI process manager config file.\n"
|
" Specify alternative path to FastCGI process manager config file.\n"
|
||||||
" -t, --test Test FPM configuration and exit\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"
|
" -R, --allow-to-run-as-root\n"
|
||||||
" Allow pool to run as root (disabled by default)\n",
|
" Allow pool to run as root (disabled by default)\n",
|
||||||
prog, PHP_PREFIX);
|
prog, PHP_PREFIX);
|
||||||
@ -1550,6 +1555,7 @@ int main(int argc, char *argv[])
|
|||||||
char *fpm_prefix = NULL;
|
char *fpm_prefix = NULL;
|
||||||
char *fpm_pid = NULL;
|
char *fpm_pid = NULL;
|
||||||
int test_conf = 0;
|
int test_conf = 0;
|
||||||
|
int force_daemon = -1;
|
||||||
int php_information = 0;
|
int php_information = 0;
|
||||||
int php_allow_to_run_as_root = 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;
|
php_allow_to_run_as_root = 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'D': /* daemonize */
|
||||||
|
force_daemon = 1;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'F': /* nodaemonize */
|
||||||
|
force_daemon = 0;
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
case 'h':
|
case 'h':
|
||||||
case '?':
|
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]) {
|
if (fpm_globals.send_config_pipe[1]) {
|
||||||
int writeval = 0;
|
int writeval = 0;
|
||||||
|
@ -54,7 +54,7 @@ case "$1" in
|
|||||||
start)
|
start)
|
||||||
echo -n "Starting php-fpm "
|
echo -n "Starting php-fpm "
|
||||||
|
|
||||||
$php_fpm_BIN $php_opts
|
$php_fpm_BIN --daemonize $php_opts
|
||||||
|
|
||||||
if [ "$?" != 0 ] ; then
|
if [ "$?" != 0 ] ; then
|
||||||
echo " failed"
|
echo " failed"
|
||||||
|
@ -99,6 +99,20 @@ Test FPM configuration file and exit
|
|||||||
If called twice (-tt), the configuration is dumped before exiting.
|
If called twice (-tt), the configuration is dumped before exiting.
|
||||||
.TP
|
.TP
|
||||||
.PD 0
|
.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
|
.B \-\-zend\-extension \fIfile\fP
|
||||||
.TP
|
.TP
|
||||||
.PD 1
|
.PD 1
|
||||||
@ -113,13 +127,20 @@ The configuration file for the php-fpm daemon.
|
|||||||
.B php.ini
|
.B php.ini
|
||||||
The standard php configuration file.
|
The standard php configuration file.
|
||||||
.SH EXAMPLES
|
.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
|
.P
|
||||||
.PD 1
|
.PD 1
|
||||||
.RS
|
.RS
|
||||||
sudo /etc/init.d/php-fpm start
|
sudo /etc/init.d/php-fpm start
|
||||||
.RE
|
.RE
|
||||||
.TP
|
.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:
|
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
|
.P
|
||||||
.PD 0
|
.PD 0
|
||||||
|
12
sapi/fpm/php-fpm.service.in
Normal file
12
sapi/fpm/php-fpm.service.in
Normal file
@ -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
|
||||||
|
|
Loading…
Reference in New Issue
Block a user