# Shutting Down FreeBSD



## jemate18 (Feb 3, 2009)

Here is the problem.... My two FreeBSD server are just hooked in an AVR. I got no UPS. There is about an average of two power trip/day in our place. Therefore, the server always goes off every time there is a power trip. Another thing is that our maintenance always cuts the power on weekends. This happens while my servers are on.

What are the chances that my FreeBSD systems will be damaged by this practices?

Another question, is is safe to just hard shutdown or hard reboot a system with freebsd running,  using the power switch and/or the reset button? Will the filesystems be damaged? 

I know that it is not the proper way, but that is my problem.

I know this may be labeled as a silly question... But answers and insights will be very helpful


----------



## trev (Feb 3, 2009)

Sooner or later one of your file systems is likely to be hosed. This happened to me once, which was enough to convince me to buy a couple of secondhand APC 1400VA UPSes off eBay. Best hardware investment I ever made!


----------



## jemate18 (Feb 3, 2009)

If in case my filesystem get hosed... What are the chances of fixin' it? What will I do to fix it? Commands, or guides... Links.... 

Thanks again...


----------



## gilinko (Feb 4, 2009)

My primary concern wouldn't be the filesystem as such, but the hardware. 12 hard resets a week with powersurges and brownouts will damage your hardware eventually and no software command will save you when it breaks. So I would invest in a UPS that can shutdown your server nicely automatically ASAP, otherwise you are just playing russian roulette with your hardware.


----------



## trev (Feb 4, 2009)

jemate18 said:
			
		

> If in case my filesystem get hosed... What are the chances of fixin' it? What will I do to fix it? Commands, or guides... Links....



The only real solution after the fateful event is called "backups"


----------



## jemate18 (Feb 4, 2009)

Thanks for the help..

I'm purchasing a cheap UPS ASAP..

Anyway.. I know this is again a very big problem....

UPS can only support the hardware in a few minutes... Is there a way to configure FreeBSD in such a way that it will automatically execute the shutdown -h now command  before the UPS runs out of power?

The reason for this is that, I may not be always available to execute the command in an event of a power failure.

I know this sounds strange and others may think it is very silly.... But again I'm asking for help..... But I'm just curious if it is possible.... 

Thanks again....


----------



## jemate18 (Feb 4, 2009)

I have read some article that there is an ACPI daemon that listens to events... I'm sure though it this may be applicable in desktop since it doesn't run on battery.

The article says in laptop, it logs events like if the laptop power is using AC or Battery. 

There is a log file in which it can be checked. I really don't know about the situation in the desktop using a UPS in which, if there is a power failure, the UPS battery is used. If the ACPI daemon logs this, is it possible to create a script to read or listen to the changes of the log messages? If it can determines that the UPS battery is in use, then may be it can trigger the shutdown -h now ? This is a wild and crazy idea...


----------



## gilinko (Feb 4, 2009)

You need to look for a UPS that has some control interface. The cheaper ones has either a usb or serial cable that you can connect to the computer and with that connection determine if and when to do a controlled shutdown. The absolutly cheapest ones are in essenase just a external battery and surge protector, and you need to manually shut things down when there is a powerloss.

The price goes way up if you have to support multiple computers from the same UPS.


----------



## jemate18 (Feb 4, 2009)

gilinko said:
			
		

> You need to look for a UPS that has some control interface. The cheaper ones has either a usb or serial cable that you can connect to the computer and with that connection determine if and when to do a controlled shutdown. The absolutly cheapest ones are in essenase just a external battery and surge protector, and you need to manually shut things down when there is a powerloss.
> 
> The price goes way up if you have to support multiple computers from the same UPS.



OH... Thanks... so my idea is right.. The only thing I will do is to study the logs and create a script that will read the logs and trigger the shutdown -h now if it detects that the UPS battery is in use. Or if the control interface has a much friendlier admin tool, then I think this is the solution to my problem.....

Other ideas and solutions are welcome and will be very useful


----------



## brd@ (Feb 5, 2009)

Get an APC with a serial port and then look in ports for sysutils/apcupsd.


----------



## morbit (Feb 5, 2009)

brd@ said:
			
		

> Get an APC with a serial port and then look in ports for sysutils/apcupsd.



APC with USB port will do too. (Tested.)


----------



## johnblue (Feb 5, 2009)

jemate18 said:
			
		

> .. and trigger the shutdown -h ..


As an aside, shutdown -p is also handy instead of exclusive use of -h provided your equipment supports it, of course.


----------

