Permalink
Browse files

- Fixed bug #63085 (Systemd integration and daemonize)

  • Loading branch information...
1 parent b5eb145 commit 64a0e7cdc2a90a13dd238068a7ff3d357de284b4 Jerome Loyet committed Sep 27, 2012
View
1 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,
View
@@ -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
View
@@ -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() ||
View
@@ -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;
View
@@ -1115,14 +1115,19 @@ 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;
if (fpm_global_config.pid_file) {
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;
}
View
@@ -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();
View
@@ -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;
@@ -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"
View
@@ -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
@@ -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
+

0 comments on commit 64a0e7c

Please sign in to comment.