Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#54194 closed defect (fixed)

nginx+launchd doesn't open port without -g

Reported by: essandess (Steve Smith) Owned by: Schamschula (Marius Schamschula)
Priority: Normal Milestone:
Component: ports Version:
Keywords: Cc: Schamschula (Marius Schamschula)
Port: nginx

Description

sudo port load nginx

doesn't open the port specified in the nginx.conf configuration because of an issue with launchd.

This issue is widely known, e.g., http://wiki.summercode.com/running_homebrewed_nginx_with_sudo_on_mac_os_x

The way to get nginx to work with launchd is to add the -g "daemon off;" option in the plist.

Here is a working launchd plist for nginx:

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd" >
<plist version='1.0'>
<dict>
<key>Label</key><string>org.macports.nginx</string>
<key>ProgramArguments</key>
<array>
	<string>/opt/local/bin/daemondo</string>
	<string>--label=nginx</string>
	<string>--start-cmd</string>
	<string>/opt/local/sbin/nginx</string>
	<string>-g</string>
	<string>&quot;daemon off;&quot;</string>
	<string>;</string>
	<string>--pid=fileauto</string>
	<string>--pidfile</string>
	<string>/opt/local/var/run/nginx/nginx.pid</string>
</array>
<key>Disabled</key><true/>
<key>KeepAlive</key><true/>
</dict>
</plist>

Change History (8)

comment:1 Changed 7 years ago by Schamschula (Marius Schamschula)

Owner: set to Schamschula
Resolution: fixed
Status: newclosed

In 40d449c9aa2a58731f37d8f17c4ba3ea76557b17/macports-ports:

nginx: fix LaunchDaemon plist

update lua variant to version 0.10.8
Closes: #54194

comment:2 Changed 7 years ago by essandess (Steve Smith)

Thanks!

BTW, I believe it may be necessary to close command line option settings with a semicolon: -g "daemon off;"

I'd sanity check with a command line test.

comment:3 in reply to:  2 Changed 7 years ago by Schamschula (Marius Schamschula)

Replying to essandess:

Thanks!

BTW, I believe it may be necessary to close command line option settings with a semicolon: -g "daemon off;"

I'd sanity check with a command line test.

I checked the plist before committing: The ; is inserted automatically.

comment:4 Changed 7 years ago by thetyrantcbass

After updating to nginx 1.13 the port no longer loads at all via launchd. Instead nginx just writes an error message every 30 seconds:

2017/05/20 06:05:18 [emerg] 213#0: unexpected end of parameter, expecting ";" in command line

And so on. The quotation or apostrophe marks are apparently required for the command to be properly executed:

sh-3.2# nginx -t -g daemon off;
nginx: invalid option: "off"
sh-3.2# nginx -t -g "daemon off;"
nginx: the configuration file /opt/local/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /opt/local/etc/nginx/nginx.conf test is successful

and the current launchd plist isn't invoking it properly.

Last edited 7 years ago by thetyrantcbass (previous) (diff)

comment:5 Changed 7 years ago by Schamschula (Marius Schamschula)

It seems that the ; location matters. Hopefully,

https://github.com/macports/macports-ports/commit/61e3e885a4e7dced32d714673cf177278ebf41fd

fixes this issue.

comment:6 Changed 7 years ago by essandess (Steve Smith)

A semicolon is needed in the nginx -g option setting.

The other semicolon is needed after the entire command for bash.

comment:7 Changed 7 years ago by essandess (Steve Smith)

I believe these launchd and daemon issues are why Macports introduced daemondo.

I am not sure if there are performance or scaling issues if nginx is run with -g "daemon off;".

Ideally, I believe there should be a Macports daemondo wrapper for Nginx, just like squid, polipo, and privoxy.

comment:8 Changed 7 years ago by thetyrantcbass

Starting fine for me now.

Note: See TracTickets for help on using tickets.