LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 03-22-2010, 01:47 PM   #1
Frank64
Member
 
Registered: Feb 2008
Distribution: Kubuntu 11.10 64-bits
Posts: 70

Rep: Reputation: 15
.../sleep.d script not fully running at resume state


Hi,

I am trying to write a script run at resume from suspend to RAM. I know a bit about scripting as I have other .sh, but that type of scripting I am having a hard time understand and my script does not do all I ask for.

My script is located in
Code:
/usr/lib/pm-utils/sleep.d
and is called
Code:
80fancontrol_cd
Owned and run by Root. It is Executable.

Basically it's to kill 'fancontrol' and 'cairo-dock' at resume state and restart them. Why I need to kill both? Different reasons, they have bugs I have logged and I try to find an automatic workaround in the meantime. Ask me for more details if you want.

My script had various versions. Here's the latest:

Code:
#!/bin/bash

case "$1" in
    hibernate|suspend)
        ;;
    thaw|resume)
        pkill cairo-dock
        pkill fancontrol
        sudo -u frank nohup cairo-dock -o > /dev/null 2>&1 &
        #nohup fancontrol > /dev/null 2>&1 &
        fancontrol
        #cairo-dock -o > /dev/null 2>&1 &
        ;;
        *)
        ;;
esac

exit $?
As you can see I also tried with the commented lines as uncommented.

The actual behavior is that both 'fancontrol' and 'cairo-dock' do get killed. But none are restarting. I can't find why and don't know where to troubleshoot.

Fancontrol needs to be run as root and cairo-dock as user (frank).

I read this to understand more http://sial.org/howto/shell/background/ Apparently I need to dissociate 'fancontrol' from the terminal, cuz it's a deamon.

So I tried the following script:

Code:
#!/bin/bash

case "$1" in
    hibernate|suspend)
        ;;
    thaw|resume)
        pkill cairo-dock
        pkill fancontrol
(
cd / || exit 1

sudo -H -u frank -- \
cairo-dock -o <&- \
>> 2>&1 &
)
        ;;
        *)
        ;;
esac

exit $?
It does not work either. I do not understand completely what they explain on that website and I don't know how to adapt it correctly to my script.

It's very easy to start cairo-dock from terminal (fancontrol as well). If I type myself as user the 'nohup' lines it will start fancontrol and get out of terminal and will start cairo-dock and get out of terminal.

So why it's not even starting when that script run? I can't figure out where I am messing up.

Can anyone help me understand my problem so I can find what's wrong?

tnx a lot!
 
Old 04-02-2010, 11:20 AM   #2
jbb@vcn.com
LQ Newbie
 
Registered: Jul 2008
Location: Buffalo, Wyoming
Posts: 9

Rep: Reputation: 0
Quote:
Originally Posted by Frank64 View Post
Hi,

I am trying to write a script run at resume from suspend to RAM. I know a bit about scripting as I have other .sh, but that type of scripting I am having a hard time understand and my script does not do all I ask for.

My script is located in
Code:
/usr/lib/pm-utils/sleep.d
and is called
Code:
80fancontrol_cd
Owned and run by Root. It is Executable.

Basically it's to kill 'fancontrol' and 'cairo-dock' at resume state and restart them. Why I need to kill both? Different reasons, they have bugs I have logged and I try to find an automatic workaround in the meantime. Ask me for more details if you want.

My script had various versions. Here's the latest:

Code:
#!/bin/bash

case "$1" in
    hibernate|suspend)
        ;;
    thaw|resume)
        pkill cairo-dock
        pkill fancontrol
        sudo -u frank nohup cairo-dock -o > /dev/null 2>&1 &
        #nohup fancontrol > /dev/null 2>&1 &
        fancontrol
        #cairo-dock -o > /dev/null 2>&1 &
        ;;
        *)
        ;;
esac

exit $?
As you can see I also tried with the commented lines as uncommented.

The actual behavior is that both 'fancontrol' and 'cairo-dock' do get killed. But none are restarting. I can't find why and don't know where to troubleshoot.

Fancontrol needs to be run as root and cairo-dock as user (frank).

I read this to understand more http://sial.org/howto/shell/background/ Apparently I need to dissociate 'fancontrol' from the terminal, cuz it's a deamon.

So I tried the following script:

Code:
#!/bin/bash

case "$1" in
    hibernate|suspend)
        ;;
    thaw|resume)
        pkill cairo-dock
        pkill fancontrol
(
cd / || exit 1

sudo -H -u frank -- \
cairo-dock -o <&- \
>> 2>&1 &
)
        ;;
        *)
        ;;
esac

exit $?
It does not work either. I do not understand completely what they explain on that website and I don't know how to adapt it correctly to my script.

It's very easy to start cairo-dock from terminal (fancontrol as well). If I type myself as user the 'nohup' lines it will start fancontrol and get out of terminal and will start cairo-dock and get out of terminal.

So why it's not even starting when that script run? I can't figure out where I am messing up.

Can anyone help me understand my problem so I can find what's wrong?

tnx a lot!
It's always dangerous in a network environment, but you might try SUID for 'fancontrol' and 'cairo-dock' to root and leave off all the frills in your script. You also might try semicolons after each command line. Exactly why your system is having problems with either command might be worth a look. It might also be your use of 'sudo' in the script.
 
Old 04-03-2010, 05:37 PM   #3
Frank64
Member
 
Registered: Feb 2008
Distribution: Kubuntu 11.10 64-bits
Posts: 70

Original Poster
Rep: Reputation: 15
Fortunately I am not in a network.

By SUID do you mean
Code:
chmod 4755
? I have googled around and 4755 seems to be used for SUID. If not, then I don't understand what SUID is.

After doing 'chmod 4755' to the file, I have tried with the semi-columns after the command, but that does not run the command, in fact I put the ; only after the 'cairo-dock' launch command and the 2 'pkill', which are before the 'cairo-dock', did not even run.

Code:
#!/bin/bash

. /usr/lib/pm-utils/functions

case "$1" in
    hibernate|suspend)
        ;;
    thaw|resume)
        pkill cairo-dock
        pkill fancontrol
        sleep 1
        #sudo -u frank nohup cairo-dock -o > /dev/null 2>&1 & ;
        #nohup fancontrol > /dev/null 2>&1 & ;
        #fancontrol
        #nohup cairo-dock -o > /dev/null 2>&1 &
        nohup cairo-dock -o > /dev/null 2>&1 & ;
        #cairo-dock -o > /dev/null 2>&1 &
        ;;
        *)
        ;;
esac

exit $?
So the above did not pkill and did not launch cairo-dock.

Then I tried without the ; but still with 'chmod 4755'. It runs just like before, which is killing both processes but not launching cairo-dock.

The above script does not even try to start 'fancontrol'. I only try to kill both processes and launch cairo-dock. Once I'll succeed with this, I'll look around for fancontrol. But maybe it should be the other way around, trying fancontrol (which is run under root) first and when it works, trying cairo-dock.

Now by removing the frills, do you mean I should only simplify the script like this:

Code:
#!/bin/bash
        pkill cairo-dock
        pkill fancontrol
        nohup fancontrol > /dev/null 2>&1 &
        nohup cairo-dock -o > /dev/null 2>&1 &    
exit
?

tnx
 
Old 04-04-2010, 12:29 AM   #4
jbb@vcn.com
LQ Newbie
 
Registered: Jul 2008
Location: Buffalo, Wyoming
Posts: 9

Rep: Reputation: 0
A further simplification might be:

#!/bin/sh
pkill cairo-dock ;
pkill fancontrol ;
nohup fancontrol > /dev/null 2>&1 & ;
nohup cairo-dock -o > /dev/null 2>&1 & ;
exit

The 'extra' spaces should not matter. The semicolons should.
But what do I know, I only dabble a little in shell scripts and try not to wander too far from the basics.
 
Old 04-05-2010, 10:00 AM   #5
Frank64
Member
 
Registered: Feb 2008
Distribution: Kubuntu 11.10 64-bits
Posts: 70

Original Poster
Rep: Reputation: 15
I can only do one test a day, cuz I suspend once per day, so testing takes a while. loll

It did act a little differently with your suggestion, I thought the ";" only after the commands that where not running.

So what it does now is it kills fancontrol and cairo-dock at suspend, probably cuz I don't specify to do it at resume, as the scripts in sleep.d folder are supposed to run at suspend and resume by default, otherwise specified within the script.

But at resume it does not run cairo-dock, neither fancontrol. And I have tried them independently from each other. One day I tried launching cairo-dock and the next fancontrol.

So now I will incorporate your script within the case of a resume only. Maybe it will work. And I will try launching cairo-dock with a 'sudo -u'.

Maybe it's just a matter of finding the right combination of arguments.
 
Old 04-06-2010, 12:19 PM   #6
jbb@vcn.com
LQ Newbie
 
Registered: Jul 2008
Location: Buffalo, Wyoming
Posts: 9

Rep: Reputation: 0
suspend - resume

First, do not clump all the commands under the single 'thaw | resume' thingy.
Second, the 'case/esac' set compares the conditions, ie. suspend OR resume, for commands to run.
Third, if you truly wish to tailor your script to your system you will look at the specific usages of 'case/esac' scripting in other scripts.

There are subtle, or dramatic, differences in tree naming, shell naming, and other 'proprietary' things among the various flavors of Linux/UNIX but it's almost always safe to use #!/bin/sh as the first line; that's all the 'porting' a flavor should need.

It seems to me that almost all the scripts under /etc/rc.d/init.d/ or /etc/init.d, whatever, are prime examples to study for proper usage of the 'case' language as practiced by your 'flavor' fanatics and how to write usage and end conditions for your flavor.

Being a 'fanatic' is NOT a career help.
 
Old 04-06-2010, 12:46 PM   #7
Frank64
Member
 
Registered: Feb 2008
Distribution: Kubuntu 11.10 64-bits
Posts: 70

Original Poster
Rep: Reputation: 15
Yes I see it's a bit more complex than I thought for that type of script, though the requirement behind it is quite easy to understand. Easy requirement != all the time easy scripting.

Then I will look at the other scripts in *.d and try to use the same basics, if I go with the case/esac structure.

What I don't understand is if I don't clump my commands under the 'thaw|resume' condition, the commands run both when suspending and resuming (which is what they are supposed to do if the case/esac isn't set). Not sure it matters if I can write the script with regards to this, though.

I need to read more stuff and perfect my scripting.
 
Old 04-07-2010, 08:54 AM   #8
jbb@vcn.com
LQ Newbie
 
Registered: Jul 2008
Location: Buffalo, Wyoming
Posts: 9

Rep: Reputation: 0
Quote:
Originally Posted by Frank64 View Post
Yes I see it's a bit more complex than I thought for that type of script, though the requirement behind it is quite easy to understand. Easy requirement != all the time easy scripting.

Then I will look at the other scripts in *.d and try to use the same basics, if I go with the case/esac structure.

What I don't understand is if I don't clump my commands under the 'thaw|resume' condition, the commands run both when suspending and resuming (which is what they are supposed to do if the case/esac isn't set). Not sure it matters if I can write the script with regards to this, though.

I need to read more stuff and perfect my scripting.
case "$1" in
hibernate|suspend)
;;
thaw|resume)

The above statement from your original script completely ignores the hibernate OR suspend condition as a cause for action.
It glides right past those conditions
and goes to the thaw OR resume condition.

Your only actions will be taken when the thaw OR resume condition occurs.
In plain English, what your original scripts says:
"In the case of hibernate OR suspend) do nothing;
In the case of thaw OR resume) perform all the sleep functions AND all the
wake-up functions;"

A better approach will clump all the sleep functions under the condition of
the sleep synonyms; hibernate OR suspend, and
clump all the wake-up functions under the wake-up synonyms; thaw OR resume.

I leave the particular writing as an exercise for your elucidation; I certainly
do not know what your needs really are and I ain't writing your script for you.

Last edited by jbb@vcn.com; 04-07-2010 at 08:57 AM.
 
Old 04-07-2010, 09:03 AM   #9
Frank64
Member
 
Registered: Feb 2008
Distribution: Kubuntu 11.10 64-bits
Posts: 70

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by jbb@vcn.com View Post
In plain English, what your original scripts says:
"In the case of hibernate OR suspend) do nothing;
In the case of thaw OR resume) perform all the sleep functions AND all the
wake-up functions;"
That is correct. That is what I want to do. When I suspend, do nothing and when I resume, 'kill' cairo-dock and fancontrol and launch cairo-dock and fancontrol. I do not need to kill them when I suspend, but maybe I could try to do so and simply launch them when I resume. That may be the issue.

I have different setups to try, based on the existing files in that folder for my distro. I guess one of them will help me figure out the right one for my script.

tnx
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Atheros wireless not detecting networks on resume from sleep taro_curly Linux - Wireless Networking 1 11-11-2009 09:05 PM
Scripts to run after resume from sleep brixtoncalling Slackware 2 09-06-2009 03:27 PM
*Sleep/Hibernate - freezes upon resume ---fix? Christastrophe Ubuntu 15 03-17-2009 05:11 AM
Change job state from SLEEP to RUN sun_sun Programming 1 11-24-2007 11:23 PM
how to wake up from S3 acpi sleep state? bluesmanu Linux - Laptop and Netbook 4 01-15-2006 03:22 PM


All times are GMT -5. The time now is 02:05 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration