LinuxMCE Forums
General => Users => Topic started by: Riggs on June 07, 2010, 11:22:15 pm
-
I was wondering if i could integrate my UPS into the core, so if i have a power out the core would send shutdown commands over ssh to over systems and shutdown its self.
I might be able to create some sort of script but i have no idea how to make it work with the core.
If you have any pointers on scripting like this then please help
-
I would imagine you could make a device template especially if it's rs232 . and you could fire events based on power outages and send the core a halt message.
I am sure Thom could expand on this.
Tim
-
I forgot about the template system, im still learning, my ups is USB Rocketfish 1025VA similar to the cyberpower powerpannel brand.
I'm just this minute reading up on NUT, there are three config files to edit http://www.linux.com/archive/feature/128099
the next thing after that is to work out how to send the command through ssh, that way you can shutdown windows to using Cygwin
-
Or in case of not having a smart UPS (with RS-232 interface), you can build your own sensor.... using a resistor, relay and make the RS-232 interface. See http://www.linuxjunkies.org/html/UPS-HOWTO.html
In my early days as sysadmin, i had one of this self-build sensor and the daemon... and it worked for years.... just adjusting times when the UPS battery banks changed.
-
well i don't need to build that but good info though.
I guess at some point I'm gonna have to buy an rs232 card, but then my question is why do i need to go back in time when we have USB it's like the TV card linux will support the old one and not the new ones.
Anyway, I'm guessing i would need to install NUT as it does have the drivers for the unit but i cant find how i can get nut to run a bash script on events or even integrate NUT with the core,
Remember I'm new so thing don't look easy to me
-
An USB to RS232 converter will be cheaper than buying a card.
-
thanks i will look into that
-
Maybe I'm missing something, but if you lose power then either the other computers are on a UPS of their own (or are a laptop) or they are already down. Unless of course it's just local to the core, knocked power cord out or tripped a breaker, in which case the other systems will continue to have power. If the other computers have their own UPS it makes sense for each of them to monitor their own.
The ups/controlled shutdown on power loss is a good idea, I'm just a bit confused as to the benefit of trying to shutdown other systems when you lose power on the core.
-
Not every system is gonna be PXE booted i look at LinuxMCE as a brain for the house, that controls everything possible.
In having the core communicate with the UPS it can a lot more function like for alarm systems etc.
My system can keep power to three PC's for around 30 minutes and I tested it with just the core and it kept it up for 64 minutes.
All my PC's are connected to the UPS power source but only one PC can communicate with the UPS unit.
-
So, all the 3 pcs and the core can get an USB to RS-232 adapter (around US$ 2,50 on ebay) and run the powerd or upsd daemon.
When there's a power outage, they will shutdown in 20 minutes.
The relay power feed will be done by the normal electrical line (not connected to the UPS).
Cheap, simple, clean.
Check which ones are supported by the linux kernel (google will help).
-
Any DCE device can emit events, that the rest of the system can respond to. If you can communicate with the UPS, and get status data, then you can write a DCE device with DCEGen (for C++), or GSD (using Ruby). Events can be added by the Web Admin, into the database, and from that point, referenced by the code.
-Thom
-
What would be the easy rout for a none programmer
-
*hmm*
This is how it is...
I just laid it out what you needed to do...so... either you have two options:
(1) you do it.
(2) you pay someone else to do it.
There is no way to DUCT TAPE IT.
Cold hard facts.
If you want it bad enough, code it. All the tools are available to do so.
-Thom
-
i am willing to code it other wise i would not of ask "What would be the easy rout for a none programmer" in the terms of what language would be easiest to get it going and maybe some pointers as to how i would integrate with MCE, yes i can read all the wiki's and faq's out there if i want to create it next year or i could get a point in the right direction and getting it done with in a month or so. not every one is lazy in the forum that asks for help.
Sorry but I don't mean to write like this but i did not mean to get a response like that as if to imply that i'm lazy or in fact dumb.
-
You can write DCE devices in one of two languages.
C++, which means you use DCEGen.
Ruby, which means you use GSD.
You specify which one you wish to use, when you create the new device template.
The purpose of the device template, is to define what it is, what commands and events the device can emit and accept, and any information the plug and play plugin can use to determine how to detect the device. There are plenty of links to allow the creation of new Manufacturers, device categories, command and event categories, and new events and commands, as needed..but please, only do this if an appropriate group does not exist.
Once this device template has been created, it can be checked into sqlCVS. Once it has been checked in and approved in sqlCVS, you can run DCEGen (if it is C++), or start writing the Device Template in the Edit Ruby Codes section of the device template. If you choose the latter, you should check in your code changes via sqlCVS.
If it is a C++ device, then DCEGen should be run from src/DCEGen of your source code checkout, followed by sql2cpp from src/sql2cpp to generate the needed constants. These packages can be installed via apt as pluto-dcegen and pluto-sql2cpp respectively, and since they are installed in /usr/pluto/bin, you'll need to use the full path to refer to them.
DCEgen will create a full C++ project, with all the scaffolding needed, you fill in the blanks of each command method with code to deal with the commands. For events, you'd have to spawn a thread, and emit events within it.
There are plenty of example devices in both the Ruby and C++ realm, that can help you. Hopefully this should give you enough to start digging for info.
-Thom
-
Thank you Thom for the help.
So far i have looked through the list of manufactures and devices and i see nothing for RocketFish so i created it and added my model for the device 1025AV.
now i have looked an the NUT website http://www.networkupstools.org/ for drivers thinking it could help me write the code, I did find the source code and downloaded it, I dont know the lang it is in but i can read it thats a start lol, i think i have fount the drivers.
i guess what I'm trying to do you would call it porting
-
Well i am getting no were fast.
there is no information out there on how to create these sort of drivers its all about AV TV etc, I have fount what i think is the drivers nut uses but I don't know where to start.
I dont even know how the to get the core to know what device i want to talk to and where to find it just to send a simple battery test command or waht i think is a battery test from looking at what i think is the drivers.
-
the first step, is figuring out what exactly what commands you can send to the UPS to do things... (On, Off, etc.)
The second step, is figuring out what information the UPS can send back to turn into events. (Battery Level, Overvoltage, Undervoltage, etc.)
-Thom
-
I have attached one of the driver files i'm looking at for reference could you tell if i'm heading in the right direction, if i'm looking at the right thing for starts
-
I would probably study and wrap NUT, making what is essentially a bridge to translate NUT messages to DCE messages.
This would be a device that could handle whatever drivers NUT supports.
It would do whatever it needed to do, to get messages from NUT, and act upon them using DCE stuff...
This is a pattern used by many parts of LinuxMCE, for example, for MythTV, they expose a telnet port that our DCE device MythTV_Player connects a socket to. The MythTV_Player has code that talks to this socket, and sends commands. It also listens on the socket, and when messages are recieved, it emits events (such as when a screen has changed.) that it reacts to.
How this is implemented is an exercise for the reader, it's open ended.
Devices can have child devices. Mostly these child devices do not have device drivers themselves, they are merely end points, where the router can send a message to. You would have a child device for each UPS, which would probably at the very least, contain device data for which driver to use, and what information the driver would need to connect. There is a method in C++ and GSD drivers called "Received Command for Child" so that the big parent device can get the command and act upon it.
This is the pattern, LinuxMCE is a messaging system.
-Thom
-
OK i think that may sound more easier I know that NUT can communicate Over the network, I'm guessing that the core could receive that.
so step one would be to install NUT
2. would be to find out how it communicates
3. create a device to receive the communication
Is there any sample devices in DCE i can reference
-
yes,
for GSD, look at the Panasonic IP Camera device template. It uses a single TCP port to send web requests and receive a single jpeg buffer in response to a Get Video Frame command.
for C++, there are many examples in the SVN tree:
http://svn.linuxmce.org/svn/branches/LinuxMCE-0810/src/
a good example, would be the VistaICM2 driver that Adam and I did for the VistaICM security panel.
Once you have a working driver, then the next step is to work on making it plug and play (LinuxMCE can for example fire detection scripts for RS232 devices, while USB and TCP/IP devices can be detected by vendor:model pairs or MAC addresses respectively.) If NUT has its own facility for detecting devices (not likely), then it could send Device Detected events to the system.
-Thom
-
In NUT you have 5 config files
1. /etc/default/nut (this is just to get nut to start, changing two no's to two yes's
2. /etc/nut/ups.conf (this is to tell not what driver to use and port)
3. /etc/nut/upsd.conf (this is to allow network connections to NUT to monitor status and issue commands)
4. /etc/nut/upsd.users (this is to setup usernames and passwords, ie admin and monitor user)
5. /etc/nut/upsmon.conf (this i guess tell Nut what to do on an event)
I you was to issue the command "upsc ups1@localhost" it would print out the complete status of the ups.
Nut will also alert you on a terminal if the status changes ie on battery or battery low, back on ac.
i'm still reading through stuff.
my big problem is it is not easy to understand webadmin in respect of creating a new device like this.
-
Have you read: http://wiki.linuxmce.org/index.php/Developers_Guide ?
-Thom
-
OK i get the DCE part and i think it is a great way to handle commands and events i can see how easy it can be to do almost anything.
its like you have a word in your head but you cant say it for some reason that is how i feel i see DCE i see how it works and what it can do in my head but then i look at webadmin and I can configure it, there are so many options and things to configure but no real documentation, if you was to step out of your shoes and step into another persons you would see where i am coming from.
It is excellent piece of software programming, I just need to understand it, I'm not gonna give up
-
this is just a basic idea just so i can see some thing working and learn to improve it
If i got Nut to output events to a text file how would i get DCE to receive it, if you do deside to explain it, try a go here click there reproach, (but only if you have the time) i will then see about putting it on the wiki as well.
and yes i can see that i am being a pain in the a*&.
I tried to setup a event in webadmin so at 2300 it would execute a command to ssh over to a PC and shut it down but it never worked, i know to you this would be an easy 30 second task but to others like me its not, yes i looked it up http://wiki.linuxmce.org/index.php/Common_Events_Examples but the screen i look is not like what it shows here and it doesn't even give directions as to hows it is done
-
You can use the App Server device on the core or a media director to launch applications. There is one for each media director, and one for the core.
-Thom