summaryrefslogtreecommitdiffstats
path: root/meta-webserver/recipes-httpd/nginx
diff options
context:
space:
mode:
authorChangqing Li <changqing.li@windriver.com>2020-02-25 15:56:16 +0800
committerKhem Raj <raj.khem@gmail.com>2020-02-26 07:17:58 -0800
commitfc8f28c61122950d25ebacffecbb582ac038c725 (patch)
treeb9649b2965ebf9ceca099008c4d1444879e2797f /meta-webserver/recipes-httpd/nginx
parenta38a73eacd5d8c2c2d53fe94c2de696b3c11917a (diff)
downloadmeta-openembedded-fc8f28c61122950d25ebacffecbb582ac038c725.tar.gz
nginx: fix error during service startup
fix below error: nginx.service: failed to parse pid from file /run/nginx/nginx.pid: invalid argument Signed-off-by: Changqing Li <changqing.li@windriver.com> Signed-off-by: Khem Raj <raj.khem@gmail.com>
Diffstat (limited to 'meta-webserver/recipes-httpd/nginx')
-rw-r--r--meta-webserver/recipes-httpd/nginx/files/nginx-fix-pidfile.patch99
-rw-r--r--meta-webserver/recipes-httpd/nginx/nginx.inc1
2 files changed, 100 insertions, 0 deletions
diff --git a/meta-webserver/recipes-httpd/nginx/files/nginx-fix-pidfile.patch b/meta-webserver/recipes-httpd/nginx/files/nginx-fix-pidfile.patch
new file mode 100644
index 000000000..90159a667
--- /dev/null
+++ b/meta-webserver/recipes-httpd/nginx/files/nginx-fix-pidfile.patch
@@ -0,0 +1,99 @@
1Description: Fix NGINX pidfile handling
2Author: Tj <ubuntu@iam.tj>
3Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/nginx/+bug/1581864
4Last-Update: 2019-06-04
5---
6This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
7
8Upstream-Status: Pending
9
10This patch is from ubuntu, https://github.com/aroth-arsoft/pkg-nginx/blob
11/master/debian/patches/nginx-fix-pidfile.patch, for fix below
12error info:
13nginx.service: failed to parse pid from file /run/nginx/nginx.pid:
14invalid argument
15
16Signed-off-by: Changqing Li <changqing.li@windriver.com>
17
18diff --git a/src/core/nginx.c b/src/core/nginx.c
19index 9fcb0eb2..083eba1d 100644
20--- a/src/core/nginx.c
21+++ b/src/core/nginx.c
22@@ -338,14 +338,21 @@ main(int argc, char *const *argv)
23 ngx_process = NGX_PROCESS_MASTER;
24 }
25
26+ /* tell-tale to detect if this is parent or child process */
27+ ngx_int_t child_pid = NGX_BUSY;
28+
29 #if !(NGX_WIN32)
30
31 if (ngx_init_signals(cycle->log) != NGX_OK) {
32 return 1;
33 }
34
35+ /* tell-tale that this code has been executed */
36+ child_pid--;
37+
38 if (!ngx_inherited && ccf->daemon) {
39- if (ngx_daemon(cycle->log) != NGX_OK) {
40+ child_pid = ngx_daemon(cycle->log);
41+ if (child_pid == NGX_ERROR) {
42 return 1;
43 }
44
45@@ -358,8 +365,19 @@ main(int argc, char *const *argv)
46
47 #endif
48
49- if (ngx_create_pidfile(&ccf->pid, cycle->log) != NGX_OK) {
50- return 1;
51+ /* If ngx_daemon() returned the child's PID in the parent process
52+ * after the fork() set ngx_pid to the child_pid, which gets
53+ * written to the PID file, then exit.
54+ * For NGX_WIN32 always write the PID file
55+ * For others, only write it from the parent process */
56+ if (child_pid < NGX_OK || child_pid > NGX_OK) {
57+ ngx_pid = child_pid > NGX_OK ? child_pid : ngx_pid;
58+ if (ngx_create_pidfile(&ccf->pid, cycle->log) != NGX_OK) {
59+ return 1;
60+ }
61+ }
62+ if (child_pid > NGX_OK) {
63+ exit(0);
64 }
65
66 if (ngx_log_redirect_stderr(cycle) != NGX_OK) {
67diff --git a/src/os/unix/ngx_daemon.c b/src/os/unix/ngx_daemon.c
68index 385c49b6..3719854c 100644
69--- a/src/os/unix/ngx_daemon.c
70+++ b/src/os/unix/ngx_daemon.c
71@@ -7,14 +7,17 @@
72
73 #include <ngx_config.h>
74 #include <ngx_core.h>
75+#include <unistd.h>
76
77
78 ngx_int_t
79 ngx_daemon(ngx_log_t *log)
80 {
81 int fd;
82+ /* retain the return value for passing back to caller */
83+ pid_t pid_child = fork();
84
85- switch (fork()) {
86+ switch (pid_child) {
87 case -1:
88 ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, "fork() failed");
89 return NGX_ERROR;
90@@ -23,7 +26,8 @@ ngx_daemon(ngx_log_t *log)
91 break;
92
93 default:
94- exit(0);
95+ /* let caller do the exit() */
96+ return pid_child;
97 }
98
99 ngx_parent = ngx_pid;
diff --git a/meta-webserver/recipes-httpd/nginx/nginx.inc b/meta-webserver/recipes-httpd/nginx/nginx.inc
index 0d229ff40..2824c6652 100644
--- a/meta-webserver/recipes-httpd/nginx/nginx.inc
+++ b/meta-webserver/recipes-httpd/nginx/nginx.inc
@@ -21,6 +21,7 @@ SRC_URI = " \
21 file://nginx.init \ 21 file://nginx.init \
22 file://nginx-volatile.conf \ 22 file://nginx-volatile.conf \
23 file://nginx.service \ 23 file://nginx.service \
24 file://nginx-fix-pidfile.patch \
24" 25"
25 26
26inherit siteinfo update-rc.d useradd systemd 27inherit siteinfo update-rc.d useradd systemd