.../sleep.d script not fully running at resume state
Linux - GeneralThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
.../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:
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).
#!/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?
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:
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).
#!/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.
? 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.
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:
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.
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.
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.
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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.