iMac with insomnia
I'm having problems with getting my late 2009 iMac (running 10.6.4) to sleep, which it is set to do after fifteen minutes of inactivity.
Sleep works fine when manually commanded - the screen, fans and disks shut down, and the lights on USB devices, such as my hub, switch off, but getting the computer to sleep automatically with the energy saver preferences is problematic.
When left idle, the screen saver activates and the display turns off on schedule. The system doesn't actually sleep, though. After about fifteen minutes (I haven't actually timed it), I can hear the fans stop and the disks spool down, but, but connected USB devices don't show any indication of sleep (for instance, the activity lights on my hub don't turn off). After a few seconds, the fans start again and the disks spool back up - though the screen doesn't come on as it would if the mouse was knocked or a USB device was plugged in or out. This then cycles endlessly.
My hypothesis is that some program is preventing or interrupting sleep by performing some action, but I'm stumped as to what it might be. The only application normally running when the program fails to sleep is Mail, and because of the disk access, I was suspicious of Dropbox, but quitting both of them doesn't help.
Does anyone have any suggestions on how to troubleshoot this? Are there any log files that would show if a particular program had woken or prevented sleep?
With 10.6 Console, you can try these some filters.
In the list on the left, select Database Searches > All Messages, and in the upper right, search for "sleep" (no quotes):
8/29/10 10:37:21 AM kernel System Sleep
8/29/10 12:28:20 PM kernel Previous Sleep Cause: 5
8/29/10 1:37:35 PM configd[13] PowerManagement configd: System Sleep prevented by active remote login session (1200 second threshold).
8/29/10 1:37:35 PM configd[13] PowerManagement configd: tty sleep preventer: /dev/ttys000
8/29/10 3:45:28 PM kernel System Sleep
8/29/10 4:34:07 PM kernel Previous Sleep Cause: 5
8/29/10 4:56:39 PM kernel System Sleep
It went to sleep at 10:37. It woke later at 12:28, and says that the reason it went to sleep before is "Cause 5", which is the only one I ever see. At 1:37, it tried to go to sleep, but didn't because a terminal ("tty") was open, and it stays active for 20 minutes ("1200 second threshold") with no activity. I must have done something intervening because it didn't go to sleep again until 3:45. I woke it again at 4:34, then slept at 4:56.
Under Database Searches > All Messages, "wake":
8/29/10 12:28:20 PM kernel Wake reason = EHC2
8/29/10 12:28:20 PM kernel System Wake
8/29/10 12:28:20 PM kernel USB (EHCI):Port 2 on bus 0x26 has remote wakeup from some device
8/29/10 12:28:20 PM kernel The USB device Apple Keyboard (Port 2 of Hub at 0x26200000) may have caused a wake by issuing a remote wakeup
8/29/10 12:28:51 PM [0x0-0xfd0fd].backupd-helper[2047] Not starting Time Machine backup after wake - failed to resolve alias to backup volume
8/29/10 4:34:07 PM kernel Wake reason = OHC2 EHC2
8/29/10 4:34:07 PM kernel System Wake
8/29/10 4:34:07 PM kernel An Unknown USB Device (Port 1 of Hub at 0x26000000), may have caused a wake by being connected
8/29/10 4:34:07 PM kernel The USB device BRCM2046 Hub (Port 1 of Hub at 0x6000000) may have caused a wake by being disconnected
Note that these wake times correlate with the "Previous Sleep Cause" messages above. The first one -- "EHC2", "(EHCI): Port 2" is the keyboard. I pressed a key to wake. The second one is more interesting. I know no one was around the computer at 4:34 -- an "unknown USB device" was connected, and "BRCM2046" was disconnected simultaneously (or in immediate succession). A quick search indicates that BRCM2046 is related to Bluetooth, and that makes sense, because I use a Bluetooth mouse, and sometimes when I wake by pressing a key on the keyboard, the mouse has disconnected, and I have to wiggle it a bit to reconnect. When I move the mouse to wake, the message is different. Here is an earlier sequence:
8/28/10 5:53:19 AM kernel Wake reason = OHC2
8/28/10 5:53:19 AM kernel System Wake
8/28/10 5:53:19 AM kernel The USB device BRCM2046 Hub (Port 1 of Hub at 0x6000000) may have caused a wake by issuing a remote wakeup
8/28/10 5:53:19 AM kernel The USB device Bluetooth USB Host Controller (Port 1 of Hub at 0x6100000) may have caused a wake by issuing a remote wakeup
So that second wake at 4:37 was spurious, because the mouse decided to give up the connection. If someone was present, they would have seen the Mac wake "by itself". It also went back to sleep a little over 20 minutes later, which is what it is set for. (That Time Machine message after wake is also very common, but it does automatically back up later.)
There are also Sleep and Wake messages under Diagnostic and Usage Information > Diagnostic and Usage Messages. But these seem to be just more detail on success.
I know that playing video with Flash within Safari will allow the display to go to sleep, but not the computer. (Sometimes Flash/Safari gets "stuck" even after closing the page with the Flash, and I have to quit Safari for the system to sleep.) Using an actual media program like DVD Player will of course keep the display on, and the system will not sleep at all. In neither case are there any diagnostic messages that these things have "prevented" sleep.
I have seen the behavior you describe, where the system nods off but then immediately awakens, on an older iMac. But then after it nods off again the second time, it stays asleep. Unfortunately, it's still running 10.4 and the logs and Console app aren't as helpful. It might be some kind of hardware interaction, in which the act of toggling some state is seen as a reason to awaken.
What happens if you simply turn the computer on and don't log in? Does it go to sleep? What about booting from the OS X DVD? I don't know if it is set to sleep in that case; and if not, whether you can open System Preferences and make that change and have it stick. (Workaround: a clean install to an external drive you can boot from, although that does introduce another variable.) If it never ever sleeps in even the most vanilla scenarios, then maybe it is a hardware issue.
Have you tried quitting all programs or just Mail and Dropbox ?
Many processes do indeed run in the background. You can take a look to see what is running at any time via the Activity Monitor, and to see the logs for the easiest way is to use the Console app.
Both Activity Monitor and Console are in Applications > Utilities
directory.
One other thing you might try is to unplug from the network (or turn your wireless network off). This might help quiet the activity on the machine down and help isolate what might be causing the issue.
The following Apple Support article can be used as a checklist to diagnose sleep problems:
Mac OS X: Why your Mac might not sleep or stay in sleep mode.
(Dead link - archived link from the WayBack Machine.)
I suggest verifying all the points mentioned in this article, and especially in the section "How can I determine what is causing a sleep issue and how can I resolve it?".