I've developed and tested a different approach. More invasive and
probably not something upstream will like the look of!

The approach is to have ngx_daemon() not do the parent process exit()
after fork() but to return the child PID. The parent process detects
that (a value > 0), sets ngx_pid = child_pid, calls ngx_crate_pidfile(),
then does the exit().

I tested with extensive log messages to trace behaviour and confirmed it
works.

Jun 01 03:01:51 u1910 systemd[1]: Starting A high performance web server and a 
reverse proxy server...
Jun 01 03:01:51 u1910 nginx[27728]: nginx: Initialise child_pid=-3
Jun 01 03:01:51 u1910 nginx[27728]: nginx: ngx_daemon() in PID 27728 returned 
27729
Jun 01 03:01:51 u1910 nginx[27728]: nginx: Process PID 27728 calling 
ngx_create_pidfile() with ngx_pid=27729
Jun 01 03:01:51 u1910 nginx[27728]: nginx: Process PID 27728 exiting
Jun 01 03:01:51 u1910 nginx[27728]: nginx: ngx_daemon() in PID 27729 returned 0
Jun 01 03:01:51 u1910 nginx[27728]: nginx: This should be child process PID 
27729, parent PID 27728
Jun 01 03:01:51 u1910 systemd[1]: Started A high performance web server and a 
reverse proxy server.

** Patch added: "Bring PID creation into parent process v2"
   
https://bugs.launchpad.net/ubuntu/+source/nginx/+bug/1581864/+attachment/5268168/+files/nginx-fix-pidfile.7.patch

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/1581864

Title:
  nginx.service: Failed to read PID from file /run/nginx.pid: Invalid
  argument

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/nginx/+bug/1581864/+subscriptions

-- 
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to