Internet Sharing and SMB stop a mac going to sleep. If you want to find out what’s stopping your mac going to sleep, you can run
pmset -g assertions. Furthermore, the mac does not allow hibernation. I’m a bit over-energy-conscious, so here is my solution to having an energy-efficient home server.
Tell power management to hibernate instead of sleep (optional):
sudo pmset -a hibernatemode 25
Create a new file, like “gotosleep.sh”, and insert these commands:
launchctl unload -w /System/Library/LaunchDaemons/com.apple.InternetSharing.plist
launchctl unload /System/Library/LaunchDaemons/smbd.plist
launchctl load /System/Library/LaunchDaemons/smbd.plist
launchctl load -w /System/Library/LaunchDaemons/com.apple.InternetSharing.plist
launchctl unload /System/Library/LaunchDaemons/org.apache.httpd.plist
launchctl unload /System/Library/LaunchDaemons/com.apple.InternetSharing.plist
launchctl unload /System/Library/LaunchDaemons/com.apple.smbd.plist
launchctl load /System/Library/LaunchDaemons/com.apple.InternetSharing.plist
launchctl load /System/Library/LaunchDaemons/com.apple.smbd.plist
launchctl load -w /System/Library/LaunchDaemons/org.apache.httpd.plist
Then make the file executable:
chmod 700 gotosleep.sh
When you want the mac to sleep for the (e.g.) night, just enter:
at the command prompt. The mac will sleep a little while after the first three commands (during the pause), and upon manual restarting (power button) will continue with the last three. So sleep is possible due to disabling the services, and they start up again afterwards. If you are running other services, just google around for the appropriate shell command. I’m not too sure about smbd – it seemed to be necessary, but I always get a message that it’s already started.
If you use hibernation, you can even unplug/switch off the power…! I haven’t tried scheduled wake-up yet, but it might be a nice feature to have – manual switch off but always ready for service by breakfast.
UPDATE: We’ve been having some problems that although Internet Sharing appears to work after restarting, it actually has to be unloaded and loaded before working after waking up. For now I took out the “load” items in the script and start SMB and Internet Sharing manually, I’ll update later with a better solution.
2nd UPDATE: This wasn’t the only problem, but overall I think the edited version above is now working well.
- Find out what’s keeping your Mac awake: http://hints.macworld.com/article.php?story=20120701234338952
- Change hibernation mode settings on MacBooks: http://www.rawcomputing.co.uk/mactips119.html
- Sleep a Mac from the Command Line: http://osxdaily.com/2012/07/22/sleep-a-mac-from-the-command-line/
- How to disable Windows Sharing — for real: https://discussions.apple.com/thread/880022?start=0&tstart=0
- Start/stop internet sharing from a script?: http://apple.stackexchange.com/questions/2488/start-stop-internet-sharing-from-a-script