Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I've run into an annoyance on Lubuntu 11.10, described here:

http://ubuntuforums.org/showthread.php?t=1869357

I came up with a workaround, described here:

http://ubuntuforums.org/showpost.php?p=11714061&postcount=30

My workaround involves putting a script in /etc/pm/sleep.d to run on resume.

However, the workaround only seems to work when I suspend using pm-suspend. When I suspend by closing my laptop's lid, my workaround fails. How can I get a script to run when I resume from sleep, and that sleep was triggered by closing the lid?

Details:

I suspect this failure might be because scripts in /etc/pm/sleep.d are not getting executed when I suspend by closing the lid. Suspending with pm-suspend, then resuming by closing/opening the lid works fine. I believe Lubuntu uses xfce4-power-manager to handle suspension due to lid closing, perhaps this is important? I prefer to suspend by closing my laptop's lid, rather than typing a terminal command.

EDIT:

By inspecting /var/log/pm-suspend.log as suggested by andrewsomething, we can see that the reset_panel script runs on every resume, it just fails on resumes that follow lid-triggered suspends. I followed his further suggestion that I add an export statement to my script, and things are working now. The script triggers too early in the wakeup process, but that's not hard to fix. The current version of the script:

#!/bin/bash
case "$1" in
   suspend|hibernate)
      #do nothing
   ;;
   resume|thaw)
      export DISPLAY=:0 #What does this do? Are there side effects?
      sleep 5 && lxpanelctl restart & #Delayed so the battery icon can finish wrecking shop.
   ;;
   *)
      exit 1
   ;;
esac
exit 0

andrewsomething, if you want to post an answer, I'll accept. Thanks for the help!

share|improve this question
1  
Anything interesting in /var/log/pm-suspend.log or /var/log/pm-suspend.log.1 ? –  andrewsomething Feb 25 '12 at 1:28
    
Interesting: /etc/pm/sleep.d/restore_brightness resume suspend: success. Running hook /etc/pm/sleep.d/reset_panel resume suspend: Cant connect to display: (null) –  Andrew Feb 25 '12 at 2:40
    
I don't get the same error if I suspend by running sudo pm-suspend from the terminal. You think the sudo or the terminal make important differences? –  Andrew Feb 25 '12 at 2:46
1  
I'd try adding export DISPLAY=:0 to your script. –  andrewsomething Feb 25 '12 at 3:31
    
Awesome, that seems to work. Care to explain what that does? Also, you should post an answer so I can accept it, you've solved my problem. –  Andrew Feb 25 '12 at 4:34

1 Answer 1

up vote 2 down vote accepted

The fact that the log contained /etc/pm/sleep.d/reset_panel resume suspend: Cant connect to display: indicates that no display is set, and you are trying to run a graphical program. When you're running pm-suspend from your session, the correct display was set probably by LightDM or whatever your display manager is. When it gets run automatically on resume, I assume it's getting run as the root user and not attached to a display. So you need to set the display variable yourself, like so:

#!/bin/bash
case "$1" in
   suspend|hibernate)
      #do nothing
   ;;
   resume|thaw)
      export DISPLAY=:0
      sleep 5 && lxpanelctl restart & #Delayed so the battery icon can finish wrecking shop.
   ;;
   *)
      exit 1
   ;;
esac
exit 0

The only draw back is that this won't work if you display isn't actually :0 That's the default, but it could change particularly in a multi-user setting.

share|improve this answer
    
Thanks! Nice work. –  Andrew Feb 25 '12 at 13:40

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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