Skip to content

Commit 851a04b

Browse files
author
Jerome Loyet
committed
- Fixed bug #63085 (Systemd integration and daemonize)
1 parent 75c63c5 commit 851a04b

File tree

9 files changed

+53
-12
lines changed

9 files changed

+53
-12
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ PHP NEWS
1818
- FPM:
1919
. Fixed bug #62954 (startup problems fpm / php-fpm). (fat)
2020
. Fixed bug #62886 (PHP-FPM may segfault/hang on startup). (fat)
21+
. Fixed bug #63085 (Systemd integration and daemonize). (remi, fat)
2122

2223
- Intl:
2324
. Fix bug #62915 (defective cloning in several intl classes). (Gustavo)

sapi/fpm/config.m4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ if test "$PHP_FPM" != "no"; then
583583
AC_DEFINE_UNQUOTED(PHP_FPM_USER, "$php_fpm_user", [fpm user name])
584584
AC_DEFINE_UNQUOTED(PHP_FPM_GROUP, "$php_fpm_group", [fpm group name])
585585

586-
PHP_OUTPUT(sapi/fpm/php-fpm.conf sapi/fpm/init.d.php-fpm sapi/fpm/php-fpm.8 sapi/fpm/status.html)
586+
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)
587587
PHP_ADD_MAKEFILE_FRAGMENT([$abs_srcdir/sapi/fpm/Makefile.frag], [$abs_srcdir/sapi/fpm], [sapi/fpm])
588588

589589
SAPI_FPM_PATH=sapi/fpm/php-fpm

sapi/fpm/fpm/fpm.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ struct fpm_globals_s fpm_globals = {
4242
.send_config_pipe = {0, 0},
4343
};
4444

45-
int fpm_init(int argc, char **argv, char *config, char *prefix, char *pid, int test_conf, int run_as_root) /* {{{ */
45+
int fpm_init(int argc, char **argv, char *config, char *prefix, char *pid, int test_conf, int run_as_root, int force_daemon) /* {{{ */
4646
{
4747
fpm_globals.argc = argc;
4848
fpm_globals.argv = argv;
@@ -55,7 +55,7 @@ int fpm_init(int argc, char **argv, char *config, char *prefix, char *pid, int t
5555

5656
if (0 > fpm_php_init_main() ||
5757
0 > fpm_stdio_init_main() ||
58-
0 > fpm_conf_init_main(test_conf) ||
58+
0 > fpm_conf_init_main(test_conf, force_daemon) ||
5959
0 > fpm_unix_init_main() ||
6060
0 > fpm_scoreboard_init_main() ||
6161
0 > fpm_pctl_init_main() ||

sapi/fpm/fpm/fpm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838

3939
int fpm_run(int *max_requests);
40-
int fpm_init(int argc, char **argv, char *config, char *prefix, char *pid, int test_conf, int run_as_root);
40+
int fpm_init(int argc, char **argv, char *config, char *prefix, char *pid, int test_conf, int run_as_root, int force_daemon);
4141

4242
struct fpm_globals_s {
4343
pid_t parent_pid;

sapi/fpm/fpm/fpm_conf.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,14 +1115,19 @@ int fpm_conf_write_pid() /* {{{ */
11151115
}
11161116
/* }}} */
11171117

1118-
static int fpm_conf_post_process(TSRMLS_D) /* {{{ */
1118+
static int fpm_conf_post_process(int force_daemon TSRMLS_DC) /* {{{ */
11191119
{
11201120
struct fpm_worker_pool_s *wp;
11211121

11221122
if (fpm_global_config.pid_file) {
11231123
fpm_evaluate_full_path(&fpm_global_config.pid_file, NULL, PHP_LOCALSTATEDIR, 0);
11241124
}
11251125

1126+
if (force_daemon >= 0) {
1127+
/* forced from command line options */
1128+
fpm_global_config.daemonize = force_daemon;
1129+
}
1130+
11261131
fpm_globals.log_level = fpm_global_config.log_level;
11271132

11281133
if (fpm_global_config.process_max < 0) {
@@ -1584,7 +1589,7 @@ static void fpm_conf_dump() /* {{{ */
15841589
}
15851590
/* }}} */
15861591

1587-
int fpm_conf_init_main(int test_conf) /* {{{ */
1592+
int fpm_conf_init_main(int test_conf, int force_daemon) /* {{{ */
15881593
{
15891594
int ret;
15901595
TSRMLS_FETCH();
@@ -1630,7 +1635,7 @@ int fpm_conf_init_main(int test_conf) /* {{{ */
16301635
return -1;
16311636
}
16321637

1633-
if (0 > fpm_conf_post_process(TSRMLS_C)) {
1638+
if (0 > fpm_conf_post_process(force_daemon TSRMLS_CC)) {
16341639
zlog(ZLOG_ERROR, "failed to post process the configuration");
16351640
return -1;
16361641
}

sapi/fpm/fpm/fpm_conf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ enum {
9797
PM_STYLE_ONDEMAND = 3
9898
};
9999

100-
int fpm_conf_init_main(int test_conf);
100+
int fpm_conf_init_main(int test_conf, int force_daemon);
101101
int fpm_worker_pool_config_free(struct fpm_worker_pool_config_s *wpc);
102102
int fpm_conf_write_pid();
103103
int fpm_conf_unlink_pid();

sapi/fpm/fpm/fpm_main.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ static const opt_struct OPTIONS[] = {
155155
{'p', 1, "prefix"},
156156
{'g', 1, "pid"},
157157
{'R', 0, "allow-to-run-as-root"},
158+
{'D', 0, "daemonize"},
159+
{'F', 0, "nodaemonize"},
158160
{'-', 0, NULL} /* end of args */
159161
};
160162

@@ -921,7 +923,7 @@ static void php_cgi_usage(char *argv0)
921923
prog = "php";
922924
}
923925

924-
php_printf( "Usage: %s [-n] [-e] [-h] [-i] [-m] [-v] [-t] [-p <prefix>] [-g <pid>] [-c <file>] [-d foo[=bar]] [-y <file>]\n"
926+
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"
925927
" -c <path>|<file> Look for php.ini file in this directory\n"
926928
" -n No php.ini file will be used\n"
927929
" -d foo[=bar] Define INI entry foo with value 'bar'\n"
@@ -937,6 +939,9 @@ static void php_cgi_usage(char *argv0)
937939
" -y, --fpm-config <file>\n"
938940
" Specify alternative path to FastCGI process manager config file.\n"
939941
" -t, --test Test FPM configuration and exit\n"
942+
" -D, --daemonize force to run in background, and ignore daemonize option from config file\n"
943+
" -F, --nodaemonize\n"
944+
" force to stay in foreground, and ignore daemonize option from config file\n"
940945
" -R, --allow-to-run-as-root\n"
941946
" Allow pool to run as root (disabled by default)\n",
942947

@@ -1560,6 +1565,7 @@ int main(int argc, char *argv[])
15601565
char *fpm_prefix = NULL;
15611566
char *fpm_pid = NULL;
15621567
int test_conf = 0;
1568+
int force_daemon = -1;
15631569
int php_information = 0;
15641570
int php_allow_to_run_as_root = 0;
15651571

@@ -1679,6 +1685,14 @@ int main(int argc, char *argv[])
16791685
php_allow_to_run_as_root = 1;
16801686
break;
16811687

1688+
case 'D': /* daemonize */
1689+
force_daemon = 1;
1690+
break;
1691+
1692+
case 'F': /* nodaemonize */
1693+
force_daemon = 0;
1694+
break;
1695+
16821696
default:
16831697
case 'h':
16841698
case '?':
@@ -1802,7 +1816,7 @@ consult the installation file that came with this distribution, or visit \n\
18021816
}
18031817
}
18041818

1805-
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)) {
1819+
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)) {
18061820

18071821
if (fpm_globals.send_config_pipe[1]) {
18081822
int writeval = 0;

sapi/fpm/init.d.php-fpm.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ case "$1" in
5454
start)
5555
echo -n "Starting php-fpm "
5656

57-
$php_fpm_BIN $php_opts
57+
$php_fpm_BIN --daemonize $php_opts
5858

5959
if [ "$?" != 0 ] ; then
6060
echo " failed"

sapi/fpm/php-fpm.8.in

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,20 @@ Test FPM configuration file and exit
9999
If called twice (-tt), the configuration is dumped before exiting.
100100
.TP
101101
.PD 0
102+
.B \-\-daemonize
103+
.TP
104+
.PD 1
105+
.B \-D
106+
Force to run in background and ignore daemonize option from configuration file.
107+
.TP
108+
.PD 0
109+
.B \-\-nodaemonize
110+
.TP
111+
.PD 1
112+
.B \-F
113+
Force to stay in foreground and ignore daemonize option from configuration file.
114+
.TP
115+
.PD 0
102116
.B \-\-zend\-extension \fIfile\fP
103117
.TP
104118
.PD 1
@@ -113,13 +127,20 @@ The configuration file for the php-fpm daemon.
113127
.B php.ini
114128
The standard php configuration file.
115129
.SH EXAMPLES
116-
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.
130+
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.
117131
.P
118132
.PD 1
119133
.RS
120134
sudo /etc/init.d/php-fpm start
121135
.RE
122136
.TP
137+
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.
138+
.P
139+
.PD 1
140+
.RS
141+
sudo systemctl start php-fpm.service
142+
.RE
143+
.TP
123144
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:
124145
.P
125146
.PD 0

0 commit comments

Comments
 (0)