I’m striking out finding anything on this one but hopefully one of you gurus can point me at a solution. Here’s my setup…
Small home network consisting of a media server(headless, no monitor/keyboard/mouse)running OpenSuse 11.0, and 3 Windows clients running Vista. I don’t need the server running 24/7 so I have it set to Suspend to Ram after 60 minutes, which works great. I have a WOL program on each client which works perfectly to wake up the server.
However, there are times when the server “sleeps” while I’m still using it. I can be downloading to the server, playing music, or whatever-doesn’t really matter-and when the 60 minutes is up, it sleeps. What I need is some solution that will keep the server awake if I’m actually using it but let it sleep after the specified period of inactivity. My first thought was using Ethtool to wake it network activity directed at the server, but I’ve tried all the ethtool options and can’t make it work right. Either it wakes on any network activity whatsoever, (which means it never sleeps) or doesn’t wake at all.
Sorry, this is getting much longer than I planned. Does anyone know of a simple program or method of having the server stay awake while I’m using it remotely, but still sleep when it’s idle?
I think you first have to find out some things for your self, like: what is inactivity in your case. And then not in the sense of “when a client is not asking something”, but in real things like: what processes run / do not run when a client is served / not served. In short, the thing you can test on in a script.
BTW, you do not explain what you mean with “I have it set to Suspend to Ram after 60 minutes”. Any problems teling us how/where? Thus we could get some idea of what you are doing. To me it looks as if you suspend the system after 60 minutes of running, irrespective of what it is doing, but I could understand you wrong.
Thanks for your reply. You’ll have to excuse me as I am a relative novice with Linux - I’ve learned just enough to set up this file server and configure it to do what I need or want it to do. Typically, that means I decide I want to make some configuration change on the server and spend the next couple of weeks trying to get it to work through research and trial and error. If I have to write scripts to monitor what processes are running, I’m way out of my league.
When I realized I didn’t want the server running 24/7 it took a couple of weeks to find a solution that would allow it to sleep when not being used. I use KPowersave for this, with the “Autosuspend” option enabled, configured to “Suspend to Ram” after 60 minutes of inactivity.
Also relevant but left out of my initial post, I use TightVNC from one of the Windows clients to access the server remotely. The problem comes in because apparently KPowersave does not recognize anything initiated via TightVNC as activity. If the keyboard/mouse were physically connected to the file server things would work perfectly, but since all the input to the server is via TightVNC, Kpowersave doesn’t see any input, and suspends the system every 60 minutes.
I do not know to much about Kpowersave. But I would think it is strongly integrated in KDE. And as this is a server, I never would have thought that you would have KDE (or any other DE) installed.
It seems that you are so focussed on what you have build there, that you think that other people do understand that from the few lines of your post.
Also you wording is not very precise and apart from the fact that people often have different ideas with the same words, we now have even different words. At first you talked about a media server and I had a vague idea about a web server with streaming audio/video. But now you talk about a file server. And then before my eyes I see words like NFS and (in this case because you talk about Windos clients) SAMBA.
My suggestion is that you need to tell more to give people ideas about what you do. Except when some clairvoyant member of our community comes to your rescue.
Henk, as much as I appreciate the attempt at helping me, I have to tell you that you’re coming across as just a little bit rude to me. And I realize that you’re some kind of amazing Linux expert and I’m just a novice, but I think one reason you’re having so much difficulty understanding my question(s) is because of a language barrier. What I’m asking for is really rather simple, a way to keep a headless server from going into sleep mode when I want to use it through TightVNC. I can’t imagine what other information I could possibly add to my previous posts that is required. Hey, maybe instead of talking about clairvoyance, you could just come out and ask for whatever it is you seem to need so you can understand my question? Nah, never mind. That would be too much work.
Pardon me for using the term media server and file server interchangeably. If that confuses or offends you, it wasn’t my intent. The server actually does both tasks. Imagine that! And I can’t see how whether it’s a file server or media server, or both, could possibly impact the answer to my question.
If I have misread the intent behind your posts and you’re not trying to be condescending, then my apologies. However, considering the fact that I’m obviously unable to convey my question in a manner that you can understand, how about if you just call it quits and let’s see if someone else who may be able to understand me can provide some assistance. If not, I’ll be glad to keep searching and maybe I’ll find a forum where it’s not a crime to have a limited understanding of Linux. Do you have to be born an expert to post here, or is learning allowed?
I only want to get facts asap. When you think this is rude then it be so.
A question like, what exeactly is the functionality of the system (NFS, SAMBA, Apache, other server programs), to find out what the criteria could be for the system to go sleeping, has to be answered for any operating system imho, not just Linux. A system is never doing “nothing” and one has to identify what are the processes that signal that the server is used as such (for the defined services) to be able to decide if it should go sleeping. A power save tool for a desktop decides this on desktop activity (keyboard mouse, user input), of which there isn’t to much on a server only system. And when you answer on a question about what the serving programs (deamons) are with: “I can’t see how whether it’s a file server or media server, or both, could possibly impact the answer to my question” I really think I can not help you.
I will close this time with a sentence which means the same as that of my last post (but with different, less lightly wording): I hope others do understand beter what you mean.
You’re right, there isn’t too much. In my case, there isn’t ANY desktop activity on the server. The reason I posted in the first place was to see if someone could suggest a method of keeping the server awake some other way.
You probably thought that because you also thought I knew what I was doing with Linux, but as I’ve said a couple of times already, I don’t. This server is basically nothing but a glorified NAS device. I store all my data on the server, including media files. Yes, I use SAMBA. I chose KDE because I knew nothing at all about Linux. I tried several flavors, including server varieties, before settling on OpenSuse 11.0 and KDE. I chose that solution solely because I was able to get it to work, no other reason. So now I have a “server” with a desktop OS.
I am sorry I didn’t make all this clear in the beginning - if I had felt it would be helpful I would have included it in the original post and (hopefully) avoided all this confusion.
But as you mentioned in your last post, Kpowersave is looking for some user input (keyboard, mouse, etc) or it puts the system to sleep. What I am searching for is a method of keeping Kpowersave from putting the system to sleep while I am actually using it, either to stream media or copy files or whatever that may be. If there isn’t something I can do with software I will probably just buy a wireless mouse and try to remember to click it every now and then, but that seems very klugy to me and I’d rather not go that route.
AFAIK you have to write some script, which tests for certain activities after the 60 minute limit. If the scripts returns an OK status, the machine can suspend, if not, wait for another xx minutes. Or in other words: make the suspend command conditional.
You could always just not use any powersave settings and just shut it down when you are not using it via a telnet/ssh/VNC connection. That way it wouldn’t be on all the time and would shutdown while you’re using it.
As GSVRasputin allready suggests, Kpowersave can not be a problem at all. Configure it to do nothing. I have KDE running here, it never automaticly goes sleeping because of Kpowersave. AFAIK it is by default not configured to do so, thus I think you configured it doing this.
This being a SAMBA file server (and not much more), you could even do without KDE (though it does not matter much if you have the small disk space needed for it).
I thought, like Knurpht, that you are seraching for a method tho bring the system down (or suspend it) when it is not doing it’s intended purpose (SAMBA file serving). The solution both Knurpht and I are thinking about is a script that is run regularly (by cron) and then decides by testing for certain processes if the system is “idling”. Then stores/removes a time stamp. When after 60 mins the time stamp is still there, the shutdown/suspend should be started.
I do not say this is very easy. The finding out about the processes could be a painfull try and error process, but it may be easy, I do not know. Also the test frequency could be a problem. When one tests every minute and access from the clients can easily fall in between one minute, the we do not monitor often enough. I hope you understand what I mean.
But generaly spoken such a script can be made.
It must be the end of your day of work ;). I went the second page of the thread expecting to see one of those nice examples of your scripting, then this showed up… First good laugh of the day.
GSVRasputin, your suggestion would work well except for the fact that I am unable to put the server in sleep mode via my VNC connection. I can shut it down entirely, but I don’t want to have to boot the server every time I use it so that’s not an option.
As for writing a script to monitor processes and/or activities as Henk and Knurpht suggested, I understand the concept but I haven’t written a script since DOS was popular back in the late 80’s and while I could probably do it (eventually), it would take more time and effort than I really want to invest right now.
Looks like I’ll just live with it as is, for a while at least. But I appreciate you guys taking the time to try to help out.
In your case I would make the server completely headless, i.e. not install X or a desktop environment, and let it run in runlevel 3. Whenever you need to access it, you can still use ‘ssh -X -l YOURUSERNAME IP_OF_THE_SERVER’ to run programs. Yast can be run on the server directly (without the -X option), you’ll like it if you still remember DOS. But it works the same as on KDE4 or Gnome.
I support Knurpht in this. Make a server a server.
BTW talking about “the fact that I am unable to put the server in sleep mode via my VNC connection”, does anybody know how to hibernate/suspend a system from the CLI? Because that would be crucial to any scripted solution here.
There is info in the online documentation for s2ram here. This can be used to suspend from the command line. There are several other options as well, from what I have seen. Some other examples I have encountered:
echo -n S3 >/sys/power/state
echo mem > /sys/power/state
pm-suspend
I have been looking into this myself recently, as I have a similar setup to the original poster. I have a computer with OpenSuse 11.2 installed, which runs Samba to share files with the other computers in the house, which have utilities to use wake on lan to bring the computer back up. This computer does not need to be running 24/7, so I would like to set it up to suspend when it isn’t actively being used. I set it up for runlevel 3 (no DE) as default, but do have KDE installed to help make some things easier, and to add flexibility to the machine. I hope to have it serving more functions eventually as I learn more about setting it up. I was using KDE to get the suspend to ram feature, as that is the only way I know to make it happen automatically, but as the original poster stated, this doesn’t work well for this application.
I figured the easiest way would be to monitor network traffic periodically, and determine the data amount difference over a set time frame to compare it against a static threshold value. If the traffic exceeds that value, then something is streaming and the system should stay up. This would be setup as a cron job to be automatically run. I got as far as pulling the transmitted data amount from ifconfig and assigning it to a variable, so that it can be compared against the same test run after a delay period. Unfortunately, I can’t get my bash script to do the math to find the difference between the two amounts for comparison against the yet to be determined threshold value. Scripting is definitely not one of my strong points. For what it’s worth, I will post what little script code I have completed. Perhaps it will be enough to get someone else started, or someone can tell me if I’m way off base…
This script was run while streaming music from the server, to ensure traffic was taking place. As I understand it, I shouldn’t need to do anything to specify these values as numbers rather than strings, if that is not the case I would definitely like to know.
#!/bin/sh
DELAY=30m # time between ifconfig runs (set in seconds while testing)
TX1= ifconfig eth0 | grep TX | grep bytes | cut -d: -f3 | awk '{print $1}'
echo $TX1 # for testing purposes
sleep $DELAY
TX2= ifconfig eth0 | grep TX | grep bytes | cut -d: -f3 | awk '{print $1}'
echo $TX2 # for testing purposes
# The first two values are being correctly applied to the variables TX1 and TX2.
# At this point it would subtract TX1 from TX2 to get the difference. All the examples I
# have found for variable math in bash scripting have been unsuccessful.
TX3=$(($TX2 - $TX1)) # Results in: syntax error: operand expected (error token is "- ")
((TX3=TX2 - TX1)) # Results in a TX3 value of zero, regardless of TX1 and TX2 values
A few other equations and several attempts at using bc also failed.
Good to see someone running (or at least walking) with this a bit. You’ve already exceeded my scripting ability so I won’t be of any help, except to mention that I finally gave up and started looking for workarounds and just two days ago settled on a KVM switch. I expect it will meet my needs well enough - not automated, but it should be a simple and quick matter to switch to the server and shut down or wake up at will.
However, if you do manage to get that script working and want to share by all means go for it!
I had a similar problem: I want to shut down my server if there is no system active in my local net. I wrote a small script which executes a ping to all known systems and stops the server if no box is active any more. Because that’s a problem which pops up from time to time in a forum I uploaded the script ishutdown. Should be easy to adapt it and to suspend instead to stop the system. There are even some additional features implemented: The system can be unconditionally shut down to a specific time to make sure it’s down over the night and it’s not shut down if a user is logged on to the box.