View Full Version : Process that shows SBS is active ?
I've built a server using Ubuntu 9.10 to provide Squeezebox streams plus files and print services to Windows clients both via Samba.
I'm reaching the final stages of configuration and am now onto the power management setup, I want the box to provide the services I require and then sleep when not.
The tool I'm experimenting with at the moment is https://launchpad.net/powernap which powers down the box when certain processes aren't running then problem I have is I finding a process that indicates when SBS is actually doing something rather than sitting idle doing nothing.
Anyone got any ideas on which process I should be looking for or failing that an alternative solution to my problem ?
Thanks in advance ?
btw for anyone interested in this general idea there's further info on what I'm trying to do here:
Lookup the srvPowerControl Plugin thread in 3rd Party forums.
It has a lot of features, and you can mix and match with your other power management routines.
Lookup the srvPowerControl Plugin thread in 3rd Party forums. It has a lot of features, and you can mix and match with your other power management routines.
Thanks for the tip, I have however looked at this already, while yes it does have the feature 'Monitor attached players and shutdown the server after an idle period.' it wouldn't help as my box does more than just SBS so I need a system level power manager that monitors other activities(Samba and BT) on the system and shuts down when non of them are being used...
I'll go and have a dig about to see how srvPowerControl sees if the players are busy.
Anyone else got any thoughts ?
I was thinking of a more recent feature of srvPowerControl which is a status flag (inactive/idle/active) raised by the plugin. That was designed to communicate with external power management solutions (lightsOut ?).
You could ask gharris999 for more details and advice. He is the godfather of PM in these parts.
Otherwise, you can whip up a bit of code that queries the server (and/or the players through the CLI). I think srvPowerControl does that and more and better than you would do it.
(I have coded my own PM daemon. An ugly beast of several hundreds lines of perl code, to manage diverse protocols/apps incl. SB players. You really don't want to do that unless you're very bored.)
Ah yes I'd seen that feature, as far I could tell though if your turn it on in srvPowerControl it'll then power off the system when the players are idle(and perhaps when something (eg. samba) else is busy), there's no way of monitoring the players only, I need to look at it again.
I guess I could mod the Powernap daemon to check if the players are busy directly (though it's coded in Perl which I no nothing about) I was hoping this kind of thing would be routine, obviously not :-(
At the moment though I'm thinking the Powernap isn't really up to the job as (as far as I can see) all it does it monitor specific processes for presence rather than activity which is not really any good for SBS, Samba etc so am beginning to wonder if I need to write my own power daemon, something I don't really want to do or ditch linux go to Microsoft...I'm still in shock from having to code the sequence to go into suspend then come back on at go into hibernate if not required during the suspend period :-)
How does you power daemon work ?
I set a single instance of it, with a "run" thread that gets polled by the linux watchdog, and a "loop" thread that looks every minute or so for the status of nfs, afp, smb, sbs, console sessions, network traffic, and recently I added backuppc.
The "loop" is slow and none too bright, and painfully returns a vote (0/1) for suspend or keep-alive. Then that status is repeated at will by the "run" thread when it receives a network connection.
The standard linux watchdog runs on its own, and queries the "run" thread via the "test-binary" facility (see the man for watchdog.) I use the wachdog because I want the machine to reboot itself when things go awry.
(But if the kernel thawing process fails at wake, there is a chance the watchdog won't operate. With the right kernel and amount of testing, you can get a reliable system even with dubious hardware.)
In addition the "run" thread reaps flags which are placed in a specific directory, and can force it to respond something other than what the "loop" wants. So I can block the machine from going to sleep by doing "touch nosleep" in the right directory (I use that when backuppc starts a job, for example), or have it reboot cleanly (without being killed halfway in the process by an angry watchdog.)
This last feature more or less requires the "loop" to be stateless, it rediscovers the situation all over at each run, until the machine sinks into sleep (and it restarts from wherever it was at wake time.) Suddenly, stateful actions like auto-switching the SB players to mySB.com when the server goes down (and grabbing them back when up) become a serious juggling act.
For suspend I tweaked the system a lot. I initially used the pm-sleep/pm-suspend suite of scripts (made for laptops) and scrubbed all I could to make it faster and leaner. I finally did away with it and call "s2ram -f" directly from the watchdog test-binary. (not exactly, but that's the idea)
The machine is up and operates in under 10 secs (from the press on the SB IR remote to a song to start). I think you want to use linux 2.6.26 at least. I am currently running a system like this with 2.6.28. My parents server work like this, they use it every day and it has an uptime that seems only limited by the frequency of power or maintenance events (I've seen > 150 days)
I'm sorry but I can't begin to describe the uglyness of that code. I could give it to you but I doubt that would make any good. But feel free to PM if you like puzzles.
(for samba and afp I do an "lsof" to see if there are opened files within the network shares. works ok.)
Well if I wasn't confused I am now :-)
I'm not sure I'm that worried about the robustness you've built into your method, at the moment I'm still struggling with the basic requirement of working out if something is being used or not
>>>and a "loop" thread that looks every minute or so for the status of nfs, afp, smb, sbs, console sessions, network traffic, and recently I added backuppc.
How do you check the 'status' of each of these individual processes and what statuses are you are triggering on ? (I saw your comment on lsof for smb)
Have a look at the attachement. These are bits and pieces extracted from the perl source, I hope it is readable enough.
A few comments:
- I use a "pipe" of values to average read points taken at each run of the loop. This way I can avoid voting for shutdown just because of a single glitch, and add some inertia to the system.
That's not the brightest system, for example a recent activity mark might be more meaningful than one that is 10 min. old.
- the sum of each pipes gives the active/idle status of each feature (afp, nfs...), then this value is modified with a weight %. The weight is useful when debugging (set to 0 to disable a cause of suspension) and to deal with stuck connections.
- In the attached code I finally check against a magic value of 0.185 to decide if the machine is active or not. This was defined through trail and error.
About Net:: Daemon, you can have a look on CPAN ( www.cpan.org ) to learn more.
Powered by vBulletin® Version 4.1.12 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.