I have a Thinkpad T410 and was plagued by this issue for years. I was using Fedora 14 but noticed that certain applications would tend to cause this issue if I left them open when I attempted to have the laptop suspend via closing the lid. I would make sure to close these applications once I recognized the pattern.
I'll also note that since upgrading to Fedora 19 I've not had this issue come up a single time, so you might have some luck by simply migrating up to Ubuntu 13.10.
The main applications that would cause this?
- LibreOffice (any of the apps such as Writer, Calc, etc.)
- SSH connections to remote systems
- Virt-Manager
I've always just kept Chrome open and that never seemed to cause any issues.
This answer is based on askubuntu.com/a/661747/394818 (as also referred to in the comment by @sun-bear), askubuntu.com/q/616272/394818 and superuser.com/a/1269158/585953.
Using a system service:
Create the file /etc/systemd/system/my_user_script.service
:
[Unit]
Description=Run my_user_script
After=suspend.target hibernate.target hybrid-sleep.target suspend-then-hibernate.target
[Service]
ExecStart=/path/to/my_user_script
#User=my_user_name
#Environment=DISPLAY=:0
[Install]
WantedBy=suspend.target hibernate.target hybrid-sleep.target suspend-then-hibernate.target
Remove suspend/hibernate/hybrid in case the service should only be executed after waking up from a specific type of sleep. In case the service needs to be run by a specific user, uncomment the User=
and Environment=
lines and replace the relevant user name.
Install the service file with:
sudo systemctl enable my_user_script
Using a user service will not work:
In order to avoid setting a hard coded user name with User=
, one could create the exact same service file at ~/.config/systemd/user/my_user_script.service
and activate with
systemctl --user enable my_user_script
However, that will not work. @grawity explains in more detail at unix.stackexchange.com/a/174837/163108 why that is:
sleep.target
is specific to system services. The reason is, sleep.target
is not a magic target that automatically gets activated when going to sleep. It's just a regular target that puts the system to sleep – so the 'user' instances of course won't have an equivalent. (And unfortunately the 'user' instances currently have no way to depend on systemwide services.)
Best Answer
You could try the pm-utils package.
I don't know if this is installed by default on Ubuntu.
You can then write a hook script (at e.g.
/etc/pm/sleep.d/00_my_resume_hook
) such asI may have glossed over some essential details here.