# execute script onsuspend with hibernte-script

## BonesToo

I've been trying to get a script to run on suspend and on resume when using hibernate-ram.  But it seems to be running the script twice during suspend, and when it booms out the second time suspend cancels.  any idea what i'm doing wrong here?

common.conf

```
OnSuspend 20 /home/mythtv/bin/hibernate-suspend.sh
```

hibernate-suspend.sh

```
#!/bin/bash

killall unclutter

```

hibernate

```
 # hibernate-ram -v3

hibernate-ram: Using implicit configuration file /etc/hibernate/ram.conf

hibernate-ram: Trying method in ususpend-ram.conf...

hibernate-ram: Including configuration from common.conf

hibernate-ram: Trying method in sysfs-ram.conf...

hibernate-ram: Including configuration from common.conf

hibernate-ram: [01] Executing CheckLastResume ...

hibernate-ram: [01] Executing CheckRunlevel ...

hibernate-ram: [01] Executing LockFileGet ...

hibernate-ram: [01] Executing NewKernelFileCheck ...

hibernate-ram: [10] Executing EnsureSysfsPowerStateCapable ...

hibernate-ram: [20] Executing MiscLaunchAuxFunc1 ...

Executing /home/mythtv/bin/hibernate-suspend.sh...

hibernate-ram: [20] Executing MiscLaunchAuxFunc2 ...

Executing /home/mythtv/bin/hibernate-suspend.sh...

unclutter: no process found

hibernate-ram: Aborting suspend due to errors in MiscLaunchAuxFunc2 (use --force to override).

hibernate-ram: [01] Executing NoteLastResume ...

hibernate-ram: [01] Executing LockFilePut ...

```

This fails because it does kill the process during the first execution. Does my script have to return some value?

Even when I do "killall -q unclutter" it still doesn't work.  Displays the same output above sans "unclutter: no process found" line.

Thanks

----------

## Hu

 *BonesToo wrote:*   

> But it seems to be running the script twice during suspend, and when it booms out the second time suspend cancels.  any idea what i'm doing wrong here?
> 
> ```
>  # hibernate-ram -v3
> 
> ...

 You have arranged the included configuration files in such a way that common.conf is included twice, so your suspend hook is added twice.  You should disable the unnecessary include directives, so that your system uses either ususpend-ram or sysfs-ram, but not both.

----------

## BonesToo

interesting, i don't think i've touched any of the files from the default install.  thanks for the heads up, I'll check it out.

----------

## Hu

The default install tries all the methods, presumably to give the best chance of working correctly with no configuration.  The default common.conf contains only settings which can be repeatedly parsed without negative side effects, so the normal path of including it multiple times works.  When you changed common.conf to include your suspend hook, that was no longer the case.

----------

## BonesToo

word, yea you are right.  I haven't been in these files in a while, needed a refresher  :Wink:   So i got it running once, but now I have another issue.  Not sure if I'm even taking the correct approach.

When the pc comes out of standby the cursor is visible over top of mythfrontend.  I have unclutter running (before the suspend and likely its still running after the resume) but for some reason it doesn't want to hide the cursor straight out of resume.  I usually have to move the mouse or hit alt+tab on the keyboard to get unclutter to then hide then mouse again.

So I thought maybe if i killed unclutter before suspend, and then restarted unclutter after the resume it might pick up on the cursor and hide it.  Only problem is that it needs to run under X and as the correct mythtv user.  So i can't seem to get it to restart on resume now because the resume happens as root and I can't get unclutter to start under X with mythtv user.  I think that OnResume script might run before X is even back up, i'm not entirely sure.  I was trying to run something like "su mythtv -c unclutter" but doesn't seem to do anything. 

/var/log/hibernate.log

```
...

hibernate-ram: [59] Executing RemountXFSBootRW ...

hibernate-ram: [20] Executing MiscLaunchAuxFunc2 ...

Executing /home/mythtv/bin/hibernate-resume.sh...

hibernate-ram: [01] Executing NoteLastResume ...

hibernate-ram: [01] Executing LockFilePut ...

Resumed at Sat Jun 12 11:08:58 PDT 2010

```

Maybe I'm doing this the completely wrong way, it was just the first idea that came to me.

----------

## Hu

Killing unclutter may work, but seems like an excessive solution.  In general, suspend is supposed to be transparent to the applications on the machine, aside from the sudden time jump.  If you manually switch from X to console and back, without suspending, do you see the unwanted return of the cursor?  If so, then it appears to be a general bug in the interaction between X and unclutter.

Recall that /bin/su uses the shell of the specified user, if not directed otherwise.  If the mythtv user has a shell that does not handle the -c option in the normal way, running /bin/su mythtv -c command will likely not work correctly.  Since you are running su as root, you may be able to use the -s option to force /bin/su to use a specific shell, without actually changing the shell of the mythtv user.

X never goes down during suspend, so it does not need to come up during resume.  Rather, the suspend script switches to an alternate virtual terminal, as a workaround for video cards that fail to resume directly to graphics mode.  nVidia cards are especially bad about hanging the entire machine when you try this.  You can tell when in the sequence the X tty is made active by finding which script in the resume process calls chvt.  That is the command used to programmatically switch to and from the X tty.

----------

## BonesToo

 *Hu wrote:*   

> Killing unclutter may work, but seems like an excessive solution.  In general, suspend is supposed to be transparent to the applications on the machine, aside from the sudden time jump.  If you manually switch from X to console and back, without suspending, do you see the unwanted return of the cursor?  If so, then it appears to be a general bug in the interaction between X and unclutter.
> 
> 

 

You are correct, simply switching back to the console and then back to X makes the cursor reappear and stay visible until I move the mouse or do an alt+tab.

now what?

----------

## Hu

You could ask the unclutter maintainers if this is a bug or a feature.  Now that you have a simpler testcase, it should be easier to investigate if it is deemed a bug.

----------

