First, sorry if I got the wrong forum. I'm a beginner at any sort of programming/etc and can't really do much of this sort of thing myself, so I'm a beginner in that respect.
Anyway, to the heart of the matter. I'm curious about how viable it might be to sort of rig up a USB power bank to act as a UPS system. Preferably a cheap one. I have a Raspberry Pi 2 being used as a server on my LAN mostly for some basic stuff like acting as a Squid proxy and network file sharing (music, videos, etc etc) on my LAN. What's more, I have multiple USB power banks, at least one of which has a decent output, boasts 4000mAh power (probably actually accurate as I think it uses two 18650s and usually those cheap Chinese generics are closer to 2000mAh than anything else,) and is capable of providing power while being plugged in to charge. Obviously a USB power bank can definitely power a Raspberry Pi just on its own, but there are two things to consider in using one as any sort of UPS type of solution:
First, how well can a DC-DC converter of the sorts these use hold up? But at the same time, as far as using a third party DC-DC converter goes, I'm not sure if this is optimal for several reasons. (They usually put the battery protection circuitry on the board rather than the battery itself in most of these cases, so I have to add on one. The charging portion would also have to be added on externally and I'm not sure how well that meshes with the output -- something a lot of power banks already implement ways to handle no doubt.) These things use fairly small DC-DC converters with no real cooling or anything, so I'm not sure how well it could handle if it's constantly running. On the other hand, most of these are built for up to 2.1 amps output for phone charging (which can still take a while, so they're obviously meant to run for more than just a few minutes at a time) and even though I do have an external harddrive plugged in (one designed for one USB 2.0 bus so has to be able to run from 500mA power even when it does run) it actually stays off most of the time (though I have it on there so I can use it for network sharing of media and such, so it can come on and run for a while at a time at least in theory though I haven't really used it all that much for all that I went to the trouble to set it up. I specifically setup Raspbian to spin it down when it goes long enough without being used however.) I have to assume the possibility that it will be properly utilized from time to time though.) I'm not sure how much the RPi2 uses on average (using ethernet rather than WiFi btw) for itself, but even with the extra 500mA I imagine it's quite considerably less than the 2.1A these cheap power banks are supposed to be able to put out.
Second, while most of the time it wouldn't even matter since usually it's just dealing with simple power blinks, what it really needs to work well is some means of actually tracking the battery status. It could potentially lose power for long periods of time at least once in a while. I really ideally would prefer in these scenarios, even if I'm not able to manually shut it down that it would be able to shut itself down automatically. But of course it would need some way of monitoring the battery. For example, if you could wire something directly to the battery where it detects the voltage and then some way for software to actually monitor this and issue a proper shutdown if it goes too low. A simple enough thing for a programmer with the appropriate hardware design knowledge no doubt, but I have no clue how I could possibly even do such a thing as I am neither. So my questions here are: 1. is it possible using some simple software (maybe the built in scheduler?) to somehow check the battery from time to time and shut down automatically if it goes below a certain threshold (probably something like 3.5V as much lower and the DC-DC converter likely craps out plus you want a bit of leeway -- it can probably go as low as 3.4 but likely starts crapping out around that sort of range, randomly shutting off and on) and 2. is it possible to more or less wire it directly to the RPi or does it require some external circuitry that might be more complex than I can really do to pull off such a thing? (Yeah, I've always been more interested in the RPi for its ability to act as a super efficient, minimal, tiny computer than for its ability to program for utilizing and managing external interfaces even if it is even more amazing at that sort of thing probably.) This also begs the question of if such a thing could be checked early on in the startup process so it maybe could refuse to continue if it's still too low (though I guess some sort of emergency bypass would be necessary if it needed to be booted without the power bank for a while or something.) Unfortunately, in my experience even journalized filesystems can have issues from time to time if improperly shut down at just the wrong moment or too frequently so really I would be a lot more comfortable with the whole idea if the server could just shut itself down.
Is the whole idea just a little too far out there? I currently have it plugged into the same UPS as my desktop PC, but the UPS has to be plugged into the PC (higher priority by far) and sometimes when the power goes off for a while in the middle of the night it wakes me up as even with almost everything off the UPS still drains sufficiently to eventually start making horrible warning noises and forces me to get up while 75% asleep and manually shut it off. I haven't had to do this since setting up the server, but it's probably inevitable and I don't think while 75% asleep I'm going to want to deal with properly shutting the thing down. I really like the idea of something independent just for it and nothing else, plus this is kind of neat as it makes for a more clean and minimal solution that even could be somewhat portable or something if I ever wanted to adapt the idea to some other use yet while just using a power bank in itself is quite portable, if it runs down it still can cause problems, so even for portability acting more like a UPS could be useful. Also, I just plain wanted to move it to another room where I keep stuff like my router and modem rather than in the bedroom for a bunch of reasons but I still don't want it to just shut off unsafely every time there's a power blink.