stop a process before suspend, and start it after resume

Kernels & Hardware, configuring network, installing services

stop a process before suspend, and start it after resume

Postby cedric! » 2013-12-06 10:16

Hi all,

I'm building a VDR server. This server uses a DVB-T USB receiver. This all works, until I do the following. When I watch live TV, and then suspend, my machine never shuts down. It also doesn't resume anymore.
The problem is that the driver for the USB receiver does not like to suspend while in use.

To work around this, I would like to stop VDR, wait until it is stopped, unload the driver of the receiver, perform the suspend. (The power will then be removed from the USB receiver, so it's reset) On resume, first load the driver, wait until the receiver is fully initialized, and then start VDR again.

I have read the following article on the wiki. It tells me howto monitor the process, and that the configuration files are here:
/var/log/pm-suspend.log
/usr/lib/pm-utils/pm-functions
https://wiki.debian.org/Suspend

Does anybody has an example of howto do this?

Best regards,
Cedric
cedric!
 
Posts: 26
Joined: 2013-11-21 19:54

Re: stop a process before suspend, and start it after resume

Postby cedric! » 2013-12-06 10:26

Me again,

I have figured out the steps I have to do manually:
{{{
# invoke-rc.d vdr stop
# rmmod dvb_usb_dib0700
# pm-suspend
<<< Press power button >>>
# modprobe dvb_usb_dib0700
# invoke-rc.d vdr start
$ vdr-sxfe
}}}

Now let's see if I can do these automatically:-)

Regards,
Cedric
cedric!
 
Posts: 26
Joined: 2013-11-21 19:54

Re: stop a process before suspend, and start it after resume

Postby cedric! » 2013-12-06 11:17

Me again,

Progress. I have added the following new file. On suspend it adds a date line to a file.
Code: Select all
#!/bin/sh
# Shutdown VDR and unload driver to not crash during suspend


. "${PM_FUNCTIONS}"

case "$1" in
        hibernate|suspend)
                echo "Hi, today is $(date)" >> ~/date.txt
                ;;
esac

This added a date line each time on suspend:
# tail -f ~/data.txt
Hi, today is Fri Dec 6 12:12:53 CET 2013


Best regards,
Cedric
cedric!
 
Posts: 26
Joined: 2013-11-21 19:54

Re: stop a process before suspend, and start it after resume

Postby cedric! » 2013-12-06 12:10

It's me again.

I have now the following script. When the USB receiver is not present, the machine does come back from suspent, but the filesystem is not mounted. Maybe this is because the modprobe or the rmmod throws an error:
# cat /usr/lib/pm-utils/sleep.d/00vdr-and-modules
Code: Select all
#!/bin/sh
# Shutdown VDR and unload driver to not crash during suspend


. "${PM_FUNCTIONS}"

echo "We are now doing $1" >> ~/date.txt

case "$1" in
        hibernate|suspend)
      echo "$(date) About to stop VDR" >> ~/date.txt
      invoke-rc.d vdr stop
      echo "$(date) About to unload module" >> ~/date.txt
      rmmod dvb_usb_dib0700
      echo "$(date) About to write resume time" >> ~/date.txt
      ;;
   resume)
      echo "Seen resume" >> ~/date.txt
      echo "$(date) About to load module" >> ~/date.txt
      modprobe dvb_usb_dib0700
      echo "$(date) About to start VDR" >> ~/date.txt
      invoke-rc.d vdr restart
      echo "$(date) Done" >> ~/date.txt
      ;;
esac


I've got to investigate if this is the problem. Does anybody know howto mask the error?

Regards,
Cedric
cedric!
 
Posts: 26
Joined: 2013-11-21 19:54

Re: stop a process before suspend, and start it after resume

Postby saulgoode » 2013-12-06 12:27

I'd recommend trying as a first step using bash instead of sh, as it will not exit the script on error by default.
If I have not seen as far as others, it is because giants were standing on my shoulders.
User avatar
saulgoode
 
Posts: 1458
Joined: 2007-10-22 11:34

Re: stop a process before suspend, and start it after resume

Postby cedric! » 2013-12-06 15:55

Thanks, using bash was indeed the solution.

Now the only thing to figure out is to let VDR initiate the suspend, and write the wake-up time to the rtc.

Best regards,
Cedric
cedric!
 
Posts: 26
Joined: 2013-11-21 19:54


Return to System configuration

Who is online

Users browsing this forum: No registered users and 14 guests

fashionable