Network UPS Tools (NUT Server) Ultimate Guide

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
last week i finally decided to investigate another open source tool to monitor and manage my ups devices i was looking for a tool that could help me unlock the data inside of my ups allow me to do some shutdown coordination and let me see my ups data without having to look at the lcd screen that is if you're lucky enough to have one so when it comes to managing power devices like pdus or ups's you should look no further than nut server nut server or network ups tools is a service that you run on your machine to monitor the status of a connected ups it works with over 140 manufacturers and maintains a common interface to communicate with the ups it also has cross platform support so you can run this on linux vsd or even a client on top of windows and it also has multi-architecture support meaning you could run it on arm x86 or x64 so we can run it on a server a desktop or a raspberry pi personally i think one of the coolest features of nut server is being able to run the client on a remote machine and have that system shut down when the ups server tells it to and that's without connecting it to that remote machine this means you only need one system connected to the ups that's running nut server and all the other clients can just listen or subscribe to changes on that ups so with all of these features and device support it comes with some complexity and to be honest it's taken a while for me to get my configuration just the way i want it and while nut server has diagrams covering a simple configuration an advanced configuration a big box configuration and even a bizarre configuration and hopefully mine doesn't fall into the bizarre configuration because i think my setup falls into the same category as most people's home labs do so today we're going to configure all of this and more we'll configure your ups and the driver we'll configure the nut server and the nut client we'll also configure a web interface to see all the graphs and data for our ups and if there's enough time we'll also configure a secondary ui using docker you know i couldn't do a tutorial without docker but it's not required we'll also configure a windows client for none and then finally we'll configure remote monitoring and shutdown for your nut server and not clients and don't worry i'll have all of my configuration in my documentation site and you can find that in the description below and if any of that sounds good to you don't forget to like this video and subscribe if you haven't already so let's talk about some hardware that you'll need first up is the most obvious it's a ups you'll need one of the supported ups devices that nut supports so i've connected three already one trip light and two apcs and they've been working really well with some tweaks the first ups is a triplet 1500 lcd smart ups it's the rack mounted one that powers all of my servers in my rack this includes both 1u servers my disk shelf and all of its disks and another server at least while it's on the next ups is an apc 1500 ups pro this one's not rack mounted per se but i did mount it inside of my rack on a shelf i didn't want to rack mount this one because of the limited space and i want to do a few things different in the future this one only powers my main networking equipment my udm pro and my unifi switch pro 24 port poe switch i have this on a separate ups because i want my network switches access points and all my connected poe devices to stay on longer than just a couple of minutes that i get on my main ups the last one is an apc 850 va ups battery backup and surge protector this one's a little more consumer friendly with its ports and its price but it lacks the lcd screen which well actually fixed with nut server this one powers most everything on the wall but mainly my fiber modem this ups will power everything on this wall for about three hours which could also dub as a phone charger or tablet charger if the power was out that long and that's why i've separated this one so those are the three ups's we'll be configuring today if you're interested i'll have some links to these ups that work with nut in the description below and don't worry if you don't have one of these or these specific models the configuration is almost exactly the same for most ups's you'll want to check the hardware compatibility list to see if yours is supported and even if you don't see yours listed there it'll most likely work with a generic usb driver so next up you'll need a system for this to run on like i mentioned before you can run this on various operating systems and processor architectures so really the choice is up to you but i'm gonna run mine on my raspberry pi my raspberry pi 4b has four usb ports which is perfect to connect my three ups devices now this might seem odd at first and it might even fall into the bizarre category that we saw in the diagrams earlier but i don't want nut to be running on one of the machines that's going to be shut down so i want this raspberry pi that's running nut server on until the power completely drains from the system now i can tweak that later and shut it off when the power is at about one percent but really i want this on no matter what so we'll get into that here in a little bit so i'm gonna connect all three ups's to this raspberry pi and the usb ports and it doesn't matter which ones you choose as long as they're plugged in and attached snugly and a side note this raspberry pi is actually poe powered so it'll run off my switches ups if the power dies and this is another reason why i've kind of broken up all of my ups's but after they're connected just make sure that your ups's are turned on and they're not running on battery power now it's time to configure the driver for your ups and then we'll configure none so you'll need to open a terminal on that machine where the ups's are connected or ssh into it once you're in you'll want to run ls usb so this will show you all of the usb devices and what bus they're connected on so you can see here i have an apc device connected another apc device connected and my trip light ups connected and now we can install the nut server the first thing we'll want to do is update our repositories then we'll want to install nut not client and nut server using sudo apt install not not client nut server next we'll use a utility called nut scanner to actually probe all of these devices and get some information from them so we can configure them a little bit easier and that's as simple as running sudo nut scanner dash uppercase u then after you run that utility it will go ahead and scan and probe those devices so you can see here my first one not dev1 you can see the driver is going to use this generic usb hid ups driver it's detecting the usb port as auto it gives me a vendor id and a product id which is important for trip lite devices and then it gives me the product name the vendor name and a bus id where this is attached and you can see the same thing from ipc devices and this helps us with our configuration so copy and paste this or make note of it so we can use some of these values in our configuration so our configuration is stored in etsy.ups.com so let's edit this file and if we look at this file we have a lot of settings that are commented out and so we could edit this file but what i typically do is just copy this example over to an example file and then create a new one myself so i close out of here and then i'll back up this file to an example file using this command then i'll go back and edit this file again and i'll clear out all of its contents now you might want this for some of the examples there but it's pretty noisy and i know the settings we need so a couple we're going to add is poll interval equals one this is how often it's going to pull that device and max retry of three this is how many times it's going to retry to connect to that device before it deems it as failed and these should be pretty low and should rarely ever fail because it's communicating over usb so the only time this should fail is if the device isn't connected next we're going to create our devices so in this directive here we're going to create our first ups device now you might only have one so only do this once i'm going to do all three so you can see all the examples of how to configure ups's for other manufacturers but this first one is my trip light device now i've named this trip light and it can be anything you want it to be i've just named it according to something i'll remember now when you name this you'll need to make sure that you don't have any spaces in here and you don't have any special characters so i'm just going to name mine trip light here like this next is the driver now the driver most likely is usb hid ups now how did i know this well we used the scanner that told us that's the driver to use but you can also look on our hardware compatibility list that i mentioned earlier and it will tell you which driver to use but most ups's i've seen use this generic driver and if you use the scanner and it told you to use something else just plug it in there next the port is for auto and that's because we got it from the scanner and next is just a friendly description for you that you'll see in the website and in your configuration and it's just a mental note of what this device is the vendor id is important for triple a more than the others so for trip light you actually need this vendor id 0 9 a e or depending on what the nut scanner told you was going to be and the product id is also important too the product id is 2012 this must be the year they created this i don't know and those are really the only values you need for chip flight and for abc it's almost the same so here are my two apc ups that i'm connecting so this is just the name that we're going to use elsewhere to refer to this the driver again is the same generic driver port is auto a description vendor id is different from trip lite but we'll still need it for apc product id2 and then a serial number so this one is important for apc devices so we should have seen the serial number that came out from the scanner and you'll just plug it in here and the same goes for this apc here so as i mentioned earlier this apc network is the one that's powering my network devices and this one called apc modem is powering my modem and a few other devices and it looks exactly the same except for the description and then the serial number will obviously be different too so once we have that we'll save this and we'll close out next we're going to configure ups mod it's part of none and that configuration is stored here so it's in etsy not upsman.com so let's edit that so in here again you'll see a bunch of values and default values and documentation within this configuration file but i'm going to clear all of this out to reduce the noise so again i'm just going to copy this config to an example and then we'll edit this one again and we'll clear out all of the values there's probably a better way to do this but this is a lot to scroll through as you can see when you want to configure this later i'm still deleting okay there we go and also nut server is very well documented you can find all of this documentation on their website it's impressive how much things are documented so i might not dive deep into each variable but know that nut server has done a great job documenting this so in here on ups mod we're going to set up monitors and so the way we set up monitors is like this so i'm going to say monitor trip light that's the name of that device we configured a little bit ago at localhost so this machine and then one is how many ups's are connected to this device next is the account which i'm using admin and then a password and then whether or not it's a master or a slave so let's talk about these so again we're setting up monitor this is my username for that device we just configured at localhost it's this machine so it's going to be monitoring that service on this machine how many ups's are connected and then some credentials and then whether or not it's a master or a slave so the way i set mine up is i treat mine as a master if it's physically connected to the ups so this one is physically connected to ups so i'm going to say he's master and for me it's easier rather than using master and slave to use client or server terminology now i know it's not a one-to-one with the way that they designed it but it's easier for me in my head to think this is going to be my server and other connected devices will be the clients anyways so i set up three monitors on this one for each of my ups's they're all set to one because they have one ups connected they're all going to use the same accounts so admin they're all going to use the same password which is secret and you can set this to whatever you like i think there's a limit of eight characters on this don't quote me on that uh but i would use something around eight characters in random i'll sprinkle one in later um and then these are all going to be masters and then there's one more setting that i've set up and it's to run this as root now you can set up additional accounts and restrict this service to be able to run as a different user so i'm taking a little bit easier approach in saying run this as the root user because the service that this is running as will need to do some additional things that require root permissions so anyways we'll want to save this upsman.conf and then we'll close out next we'll want to edit etsynutupsd.conf and when we edit this again we're going to see lots of documentation built into this configuration file and no config so what do i usually do we copy it to an example file we edit this file again clear it out and we start all over so in this file is where the service is actually going to listen on and most of the time they'll tell you to listen on localhost so 127.00.1 and it's on port 3493 and that's great if you're running in standalone mode where you only want to communicate with yourself but i actually need to communicate with this from other devices so i'm actually going to listen for all i p addresses and i do that by setting it to 0.0.0.0 and so if you're not going to run this in a client server configuration between two different machines you can set this back to localhost but if you are going to connect to this from another machine you'll need to allow this address for 0.0.0.0 so let's save that next we're going to edit the nut configuration so that's etsy nut dot nut hold on that's etsy nut slash nut.com too many nuts so we'll edit this and again a bunch of documentation and a little configuration so what do i do copy it then edit it then clear it out so the only thing in here is mode equals none so as it stands it won't work we actually need to set a mode for this so i think there are a few modes here i don't think none counts but i guess so so mode of done i don't think it'll do anything then there's mode of standalone which is the mode you would put it in if you're only going to run the nut server and not client on one machine then there's mode of net server or net client so for me i'm actually going to set it to net server so this means it will serve out that api information on this machine to clients who connect who set theirs to net server we'll do that in a little bit so let's save that next we'll need to configure users so you saw earlier on our monitors we had a user of admin and a password of secret this is where we'll actually configure our users so if we edit these users again tons of config and documentation built into the config and no active configuration so i'm going to copy it out edit clear it and again i only do this so i have pristine versions of the original file called example and then i don't have a bunch of variables spread across a hundred lines of config because i've accidentally defined the same variable twice and i think the last one that gets defined is the one that wins and so you'll rip your hair out trying to figure out why something won't work because you set it on line two and in line 102. anyways enough of that do this however you like but this is how i do it so in here we're going to create a mon user so this is the user we're using to connect to this service to get information from the ups and as you can see here i just named it mon user this could be anything and then my password is secret that's what we said earlier or it could be random characters but we're gonna set it to secret and my account name is admin and it's actually the master now you can get pretty detailed and pretty fancy with users and settings i'm keeping this pretty basic but if you have more needs i highly recommend looking at the nut documentation for upsd.users it explains some of the advanced permissions you can give to this user and how you can restrict permissions to either a master or a slave and whether or not they can perform certain commands but for me i'm keeping it simple and setting the password here and setting this admin as a master so we'll save here and close out of here and now we should be able to restart all of our services now you can do this one of two ways you can run a whole bunch of commands to restart each individual service and the driver or you can just reboot the device rebooting is definitely easier or you can run all of these commands right here so once all the services are stopped and restarted we can start to see some communication happening so these messages that we're seeing are the ones we configured in ups mod so ups mon right here is actually monitoring the ups service that we restarted and you can see here i updated my password it's no longer secret so take note of that use something else don't use these random characters that i use use something else but because it's monitoring trip light abc modem and apc network on this machine when that service restarts it says that it lost communication with the device and that the devices are now unavailable and it should be reconnected to the server so let's test it so we can test or query this ups through the net server by running upsc trip lite or the name we set up at localhost and if we run that query we can see a lot of data coming back from that ups so you can see here my ups has a battery charge of 100 a run time of 794 seconds so a little over 10 minutes the battery voltage the name that we set up earlier the name that came back earlier the model the driver we're using the poll frequency so we can get a lot of this information and you can even query individual variables if you want to so if we wanted to query and see what's the battery charge for this device we would run that same command and put the variable afterwards and it would tell us hey it's 100. this is pretty cool so we can do the same thing for the other ones too we can run the same command for apc wall or apc network and that's cool and it's nice to see this information but we actually would like a web page for this and graph this too so if we want to install a web server on this device to serve out the information through a web page we would do it like this sudo apt install apache 2 and nut cgi then we'll say yes to this prompt then once it's installed we'll need to modify some configuration so we can edit this config file etsy.hosts.com so same pattern here a config file with lots of documentation built in i'm going to copy it edit it and clear it out and in here we're going to paste a configuration that looks just like our ups mod.conf we're going to tell it to monitor that device at localhost and give it a friendly name so my trip lite i gave it a friendly name of trip lite 1500 va smart ups and racks so i know and for abc i said the abc 850 va on the wall and then for apc-network i said the apc backup ups access on the rack so once we save that and close out then we'll run this command sudo a2 en mod cgi and that's just enabling a module i think for apache then we'll need to restart our apache server using this command so after we restart it we'll need to modify one thing etsy nut ups set.conf and in here same idea back this up to an example i'll clear this one out and then we'll need to uncomment this one line which i have secured my cgi directory then we'll save this close out then we should be able to go to the ip address of that machine or dns entry if you use it slash cgi dash bin slash nut slash ups stats dot cgi and see our statistics so here they are so here's my trip lite one we can see it's online the battery's a hundred percent we can see the input output and the current load and the current battery run time so this one only gets me about 13 to 10 minutes depending on the load and if we drill into this machine we can see some charts here so we can see it's a hundred percent the voltage the input output and just what we saw the load so it's just under 50 so about 40 percent about 40 it's right there and if we go back we can do the same thing for our apc so my abc 4 load the output is not supported but the input is and you can see the charge and voltage here too so this is the one that powers a couple of devices but mainly my fiber modem and then next is my apc one that's in the rack you can see that this has an hour and 44 minutes of run time and you can see the current load is only seven percent now that's pretty awesome because this is my unifi switch pro and my unifi udm problem with all connected devices including multiple access points multiple mini switches multiple raspberry pi's and lots of cameras so that whole system can run for an hour and 44 minutes until it totally dies and this is why i separated them out because i have a tiered approach to where my servers will shut down first then my unify will shut down next and last but not least is just my fiber modem now i can't do much without my udm pro but if i get to that point where i've been off power for hour and 44 minutes i know that it's going to be off for a lot longer so i want this battery just to charge my devices and i'll hook up an old router if i really need internet access but most likely i'll just set up my phone charge it instead of tethering anyway and then we can actually see the data tree so this is all the data we saw when we queried the client it's the same information but just presented in a web page so pretty cool we got this set up so the next ui is just an alternative ui and it gives you a lot of the same information but in a different way so the next one is called webnut this is actually a docker container that you can use to host on a totally different machine to query your nut server to get this information back so i'll talk through this really quick because it's not necessary but it is cool so this docker compose file pretty typical we're setting an api version we're configuring one service we're calling it none we're using this image technologist webnut the container name i'm naming webnut and then i'm setting up some environment variables so this is the host that the ups is physically connected to and the nut server's running on now it technically doesn't need to be physically connected to it but i won't get into that but it's the one that nut server is running on that's serving out the information so for me that's 192 168 0.120 then the ups port this is going to be 34.93 in most cases unless you changed it but i highly doubt you did next is a username that we use so ours was admin and then a password now i have this random password here yours could be secret hopefully it's not hopefully it's not password it's the password you use to communicate with your nut server and then we say restart unless stop and this helps if the container starts crashing it'll just restart itself unless you stop it yourself security options this is one i typically use no new privileges equals true and so this means the privileges within the container can't be elevated and then we're going to expose some ports and i got one wrong there should be six five four three so six five four three on the outside six five four three on the inside left is outside right is inside left is one you can change yourself so if you wanted this on 80 8081 would change it here but on the right side you can't change that because that's how they built the container but shouldn't matter so anyways we should be able to use this docker compose file create a docker compose file edit that paste in all of our contents and then save it then run docker dash compose up dash d dash force dash recreate i know i don't need to say four stash recreate but i use that command every time because it works every time whether i'm starting it creating a new one or replacing it so we can run that command it should pull down that container and it should start it up and if we go to that ip address and that port we should see our ups devices so we'll see the same ups devices that we listed so i have trip light apc network and apc modem so if we go into my trip light we're going to see a lot of the same information here we probably want to show more records than 25 because it gets clipped off but so here again we can see all of the same information here but we don't get charting which we got in the other one but still this is really nice to be able to see and i figured i may as well mentioned it okay so i also mentioned a windows client now we can run a windows client to monitor that same status information from that ups and we can do that using this client called windnut-client so on their github page all we need to do is get the latest available release i'm not going to go with a pre-release it's probably fine but i'm going to go with one of the stable ones and i'm going to download this msi here once we download the msi we'll want to install it and once it's installed we can launch it so once you launch it you'll want to go into settings and we'll want to configure some settings for it so here you're going to specify your nut hosts so this is the host that's actually running nut server and for me it's 192 168 60.28 now you can use the dns name here i highly advise it but this is the ip address of that machine the nut port is the same port again so it's 34.93 same port we saw when configuring webnut and then the name of your ups so this could be the apc that i had so apc wall or apc network or it could be trip light too then we're going to set up the polling interval 5 is usually fine then we're going to set up our login and our passwords or our credentials and this was the same login and password that we used everywhere else so mine is admin and then your password which is hopefully not secret hopefully not password but it's a real password and then we should be able to just hit apply and okay and you can see right now that it's actually monitoring my ups so you can see the same information we got before so the input voltage the frequency output battery charge ups load and the battery voltage so this is pretty cool so this is connected to my trip light so i could actually shut this down if that machine were to go down now this doesn't make a ton of sense in this scenario i'm just showing you this how it works but i could say once that battery so that battery that's connected to my server rack gets to 20 percent shut down this machine or it could also shut it down if the run time is lower than 120 seconds or two minutes hit apply and okay so now this machine will actually shut down if that goes on ups power now i said this doesn't make a ton of sense because if that's on ups power that means there's no power in here and i do have a ups connected here so i guess it kind of makes sense but you could see how you could use this say on virtual machines or something like that if a windows virtual guest is running on say your hypervisor and you want to shut that down when the host goes to ups power you could do that and there's a million use cases i'm just showing you the windows client which i think is pretty good now we have one more configuration and that's automatically shutting down another machine based on nut server's status but before we do that i should probably mention something about trip lite triplite took the most configuration to get working and i figured i should dive in just a little bit deeper for just a minute to explain a couple of things because this ups is pretty common for home ladders in their racks i figured i should mention this but if you're having troubles configuring your triplet ups it might be because the device is disconnecting over and over so how do you know that if you run the message i don't know how you pronounce that do you mess again if you run that you'll see your device in here and before i applied this fix you would see this device connecting over and over and over about every 10 seconds and it's pretty annoying because when it does that it actually can change the bus and the device id and so as it's changing the nut server has no way to get a reference to it to be able to query it so you end up in this weird crazy loop so the fix for it is actually to create this udev rule so we want to edit etsy udev rules.d called 999-nut-ups.rules and this could be named anything you want you should probably put it higher than what's in there so 99 is usually a good fit and a huge thank you to pcgeek from the community for sending this to me because this actually solved all of my problems so thanks dude appreciate it and if you don't know pcgeek is part of our discord community and if you don't know about our discord community you should totally join but thanks dude appreciate it so we'll want to create a new rule here helps if i have that path right so it's slash 99 not ups rules i copy and pasted my own comments copy pasta so anyways well edit this rule and in here you'll want to paste all of this truth be told i don't understand a lot of this but i actually found an old stack overflow post that pcgeek pointed me to that then referenced some old archaic email from someone who worked at trip lite who said to apply this so the internet told me so so it must be true so anyways once you apply this i actually had to reboot and after i rebooted with this applied then i no longer saw the device connecting in d-messig and then the nut server was actually able to connect to that device if you're not using trip lite don't worry don't apply this please don't won't help anything i doubt it'll hurt anything but won't help but if you are using a trip light because like i said it's popular among home labbers you'll want to apply this and then reboot your system so anyways back to what i was saying now we actually want to install nutclient on another system and have that system communicate with nut server and get status information from it and the reason why i want to do that is because i want to automatically shut down remote systems if the nut server says it's low on battery or it's been running on battery for a certain period of time and so this is how i'm going to orchestrate shutdowns of all of my hypervisors if the nut server that's running on my raspberry pi says the batteries at a critical level it's pretty cool it's pretty easy too well after you know how it's pretty easy so i'm going to remote into one of my proxmox servers this one's called helios and on here we're going to run apt update and we don't need sudo because we don't have sudo on debian on proxmox then we're going to run apt install nut dash client so we're only going to install the client on this machine and if you're using something that uses sudo like any version of ubuntu apply sudo here but we're going to install the nut client here and configure it to communicate with our nut server and then once it's installed we'll want to modify our etsy nut ups bond.conf now this should sound familiar it's the same configuration that we configured on the server so that the client could communicate with the server on itself it's kind of confusing but on nut server the first one we installed both the client and the server so it can communicate with itself so now we're going to configure this upsman.conf to communicate with our server and here's the configuration now again you'll have that example configuration you'll want to back that up and copy it to an example file like we did at least 15 times and then i clear it out and start all over so i have a clean slate now i'm not going to go through everything that's in here but i'll cover the highlights and again i just want to reiterate that everything is super well documented on nut server on their website and i'll have a link in the description below so we're just going to cover the highlights but again we're going to say run this as root this monitor might look familiar because we had it on our nut server but here we're telling it to monitor one ups and that one ups the user or ups name was a pc modem so i'm telling this to monitor apc modem and this is the ip address and this is how many ups it has connected to it only one and then the user which we set up and then the password or the secret now this should be secret or password but not those values your own secret our password and assure you i'm going to change this after this thanks defender no viruses okay anyways um so and then here i'm configuring it as a slave so really this is basically saying that this machine depends on the other one i'm going to call it client server except for it's a little more nuanced than that but this client depends on the other server so if the other one is in a bad state this one will consider itself in a bad state too but we're going to configure a few things we're going to say minimum supplies are one and this is the minimum amount of ups's that can be alive so some machines have multiple ups's and they can fail over super fancy stuff i don't i have one so i'm saying i only need a minimum but one here's the shutdown command so this is the shutdown command that's defined if it needs to shut down so how does this machine shut down well he runs sbin shutdown dash h if you're running a different flavor of linux or some other machine or unix-like machine check to see what your shutdown command is and set this here notify command is what it runs to execute notification messages so it runs this ups shedge ubs schedule uh command and we'll see that here in a little bit but when certain things happen this is the binary it's going to use to send out these commands poll frequency poll alert pretty pretty self-explanatory hotsync and dead timer pretty complex but 15 is a good value according to their documentation this power down flag is actually how it kills power to the ups this one is kind of dangerous because i accidentally triggered it a couple times and sent it to my ups server and shut down all three but this is just how it knows how to do it not that we're gonna use it but just so out knows it's defining it and then a whole bunch of notifications so notifications are defined and doing a little bit of formatting of the messages and then what happens when we get these notifications so when we get these notifications so this is the way i understand it it's going to write to syslog if you do a plus wall i think it's going to broadcast this message to all the listeners and then it's also going to execs something so it's going to exact this notify flag of online uh when the ups comes online it's going to write to syslog broadcast a message and then exec whatever we defined for online and you'll see that here in a little bit and the same thing for all these so we have these different events on bat low bat fsd common com okay combat down replace battery no communication no parent so a lot of things defined there and then there's a couple other that they have defined in their example that i carried over that they say to use so once we have that we'll save that then we're going to modify the nut slash nut client configuration so this is the nut client configuration on this machine and in here i didn't follow my own pattern but what we should be doing is copying this off and then creating an example and then using this so here the only important piece is mode and the mode is netclient so on our server we had that server on our clients now we'll have net client this is basically saying hey i'm a client to that server that's where i'll go for communication messages and statuses and querying to see if my ups is okay so we'll set this in net client next we're going to modify one last file and it's etsy nut upshed dot confirm and we don't need sudo on debian oh anyways this is the commands that we saw from the exact earlier so let's talk about this so first we're saying hey we're going to run a command script and where is our command script located we put it in etsy not up shedge cmd now we don't have this file yet we'll create it here in a second but it's actually going to run that script when one of these events happens python and lockfin just going to pronounce them uh but these are also necessary to create the pipes and lock files in this directory so python and lockfin are just our directories where pipes and locks will be written to and then we're defining a few things here on bat and we're sending a tire so on the on bat event we're going to start a timer and call on bat and set the timer for 30 seconds when it's online we're going to cancel that timer and say on bat online and then on battery if we get to this point we're going to start a timer and then we're going to call early shutdown and i set that for 30 seconds then on low bat we're going to execute on bat and then when we get the command communication bad we're going to start a timer for 30 seconds and then if communication is okay we're gonna cancel that timer and execute communication okay no com we're gonna execute combat shutdown we're gonna execute power down so this is just mapping from the event with parameters to this file the cmd file it's kind of confusing it confused me a ton over the weekend so let's actually check out this file now so we'll save that then if we edit this file which you might not have so you want to create it but we'll run a nano etsy nut up shed cmd and if we open or create this file you'll want to paste these contents into it so this is the shell script it's actually going to run so this looks like a case statement so on battery that command we got it's going to log out the output of upshed cmd the ups is on battery so this is what happens immediately when it goes to battery the next piece i defined is early shutdown so when that timer hits 30 seconds it's going to call early shutdown and what this is going to do is going to log out and say the battery's been on for too long for shutdown and then it's going to call ups mod with dash c and fsd for shutdown i think and it's going to do the same thing for critical so i have two events that i've wired up if it's on for more than 30 seconds it's going to shut down and if the battery is actually critical it's gonna shut down now how would i have one without the other well well if it was running on batteries say for 10 minutes and everything was shut down and had two percent left when it came back up and the battery was still critical it would shut this back down now that's a lot of automation that i still haven't done yet but that's the idea and so once we have this and we save this we should be able to trigger this now there are some fancy commands you can run on the host machine to trigger this but i think the best way to actually trigger this is to actually pull the power so i'm going to show you what this looks like when it actually happens and real quick one thing i kind of skipped over is that we should actually test this really quick and it's really easy to do so on the right side is my proxmox machine that we just configured we configured a lot on it but we want to make sure that we can communicate with the actual server so on the left side i'm actually ssh into that raspberry pi which has the server running so the first thing you'll want to do is actually restart the nut client with our configuration after we restart it we should be good and we should be able to communicate with our server and the way that we query it is the same way we did it earlier on our local machine so on my remote machine i'm going to say upsc trip light or whichever modem you want to communicate with and then the ip address if we do it i should be able to communicate so that's pretty cool that means it works and on the remote machine if you actually want to test disconnects and reconnects and on my nut server i can just restart the service so that all clients connected to it will get disconnected and then hopefully reconnect so i can do that by using sudo system ctl restart nut not client but server if i do that supply password i should see a disconnect and we saw it on the right disconnect before the left see the left disconnect and then communications reestablished on the right so this means it's working just as it should there's only one thing left to do and that's actually go down and unplug the power wait for 30-ish seconds and we should see the one on the right reboot so top left is the server bottom left i'm pinging that machine and right is the client which is actually subscribed to the server and if this all works when i pull the power on the server after about 30-ish seconds the client should automatically shut down so we should see disconnect a power message and then it shut down and the ping stop responding and i have no way to do this other than to run downstairs and unplug it so i'll be right back okay so don't mind any of my messy chords right now because you're kind of getting a little sneak peek i won't show too much i mean server rooms and that's coming soon so make sure you're subscribed but i'm going to unplug this apc now i'm not in there to see if it's actually sending out the message so we're just gonna wait and so this is the raspberry pi and so we disconnected this one right here and hair peeping so after some period of time this device right here should shut down because it reached a critical level yes there it goes there it goes no more power that took so long to configure sorry so no more power on this device so now this proxmox server which is my third note that's another story for another day shut down so now i can plug this back in and safely power it back on yes i didn't think that was gonna work but let's look at this really quick sorry just reviewing the logs so you can see on the top left the server said hey i've lost line power then we see on the client on the right let me scroll up let's see first it received it's on battery then it received automatic power fail shut down then auto log and shut down proceeding and then it's going for a power off and then it powered off now and then it disconnected awesome and then here we saw the ping stop so you can see how powerful nut server is and this is just one configuration this is how i have my environment configured but you could connect a raspberry pi or a server or any machine to a ups and then take action based on those events that happen for that ups so no power low power running on battery too long bad communication the battery's bad all possible and all automated and so i encourage you to spin up nut server yourself and configure it i also would love it if you would tell me in the comments below how you configured nut server was mine the bizarre configuration or is there something else that you're using please let me know in the comments and remember if you found anything in this video helpful don't forget to like and subscribe thanks for watching i keep coming back to ubuntu i i go on these distro hopping like binges every now and then where i'm like you hop on one distro hop on another hop on a different flavor of this distro you know five versions of ubuntu kubuntu x ubuntu eduboontu um you know to check out all the the different uis and then you know and then i'm like oh yeah i'm gonna totally jump on the mint and then then i mean those are all ubuntu distributions and then i try other linux distributions and i always come back to ubuntu because you know it's it's i don't know i dare i say it's the windows of linux but it's you know it's it's pretty user friendly and things are generally well supported there and i mean they they are other places but with more tweaking
Info
Channel: Techno Tim
Views: 114,867
Rating: undefined out of 5
Keywords: techno tim, technotim, nut, nut server, network, ups, tools, apc, tripp lite, windows, pi, raspberry pi, server, desktop, nut client, pdu, smart ups, network ups, how to, self-hosted, selfhosted, homelab, home lab, ui, graph, data, docker, remote monitoring, diy, open source, ups pro
Id: vyBP7wpN72c
Channel Id: undefined
Length: 49min 35sec (2975 seconds)
Published: Sat Sep 25 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.