Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Mac OS X Mountain Lion does not have a Web Sharing box in the Sharing system prefs menu. It is thoroughly discussed on the web that the Apache server is available, and that it can be turned on manually in the command line, or by using a convenient Prefs Pane. That works while the computer is awake. But, when my computer goes to sleep, the server stops working, even though Wake for Network Access is checked in the Energy Saver Pref Pane. From the discussion on Bonjour, I see that this problem probably results from the fact that Apache isn't registered with Bonjour. Does that sound likely? If not, please make some suggestions. The connection is via hard-wired ethernet.

If registration with Bonjour is the problem, I'd like to know how to register it. You gave a nice description of dns-sd, and the command description says dns-sd -R Name Type Domain Port [TXT...] (Register a service)", but I don't know what to use for "Name" or "Type", or the format of the domain. I tried some dns-sd -B searches and found nothing I could use as a model, and it doesn't show up in Bonjour Browser.

Any suggestions would be appreciated.

share|improve this question

closed as off topic by Zoredache, SvW, Michael Hampton, Scott Pack, HopelessN00b Sep 24 '12 at 11:28

Questions on Server Fault are expected to relate to professional server, networking, or related infrastructure administration within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

    
Wake on lan for an HTTP service is almost always too slow. Systems take 15-45 seconds to wake up if you are really lucky. Incoming connections will almost certainly timeout before the system will be ready to respond. Servers usually just need to stay online and never go to sleep. –  Zoredache Sep 11 '12 at 20:59

1 Answer 1

The correct solution to this problem (as @Zoredache pointed out) is to set the server to never sleep. There may be a way to kluge it to wake on demand, but it'll be slow, overcomplicated, and potentially unreliable.

Now about "Wake for Network Access": it doesn't wake for just any old network access, it wakes when it receives a specially-formatted "magic packet" telling it to wake up. Incoming HTTP requests are not in this format, so they won't do the job. (Note: actually, it's the TCP SYN packet that initiates the HTTP session that would have to be in this format... except that even that wouldn't work because your computer doesn't respond to ARP in its sleep, so the router wouldn't know how to send it the SYN...)

A Bonjour Sleep Proxy provides a possible workaround for this (although as I said above, it'll be slow etc). If you have a device on your local network that provides the sleep proxy service, the Mac can register its Bonjour-advertized services with the proxy as it goes to sleep. While it's asleep, the proxy advertises your services over Bonjour, and responds to ARPs on your computer's behalf. When a request (well, the SYN packet actually) comes in for one of your services, the proxy sends a magic packet to wake your computer, then hands off the incoming connection to your computer.

I haven't tested this, but my understanding is that to get this to work you'd need a device that provides the Bonjour sleep proxy service (although apparently some Macs have it built into the ethernet interface), then register a service on port 80 with Bonjour:

dns-sd -R "some arbitrary name" _http._tcp local 80 &

Note that the "&" runs this in the background; the dns-sd program must be left running to keep the registration alive. Another possibility would be to edit the launchd .plist file for apache to have that create the Bonjour registration. But I'm not going to worry about it because it's not the right solution anyway; the right solution is not letting the server sleep in the first place.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.