Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

stop a process before suspend, and start it after resume

Linux Kernel, Network, and Services configuration.
Post Reply
Message
Author
cedric!
Posts: 30
Joined: 2013-11-21 19:54

stop a process before suspend, and start it after resume

#1 Post by cedric! »

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: 30
Joined: 2013-11-21 19:54

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

#2 Post by cedric! »

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: 30
Joined: 2013-11-21 19:54

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

#3 Post by cedric! »

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: 30
Joined: 2013-11-21 19:54

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

#4 Post by cedric! »

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

User avatar
saulgoode
Posts: 1445
Joined: 2007-10-22 11:34
Been thanked: 4 times

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

#5 Post by saulgoode »

I'd recommend trying as a first step using bash instead of sh, as it will not exit the script on error by default.
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -- Brian Kernighan

cedric!
Posts: 30
Joined: 2013-11-21 19:54

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

#6 Post by cedric! »

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

Post Reply