summaryrefslogtreecommitdiffstats
path: root/php-5.4.7-fpm-systemd.patch
blob: 0cbe96f6740fa129ed29e585d1055d4e6ed90351 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
From 851a04bb7b680954249e825ea3fef420f7d66bb7 Mon Sep 17 00:00:00 2001
From: Jerome Loyet <fat@php.net>
Date: Fri, 28 Sep 2012 00:33:05 +0200
Subject: [PATCH] - Fixed bug #63085 (Systemd integration and daemonize)

---
 NEWS                       |    1 +
 sapi/fpm/config.m4         |    2 +-
 sapi/fpm/fpm/fpm.c         |    4 ++--
 sapi/fpm/fpm/fpm.h         |    2 +-
 sapi/fpm/fpm/fpm_conf.c    |   11 ++++++++---
 sapi/fpm/fpm/fpm_conf.h    |    2 +-
 sapi/fpm/fpm/fpm_main.c    |   18 ++++++++++++++++--
 sapi/fpm/init.d.php-fpm.in |    2 +-
 sapi/fpm/php-fpm.8.in      |   23 ++++++++++++++++++++++-
 9 files changed, 53 insertions(+), 12 deletions(-)

diff --git a/sapi/fpm/config.m4 b/sapi/fpm/config.m4
index c23485a..7687660 100644
--- a/sapi/fpm/config.m4
+++ b/sapi/fpm/config.m4
@@ -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 --git a/sapi/fpm/fpm/fpm.c b/sapi/fpm/fpm/fpm.c
index 2f42175..b866f37 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 c576876..65d0e0d 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 dfe6792..25e2cc4 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 f780f03..dc54133 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 70e917a..3faf308 100644
--- a/sapi/fpm/fpm/fpm_main.c
+++ b/sapi/fpm/fpm/fpm_main.c
@@ -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_pipe[1]) {
 			int writeval = 0;
diff --git a/sapi/fpm/init.d.php-fpm.in b/sapi/fpm/init.d.php-fpm.in
index dc66310..3edd64f 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 6c9c6d6..a4e7e74 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
-- 
1.7.8

From 2259a8f18b1f25c175c486f54849fcd9e61ecde1 Mon Sep 17 00:00:00 2001
From: Jerome Loyet <fat@php.net>
Date: Fri, 28 Sep 2012 00:47:56 +0200
Subject: [PATCH] - add missing php-fpm.service.in

---
 sapi/fpm/php-fpm.service.in |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)
 create mode 100644 sapi/fpm/php-fpm.service.in

diff --git a/sapi/fpm/php-fpm.service.in b/sapi/fpm/php-fpm.service.in
new file mode 100644
index 0000000..396a88d
--- /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
+
-- 
1.7.8