php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #63085
Patch php-fpm-systemd.patch revision 2012-09-19 15:00 UTC by remi@php.net
Patch php-fpm.service revision 2012-09-14 05:41 UTC by remi@php.net

Patch php-fpm-systemd.patch for FPM related Bug #63085

Patch version 2012-09-19 15:00 UTC

Return to Bug #63085 | Download this patch
Patch Revisions:

Developer: remi@php.net

diff -Nru sapi/fpm.old/config.m4 sapi/fpm/config.m4
--- sapi/fpm.old/config.m4	2012-09-19 15:53:48.001758347 +0200
+++ sapi/fpm/config.m4	2012-09-19 16:18:57.661936394 +0200
@@ -589,7 +589,7 @@
 
   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 -Nru sapi/fpm.old/fpm/fpm.c sapi/fpm/fpm/fpm.c
--- sapi/fpm.old/fpm/fpm.c	2012-09-19 15:53:48.000758297 +0200
+++ sapi/fpm/fpm/fpm.c	2012-09-19 16:09:57.462102346 +0200
@@ -42,7 +42,7 @@
 	.send_config_signal = 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 @@
 
 	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 -Nru sapi/fpm.old/fpm/fpm_conf.c sapi/fpm/fpm/fpm_conf.c
--- sapi/fpm.old/fpm/fpm_conf.c	2012-09-19 15:53:48.000758297 +0200
+++ sapi/fpm/fpm/fpm_conf.c	2012-09-19 16:08:46.034854345 +0200
@@ -1115,7 +1115,7 @@
 }
 /* }}} */
 
-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 @@
 		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 @@
 }
 /* }}} */
 
-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 @@
 		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 -Nru sapi/fpm.old/fpm/fpm_conf.h sapi/fpm/fpm/fpm_conf.h
--- sapi/fpm.old/fpm/fpm_conf.h	2012-09-19 15:53:48.000758297 +0200
+++ sapi/fpm/fpm/fpm_conf.h	2012-09-19 16:05:29.874174589 +0200
@@ -97,7 +97,7 @@
 	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 -Nru sapi/fpm.old/fpm/fpm.h sapi/fpm/fpm/fpm.h
--- sapi/fpm.old/fpm/fpm.h	2012-09-19 15:53:48.000758297 +0200
+++ sapi/fpm/fpm/fpm.h	2012-09-19 16:02:06.113470905 +0200
@@ -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 -Nru sapi/fpm.old/fpm/fpm_main.c sapi/fpm/fpm/fpm_main.c
--- sapi/fpm.old/fpm/fpm_main.c	2012-09-19 15:53:47.999758244 +0200
+++ sapi/fpm/fpm/fpm_main.c	2012-09-19 16:29:52.595853439 +0200
@@ -155,6 +155,8 @@
 	{'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 @@
 		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 @@
 				"  -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 @@
 	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 @@
 				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 @@
 		}
 	}
 
-	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_signal) {
 			zlog(ZLOG_DEBUG, "Sending SIGUSR2 (error) to parent %d", getppid());
diff -Nru sapi/fpm.old/init.d.php-fpm.in sapi/fpm/init.d.php-fpm.in
--- sapi/fpm.old/init.d.php-fpm.in	2012-09-19 15:53:47.998758183 +0200
+++ sapi/fpm/init.d.php-fpm.in	2012-09-19 16:12:13.356570094 +0200
@@ -54,7 +54,7 @@
 	start)
 		echo -n "Starting php-fpm "
 
-		$php_fpm_BIN $php_opts
+		$php_fpm_BIN --daemonize $php_opts
 
 		if [ "$?" != 0 ] ; then
 			echo " failed"
diff -Nru sapi/fpm.old/php-fpm.8.in sapi/fpm/php-fpm.8.in
--- sapi/fpm.old/php-fpm.8.in	2012-09-19 15:53:47.998758183 +0200
+++ sapi/fpm/php-fpm.8.in	2012-09-19 16:40:57.865863325 +0200
@@ -99,6 +99,20 @@
 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 @@
 .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 -Nru sapi/fpm.old/php-fpm.service.in sapi/fpm/php-fpm.service.in
--- sapi/fpm.old/php-fpm.service.in	1970-01-01 01:00:00.000000000 +0100
+++ sapi/fpm/php-fpm.service.in	2012-09-19 16:21:32.140467558 +0200
@@ -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
+
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Dec 04 15:01:30 2024 UTC