The cart is empty

Security and data integrity are crucial aspects of server management, especially in environments where critical applications are constantly running. One effective method to protect against sudden power outages is to use an Uninterruptible Power Supply (UPS). This article outlines how to set up CentOS 7 for automatic server shutdown in case of power failure when the server is powered by a UPS, ensuring safe system shutdown and data protection.

Prerequisites

Before you begin, make sure that:

  • You have CentOS 7 installed and operational.
  • You have physical or network access to the server.
  • You have a UPS connected to the server via USB or network.

1. Installation and Configuration of NUT (Network UPS Tools)

NUT (Network UPS Tools) is the most commonly used software for communicating with UPS on Linux. It provides a mechanism for monitoring UPS and automatically shutting down the server during a power outage.

a. Installing NUT

Open a terminal and run the following command to install NUT:

sudo yum install nut

b. Configuring NUT

NUT configuration depends on the model of your UPS. The basic NUT configuration files are located in /etc/ups. The main files that need to be edited are:

  • ups.conf - Define your UPS here.
  • upsd.conf - Configuration for the UPS daemon.
  • upsd.users - File for defining users and permissions.
  • upsmon.conf - For UPS monitoring and configuring actions.

Example ups.conf configuration:

[myups]
    driver = usbhid-ups
    port = auto
    desc = "My UPS"

Replace myups with the identifier of your UPS and usbhid-ups with the driver that corresponds to your UPS. More information about available drivers can be found in your UPS documentation or on the NUT project website.

2. Setting Up Action on Power Failure

In the upsmon.conf file, set what should happen when the UPS detects a power failure. This is typically configured using the SHUTDOWNCMD directive.

Example:

SHUTDOWNCMD "/sbin/shutdown -h now"

3. Starting and Testing

After configuration, start NUT and test whether the system can detect UPS status and properly shut down when the UPS signals low battery or power failure.

a. Starting NUT services:

sudo systemctl start nut-server
sudo systemctl start nut-client

b. Testing

You can perform testing by simulating a power outage (if your UPS allows) or using NUT commands to simulate UPS states.

 

Properly configured automatic server shutdown during power failure is crucial for data and system protection. By using Network UPS Tools on CentOS 7, you can effectively manage your UPS and secure your server against sudden power outages.